diff --git a/app/models/user.rb b/app/models/user.rb index 37fb36ed67..c9bb86d407 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -39,6 +39,12 @@ class User < ApplicationRecord 90.days.ago) } + scope :not_active_since, + lambda { |date| + where('DATE(current_login_at) = ? OR + (current_login_at IS NULL AND DATE(created_at) = ?)', date, date) + } + acts_as_authentic do |c| c.login_field = :email c.validate_email_field = true diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml index a64eff0ebb..1842bccc7d 100644 --- a/spec/fixtures/users.yml +++ b/spec/fixtures/users.yml @@ -114,6 +114,16 @@ new_non_active_user: email: new_non_active_user@fixtures.org created_at: <%= 3.days.ago.to_s(:db) %> +not_active_76_days: + <<: *DEFAULTS + email: not_active_for_76_days@fixtures.org + current_login_at: <%= 76.days.ago.to_s(:db) %> + +never_active_76_days: + <<: *DEFAULTS + email: never_active_for_76_days@fixtures.org + created_at: <%= 76.days.ago.to_s(:db) %> + affiliate_manager_with_pending_contact_information_status: <<: *DEFAULTS email: affiliate_manager_with_pending_contact_information_status@fixtures.org diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 177f0f6bd9..aa41fb171c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -140,6 +140,16 @@ it { is_expected.to include(never_active_user) } it { is_expected.not_to include(new_non_active_user) } end + + describe '.not_active_since' do + subject(:not_active_since) { User.not_active_since(76.days.ago.to_date) } + + let(:not_active_76_days_user) { users(:not_active_76_days) } + let(:never_active_76_days_user) { users(:never_active_76_days) } + + it { is_expected.to include(not_active_76_days_user) } + it { is_expected.to include(never_active_76_days_user) } + end end describe '#deliver_password_reset_instructions!' do