mirror of
https://github.com/mastodon/mastodon.git
synced 2025-11-27 10:00:50 +00:00
Improve SessionActivation.activate spec (#36983)
This commit is contained in:
parent
00163e89bf
commit
cb4f1cc89c
|
|
@ -38,9 +38,7 @@ class SessionActivation < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def activate(**)
|
def activate(**)
|
||||||
activation = create!(**)
|
create!(**).tap { purge_old }
|
||||||
purge_old
|
|
||||||
activation
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def deactivate(id)
|
def deactivate(id)
|
||||||
|
|
|
||||||
|
|
@ -39,20 +39,24 @@ RSpec.describe SessionActivation do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.activate' do
|
describe '.activate' do
|
||||||
let(:options) { { user: Fabricate(:user), session_id: '1' } }
|
let(:user) { Fabricate :user }
|
||||||
|
let!(:session_activation) { Fabricate :session_activation, user: }
|
||||||
|
|
||||||
it 'calls create! and purge_old' do
|
around do |example|
|
||||||
allow(described_class).to receive(:create!).with(**options)
|
original = Rails.configuration.x.max_session_activations
|
||||||
allow(described_class).to receive(:purge_old)
|
Rails.configuration.x.max_session_activations = 1
|
||||||
|
example.run
|
||||||
described_class.activate(**options)
|
Rails.configuration.x.max_session_activations = original
|
||||||
|
|
||||||
expect(described_class).to have_received(:create!).with(**options)
|
|
||||||
expect(described_class).to have_received(:purge_old)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns an instance of SessionActivation' do
|
it 'creates a new activation and purges older ones' do
|
||||||
expect(described_class.activate(**options)).to be_a described_class
|
result = described_class.activate(user: user, session_id: '123')
|
||||||
|
|
||||||
|
expect(result)
|
||||||
|
.to be_a(described_class)
|
||||||
|
.and have_attributes(session_id: '123', user:)
|
||||||
|
expect { session_activation.reload }
|
||||||
|
.to raise_error(ActiveRecord::RecordNotFound)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user