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,30 +62,39 @@ RSpec.describe User, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "updates user's updates last_login and updated_at attributes" do
|
context 'when previous login was' do
|
||||||
expect { described_class.authenticate(user.login, password) }
|
context 'never' do
|
||||||
.to change { user.reload.last_login }
|
it 'updates #last_login and #updated_at' do
|
||||||
.and change { user.reload.updated_at }
|
expect { described_class.authenticate(user.login, password) }
|
||||||
end
|
.to change { user.reload.last_login }
|
||||||
|
.and change { user.reload.updated_at }
|
||||||
context 'when authenticated multiple after another' do
|
end
|
||||||
|
|
||||||
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
|
|
||||||
travel 9.minutes
|
|
||||||
|
|
||||||
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 'less than 10 minutes ago' do
|
||||||
travel 11.minutes
|
before do
|
||||||
|
described_class.authenticate(user.login, password)
|
||||||
|
travel 9.minutes
|
||||||
|
end
|
||||||
|
|
||||||
expect { described_class.authenticate(user.login, password) }
|
it 'does not update #last_login and #updated_at' do
|
||||||
.to change { user.reload.last_login }
|
expect { described_class.authenticate(user.login, password) }
|
||||||
.and change { user.reload.updated_at }
|
.to not_change { user.reload.last_login }
|
||||||
|
.and not_change { user.reload.updated_at }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue