Refactoring: Clean up User.authenticate spec
This commit is contained in:
parent
33c44d3486
commit
296f37ef23
1 changed files with 30 additions and 21 deletions
|
@ -62,33 +62,42 @@ RSpec.describe User, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
it "updates user's updates last_login and updated_at attributes" do
|
||||
context 'when previous login was' do
|
||||
context 'never' do
|
||||
it 'updates #last_login and #updated_at' do
|
||||
expect { described_class.authenticate(user.login, password) }
|
||||
.to change { user.reload.last_login }
|
||||
.and change { user.reload.updated_at }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when authenticated multiple after another' do
|
||||
|
||||
before { described_class.authenticate(user.login, password) }
|
||||
|
||||
it "doesn't update last_login and updated_at when last login was less than 10 minutes ago" do
|
||||
context 'less than 10 minutes ago' do
|
||||
before do
|
||||
described_class.authenticate(user.login, password)
|
||||
travel 9.minutes
|
||||
end
|
||||
|
||||
it 'does not update #last_login and #updated_at' do
|
||||
expect { described_class.authenticate(user.login, password) }
|
||||
.to not_change { user.reload.last_login }
|
||||
.and not_change { user.reload.updated_at }
|
||||
end
|
||||
end
|
||||
|
||||
it 'updates last_login and updated_at when last login was more than 10 minutes ago' do
|
||||
context 'more than 10 minutes ago' do
|
||||
before do
|
||||
described_class.authenticate(user.login, password)
|
||||
travel 11.minutes
|
||||
end
|
||||
|
||||
it 'updates #last_login and #updated_at' do
|
||||
expect { described_class.authenticate(user.login, password) }
|
||||
.to change { user.reload.last_login }
|
||||
.and change { user.reload.updated_at }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with valid user and invalid password' do
|
||||
it 'increments failed login count' do
|
||||
|
|
Loading…
Reference in a new issue