An admin has always a gestionnaire role
This commit is contained in:
parent
2391c73616
commit
2613d05a4f
4 changed files with 31 additions and 1 deletions
|
@ -19,11 +19,17 @@ class Administration < ApplicationRecord
|
|||
if administrateur.save
|
||||
AdministrationMailer.new_admin_email(administrateur, self).deliver_later
|
||||
administrateur.invite!(id)
|
||||
|
||||
User.create({
|
||||
email: email,
|
||||
password: password,
|
||||
confirmed_at: Time.zone.now
|
||||
})
|
||||
|
||||
Gestionnaire.create({
|
||||
email: email,
|
||||
password: password
|
||||
})
|
||||
end
|
||||
|
||||
administrateur
|
||||
|
|
15
lib/tasks/2018_10_30_admin_has_gestionnaire.rake
Normal file
15
lib/tasks/2018_10_30_admin_has_gestionnaire.rake
Normal file
|
@ -0,0 +1,15 @@
|
|||
namespace :'2018_10_30_admin_has_gestionnaire' do
|
||||
task run: :environment do
|
||||
admin_without_gestionnaire_ids = Administrateur
|
||||
.find_by_sql('SELECT administrateurs.id FROM administrateurs LEFT OUTER JOIN gestionnaires ON gestionnaires.email = administrateurs.email WHERE gestionnaires.email IS NULL')
|
||||
.pluck(:id)
|
||||
|
||||
admin_without_gestionnaire_ids.each do |admin_id|
|
||||
admin = Administrateur.find(admin_id)
|
||||
g = Gestionnaire.new
|
||||
g.email = admin.email
|
||||
g.encrypted_password = admin.encrypted_password
|
||||
g.save(validate: false)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,10 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'Administrator connection' do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:email) { 'admin1@admin.com' }
|
||||
let(:password) { 'mon chien aime les bananes' }
|
||||
let!(:admin) { create(:administrateur, email: email, password: password) }
|
||||
let!(:gestionnaire) { create(:gestionnaire, email: email, password: password) }
|
||||
before do
|
||||
visit new_administrateur_session_path
|
||||
end
|
||||
|
|
|
@ -20,6 +20,12 @@ describe Administration, type: :model do
|
|||
expect(user).to be_present
|
||||
end
|
||||
|
||||
it 'creates a corresponding gestionnaire account for the email' do
|
||||
subject
|
||||
gestionnaire = Gestionnaire.find_by(email: valid_email)
|
||||
expect(gestionnaire).to be_present
|
||||
end
|
||||
|
||||
context 'when there already is a user account with the same email' do
|
||||
before { create(:user, email: valid_email) }
|
||||
it 'still creates an admin account' do
|
||||
|
|
Loading…
Reference in a new issue