mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00
Add coverage to user spec for missing last_sign_in_at
scenario (#35587)
This commit is contained in:
parent
139025fce0
commit
e8e6cf9510
|
@ -209,10 +209,8 @@ class User < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_sign_in!(new_sign_in: false)
|
def update_sign_in!(new_sign_in: false)
|
||||||
old_current = current_sign_in_at
|
|
||||||
new_current = Time.now.utc
|
new_current = Time.now.utc
|
||||||
|
self.last_sign_in_at = current_sign_in_at || new_current
|
||||||
self.last_sign_in_at = old_current || new_current
|
|
||||||
self.current_sign_in_at = new_current
|
self.current_sign_in_at = new_current
|
||||||
|
|
||||||
increment(:sign_in_count) if new_sign_in
|
increment(:sign_in_count) if new_sign_in
|
||||||
|
|
|
@ -163,12 +163,13 @@ RSpec.describe User do
|
||||||
|
|
||||||
describe '#update_sign_in!' do
|
describe '#update_sign_in!' do
|
||||||
context 'with an existing user' do
|
context 'with an existing user' do
|
||||||
let!(:user) { Fabricate :user, last_sign_in_at: 10.days.ago, current_sign_in_at: 1.hour.ago, sign_in_count: 123 }
|
let!(:user) { Fabricate :user, last_sign_in_at: 10.days.ago, current_sign_in_at:, sign_in_count: 123 }
|
||||||
|
let(:current_sign_in_at) { 1.hour.ago }
|
||||||
|
|
||||||
context 'with new sign in false' do
|
context 'with new sign in false' do
|
||||||
it 'updates timestamps but not counts' do
|
it 'updates timestamps but not counts' do
|
||||||
expect { user.update_sign_in!(new_sign_in: false) }
|
expect { user.update_sign_in!(new_sign_in: false) }
|
||||||
.to change(user, :last_sign_in_at)
|
.to change(user, :last_sign_in_at).to(current_sign_in_at)
|
||||||
.and change(user, :current_sign_in_at)
|
.and change(user, :current_sign_in_at)
|
||||||
.and not_change(user, :sign_in_count)
|
.and not_change(user, :sign_in_count)
|
||||||
end
|
end
|
||||||
|
@ -177,11 +178,22 @@ RSpec.describe User do
|
||||||
context 'with new sign in true' do
|
context 'with new sign in true' do
|
||||||
it 'updates timestamps and counts' do
|
it 'updates timestamps and counts' do
|
||||||
expect { user.update_sign_in!(new_sign_in: true) }
|
expect { user.update_sign_in!(new_sign_in: true) }
|
||||||
.to change(user, :last_sign_in_at)
|
.to change(user, :last_sign_in_at).to(current_sign_in_at)
|
||||||
.and change(user, :current_sign_in_at)
|
.and change(user, :current_sign_in_at)
|
||||||
.and change(user, :sign_in_count).by(1)
|
.and change(user, :sign_in_count).by(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the user does not have a current_sign_in_at value' do
|
||||||
|
let(:current_sign_in_at) { nil }
|
||||||
|
|
||||||
|
before { travel_to(1.minute.ago) }
|
||||||
|
|
||||||
|
it 'updates last sign in to now' do
|
||||||
|
expect { user.update_sign_in! }
|
||||||
|
.to change(user, :last_sign_in_at).to(Time.now.utc)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a new user' do
|
context 'with a new user' do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user