User get the active notion

This commit is contained in:
simon lehericey 2019-11-05 10:01:07 +01:00
parent 40af20b733
commit b193dd1465
2 changed files with 22 additions and 0 deletions

View file

@ -92,6 +92,10 @@ class User < ApplicationRecord
"User:#{id}"
end
def active?
last_sign_in_at.present?
end
private
def link_invites!

View file

@ -191,4 +191,22 @@ describe User, type: :model do
it { expect(AdministrationMailer).to have_received(:invite_admin).with(user, nil, administration.id) }
end
end
describe '#active?' do
let!(:user) { create(:user) }
subject { user.active? }
context 'when the user has never signed in' do
before { user.update(last_sign_in_at: nil) }
it { is_expected.to be false }
end
context 'when the user has already signed in' do
before { user.update(last_sign_in_at: Time.zone.now) }
it { is_expected.to be true }
end
end
end