Merge pull request #10779 from demarches-simplifiees/fix-10753
ETQ Mainteneur je veux marqué les emails des instructeurs qui se sont connectés il y a < 5 mois comme vérifiés
This commit is contained in:
commit
5e0ebb69f8
3 changed files with 53 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -22,6 +22,7 @@ uploads/*
|
|||
*.swp
|
||||
.envrc
|
||||
.env
|
||||
.tool-versions
|
||||
storage/
|
||||
/node_modules
|
||||
/yarn-error.log
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
namespace :after_party do
|
||||
desc 'Deployment task: mark_email_verified_when_user_signed_in_during_last_5_months'
|
||||
task mark_email_verified_when_user_signed_in_during_last_5_months: :environment do
|
||||
users_signed_in_during_last_5_months = User.where(email_verified_at: nil, created_at: 5.months.ago.., sign_in_count: 1..)
|
||||
|
||||
affected_users_count = users_signed_in_during_last_5_months.count
|
||||
|
||||
puts "Processing #{affected_users_count} users signed in during the last 5 months and not verified"
|
||||
|
||||
users_signed_in_during_last_5_months.update_all(email_verified_at: Time.zone.now)
|
||||
puts "Done"
|
||||
|
||||
AfterParty::TaskRecord
|
||||
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||
end
|
||||
end
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe 'after_party:mark_email_verified_when_user_signed_in_during_last_5_months' do
|
||||
let(:rake_task) { Rake::Task['after_party:mark_email_verified_when_user_signed_in_during_last_5_months'] }
|
||||
|
||||
subject { rake_task.invoke }
|
||||
after(:each) { rake_task.reenable }
|
||||
|
||||
let(:old_date) { 6.months.ago }
|
||||
|
||||
let!(:user) { create(:user, email_verified_at: nil, sign_in_count: 1) }
|
||||
let!(:user2) { create(:user, email_verified_at: nil, sign_in_count: 1) }
|
||||
let!(:user3) { create(:user, email_verified_at: nil, sign_in_count: 0) }
|
||||
let!(:user4) { create(:user, email_verified_at: old_date, sign_in_count: 1) }
|
||||
let!(:user5) do
|
||||
travel_to(old_date) do
|
||||
create(:user, email_verified_at: nil, sign_in_count: 1)
|
||||
end
|
||||
end
|
||||
|
||||
it 'mark_email_verified_when_user_signed_in_during_last_5_months' do
|
||||
expect(User.where(email_verified_at: nil, sign_in_count: 1.., created_at: 5.months.ago..).count).to eq(2)
|
||||
|
||||
subject
|
||||
|
||||
expect(User.where(email_verified_at: nil, sign_in_count: 1.., created_at: 5.months.ago..).count).to eq(0)
|
||||
expect(user.reload.email_verified_at).to be_present
|
||||
expect(user2.reload.email_verified_at).to be_present
|
||||
expect(user3.reload.email_verified_at).to be_nil
|
||||
expect(user4.reload.email_verified_at.to_i).to eq(old_date.to_i)
|
||||
expect(user5.reload.email_verified_at).to be_nil
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue