Refactoring: Clean up User.authenticate spec

This commit is contained in:
Ryan Lue 2019-03-18 17:56:20 +08:00 committed by Thorsten Eckel
parent 33c44d3486
commit 296f37ef23

View file

@ -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