diff --git a/app/models/user.rb b/app/models/user.rb index 126c7adec..62176d692 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -92,6 +92,10 @@ class User < ApplicationRecord "User:#{id}" end + def active? + last_sign_in_at.present? + end + private def link_invites! diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 4ff839507..a24949fbc 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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