An admin has always a gestionnaire role

This commit is contained in:
simon lehericey 2018-10-30 15:31:13 +01:00
parent 2391c73616
commit 2613d05a4f
4 changed files with 31 additions and 1 deletions

View file

@ -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

View 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

View file

@ -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

View file

@ -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