instructeurs: replace calls to Instructeur.find_by(email: …)
This commit is contained in:
parent
c14dc7ad64
commit
cd478b489e
9 changed files with 15 additions and 11 deletions
|
@ -13,7 +13,7 @@ class Admin::InstructeursController < AdminController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
email = params[:instructeur][:email].downcase
|
email = params[:instructeur][:email].downcase
|
||||||
@instructeur = Instructeur.find_by(email: email)
|
@instructeur = Instructeur.by_email(email)
|
||||||
procedure_id = params[:procedure_id]
|
procedure_id = params[:procedure_id]
|
||||||
|
|
||||||
if @instructeur.nil?
|
if @instructeur.nil?
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Users::PasswordsController < Devise::PasswordsController
|
||||||
@devise_mapping = Devise.mappings[:administrateur]
|
@devise_mapping = Devise.mappings[:administrateur]
|
||||||
params[:administrateur] = params[:user]
|
params[:administrateur] = params[:user]
|
||||||
# uncomment to check password complexity for Instructeur
|
# uncomment to check password complexity for Instructeur
|
||||||
# elsif Instructeur.find_by(email: email)
|
# elsif Instructeur.by_email(email)
|
||||||
# @devise_mapping = Devise.mappings[:instructeur]
|
# @devise_mapping = Devise.mappings[:instructeur]
|
||||||
# params[:instructeur] = params[:user]
|
# params[:instructeur] = params[:user]
|
||||||
end
|
end
|
||||||
|
@ -46,7 +46,7 @@ class Users::PasswordsController < Devise::PasswordsController
|
||||||
|
|
||||||
def try_to_authenticate_instructeur
|
def try_to_authenticate_instructeur
|
||||||
if user_signed_in?
|
if user_signed_in?
|
||||||
instructeur = Instructeur.find_by(email: current_user.email)
|
instructeur = Instructeur.by_email(current_user.email)
|
||||||
|
|
||||||
if instructeur
|
if instructeur
|
||||||
sign_in(instructeur.user)
|
sign_in(instructeur.user)
|
||||||
|
|
|
@ -4,8 +4,8 @@ class WebhookController < ActionController::Base
|
||||||
def helpscout
|
def helpscout
|
||||||
email = params[:customer][:email].downcase
|
email = params[:customer][:email].downcase
|
||||||
user = User.find_by(email: email)
|
user = User.find_by(email: email)
|
||||||
instructeur = Instructeur.find_by(email: email)
|
instructeur = user.instructeur
|
||||||
administrateur = Administrateur.find_by(email: email)
|
administrateur = user.administrateur
|
||||||
html = []
|
html = []
|
||||||
|
|
||||||
if user
|
if user
|
||||||
|
|
|
@ -74,7 +74,7 @@ class Administrateur < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def instructeur
|
def instructeur
|
||||||
Instructeur.find_by(email: email)
|
user.instructeur
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_be_deleted?
|
def can_be_deleted?
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Avis < ApplicationRecord
|
||||||
private
|
private
|
||||||
|
|
||||||
def try_to_assign_instructeur
|
def try_to_assign_instructeur
|
||||||
instructeur = Instructeur.find_by(email: email)
|
instructeur = Instructeur.by_email(email)
|
||||||
if instructeur
|
if instructeur
|
||||||
self.instructeur = instructeur
|
self.instructeur = instructeur
|
||||||
self.email = nil
|
self.email = nil
|
||||||
|
|
|
@ -24,6 +24,10 @@ class Instructeur < ApplicationRecord
|
||||||
|
|
||||||
has_one :user
|
has_one :user
|
||||||
|
|
||||||
|
def self.by_email(email)
|
||||||
|
Instructeur.eager_load(:user).find_by(users: { email: email })
|
||||||
|
end
|
||||||
|
|
||||||
def follow(dossier)
|
def follow(dossier)
|
||||||
begin
|
begin
|
||||||
followed_dossiers << dossier
|
followed_dossiers << dossier
|
||||||
|
|
|
@ -112,7 +112,7 @@ describe Admin::InstructeursController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when an other admin will add the same email' do
|
context 'when an other admin will add the same email' do
|
||||||
let(:instructeur) { Instructeur.find_by(email: email) }
|
let(:instructeur) { Instructeur.by_email(email) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create :instructeur, email: email, administrateurs: [admin]
|
create :instructeur, email: email, administrateurs: [admin]
|
||||||
|
@ -133,7 +133,7 @@ describe Admin::InstructeursController, type: :controller do
|
||||||
|
|
||||||
context 'when an other admin will add the same email with some uppercase in it' do
|
context 'when an other admin will add the same email with some uppercase in it' do
|
||||||
let(:email) { 'Test@Plop.com' }
|
let(:email) { 'Test@Plop.com' }
|
||||||
let(:instructeur) { Instructeur.find_by(email: email.downcase) }
|
let(:instructeur) { Instructeur.by_email(email.downcase) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create :instructeur, email: email, administrateurs: [admin]
|
create :instructeur, email: email, administrateurs: [admin]
|
||||||
|
|
|
@ -284,7 +284,7 @@ describe Instructeurs::AvisController, type: :controller do
|
||||||
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
|
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
|
||||||
let(:avis_id) { avis.id }
|
let(:avis_id) { avis.id }
|
||||||
let(:password) { 'démarches-simplifiées-pwd' }
|
let(:password) { 'démarches-simplifiées-pwd' }
|
||||||
let(:created_instructeur) { Instructeur.find_by(email: invited_email) }
|
let(:created_instructeur) { Instructeur.by_email(invited_email) }
|
||||||
let(:invitations_email) { true }
|
let(:invitations_email) { true }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
|
|
@ -24,7 +24,7 @@ describe Administration, type: :model do
|
||||||
|
|
||||||
it 'creates a corresponding instructeur account for the email' do
|
it 'creates a corresponding instructeur account for the email' do
|
||||||
subject
|
subject
|
||||||
instructeur = Instructeur.find_by(email: valid_email)
|
instructeur = Instructeur.by_email(valid_email)
|
||||||
expect(instructeur).to be_present
|
expect(instructeur).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue