[fix #4361] Update user table sign_in
This commit is contained in:
parent
0c15326df6
commit
725798da6a
2 changed files with 44 additions and 0 deletions
|
@ -0,0 +1,17 @@
|
|||
namespace :after_party do
|
||||
desc 'Deployment task: update_admin_last_sign_in_at'
|
||||
task update_admin_last_sign_in_at: :environment do
|
||||
sql = <<-SQL
|
||||
UPDATE users
|
||||
SET last_sign_in_at = administrateurs.updated_at
|
||||
FROM administrateurs
|
||||
WHERE administrateur_id = administrateurs.id
|
||||
AND users.last_sign_in_at IS NULL
|
||||
AND administrateurs.active = true
|
||||
SQL
|
||||
|
||||
ActiveRecord::Base.connection.execute(sql)
|
||||
|
||||
AfterParty::TaskRecord.create version: '20191007124230'
|
||||
end
|
||||
end
|
|
@ -0,0 +1,27 @@
|
|||
describe '20191007124230_update_admin_last_sign_in_at.rake' do
|
||||
let(:rake_task) { Rake::Task['after_party:update_admin_last_sign_in_at'] }
|
||||
|
||||
subject { rake_task.invoke }
|
||||
after { rake_task.reenable }
|
||||
|
||||
context 'with 2 administrateurs' do
|
||||
let!(:admin) { create(:administrateur, active: true) }
|
||||
let(:user) { admin.user }
|
||||
let!(:admin2) { create(:administrateur, active: false) }
|
||||
let(:user2) { admin2.user }
|
||||
|
||||
before do
|
||||
end
|
||||
|
||||
it do
|
||||
expect(admin.active).to be true
|
||||
expect(user.last_sign_in_at).to be_nil
|
||||
expect(admin.updated_at).not_to be_nil
|
||||
|
||||
subject
|
||||
|
||||
expect(user.reload.last_sign_in_at).to eq(admin.reload.updated_at)
|
||||
expect(user2.reload.last_sign_in_at).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue