Skip to content

Commit

Permalink
SRCH-1191 - create not_active_for scope that passes time parameter (#516
Browse files Browse the repository at this point in the history
)

* SRCH-1191 - create not_active_for scope that passes time parameter
  • Loading branch information
peggles2 authored Jan 22, 2020
1 parent bb98792 commit 76882df
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ new_non_active_user:
email: [email protected]
created_at: <%= 3.days.ago.to_s(:db) %>

not_active_76_days:
<<: *DEFAULTS
email: [email protected]
current_login_at: <%= 76.days.ago.to_s(:db) %>

never_active_76_days:
<<: *DEFAULTS
email: [email protected]
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
Expand Down
10 changes: 10 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 76882df

Please sign in to comment.