Administrateur can be assign accompagnateur on each of his procedure.
This commit is contained in:
parent
1923f2aec1
commit
1fcb33104d
19 changed files with 385 additions and 74 deletions
30
spec/controllers/admin/accompagnateurs_controller_spec.rb
Normal file
30
spec/controllers/admin/accompagnateurs_controller_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Admin::AccompagnateursController, type: :controller do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:procedure) { create :procedure, administrateur: admin }
|
||||
let(:gestionnaire) { create :gestionnaire, administrateurs: [admin] }
|
||||
|
||||
before do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
subject { get :show, procedure_id: procedure.id }
|
||||
it { expect(subject.status).to eq(200) }
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
subject { put :update, accompagnateur_id: gestionnaire.id ,procedure_id: procedure.id }
|
||||
|
||||
it { expect(subject).to redirect_to admin_procedure_accompagnateurs_path(procedure_id: procedure.id) }
|
||||
|
||||
context 'when assignement is valid' do
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(flash[:notice]).to be_present }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,19 +1,22 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Admin::GestionnairesController, type: :controller do
|
||||
describe Admin::GestionnairesController, type: :controller do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:email_2) { 'plip@octo.com' }
|
||||
let(:admin_2) { create :administrateur, email: email_2 }
|
||||
|
||||
before do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
subject { get :index }
|
||||
it { expect(subject.status).to eq(200) }
|
||||
subject { get :index }
|
||||
it { expect(subject.status).to eq(200) }
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:email) { 'test@plop.com' }
|
||||
subject { post :create, gestionnaire: { email: email } }
|
||||
let(:email) { 'test@plop.com' }
|
||||
subject { post :create, gestionnaire: {email: email} }
|
||||
|
||||
context 'When email is valid' do
|
||||
before do
|
||||
|
@ -39,77 +42,124 @@ describe Admin::GestionnairesController, type: :controller do
|
|||
before do
|
||||
subject
|
||||
end
|
||||
let(:email) { 'piou' }
|
||||
it { expect(response.status).to eq(302) }
|
||||
it { expect{ response }.not_to change(Gestionnaire, :count) }
|
||||
end
|
||||
|
||||
context 'when email is empty' do
|
||||
before do
|
||||
subject
|
||||
end
|
||||
let(:email) { '' }
|
||||
it { expect(response.status).to eq(302) }
|
||||
it { expect{ response }.not_to change(Gestionnaire, :count) }
|
||||
it 'Notification email is not send' do
|
||||
expect(GestionnaireMailer).not_to receive(:new_gestionnaire)
|
||||
expect(GestionnaireMailer).not_to receive(:deliver_now!)
|
||||
end
|
||||
end
|
||||
|
||||
context ' when email already exists' do
|
||||
let(:email) { 'test@plop.com' }
|
||||
before do
|
||||
subject
|
||||
post :create, gestionnaire: { email: email }
|
||||
end
|
||||
let(:email) { 'piou' }
|
||||
it { expect(response.status).to eq(302) }
|
||||
it { expect{ response }.not_to change(Gestionnaire, :count) }
|
||||
end
|
||||
it { expect { response }.not_to change(Gestionnaire, :count) }
|
||||
it { expect(flash[:alert]).to be_present }
|
||||
|
||||
context 'Email notification' do
|
||||
|
||||
it 'Notification email is sent when email is valid' do
|
||||
expect(GestionnaireMailer).to receive(:new_gestionnaire).and_return(GestionnaireMailer)
|
||||
expect(GestionnaireMailer).to receive(:deliver_now!)
|
||||
subject
|
||||
end
|
||||
|
||||
context 'is not sent when email is not valid' do
|
||||
let(:email) { 'testplop.com' }
|
||||
describe 'Email Notification' do
|
||||
it {
|
||||
expect(GestionnaireMailer).not_to receive(:new_gestionnaire)
|
||||
expect(GestionnaireMailer).not_to receive(:deliver_now!)
|
||||
subject
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
it 'is not sent when email already exists' do
|
||||
context 'when email is empty' do
|
||||
before do
|
||||
subject
|
||||
end
|
||||
let(:email) { '' }
|
||||
it { expect(response.status).to eq(302) }
|
||||
it { expect { response }.not_to change(Gestionnaire, :count) }
|
||||
|
||||
it 'Notification email is not send' do
|
||||
expect(GestionnaireMailer).not_to receive(:new_gestionnaire)
|
||||
expect(GestionnaireMailer).not_to receive(:deliver_now!)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when email is already assign at the admin' do
|
||||
before do
|
||||
create :gestionnaire, email: email, administrateurs: [admin]
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(response.status).to eq(302) }
|
||||
it { expect { response }.not_to change(Gestionnaire, :count) }
|
||||
it { expect(flash[:alert]).to be_present }
|
||||
|
||||
describe 'Email notification' do
|
||||
it 'is not sent when email already exists' do
|
||||
expect(GestionnaireMailer).not_to receive(:new_gestionnaire)
|
||||
expect(GestionnaireMailer).not_to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when an other admin will add the same email' do
|
||||
let(:gestionnaire) { Gestionnaire.find_by_email(email) }
|
||||
|
||||
before do
|
||||
create :gestionnaire, email: email, administrateurs: [admin]
|
||||
|
||||
sign_out admin
|
||||
sign_in admin_2
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(response.status).to eq(302) }
|
||||
it { expect { response }.not_to change(Gestionnaire, :count) }
|
||||
it { expect(flash[:notice]).to be_present }
|
||||
|
||||
it { expect(admin_2.gestionnaires).to include gestionnaire }
|
||||
it { expect(gestionnaire.administrateurs.size).to eq 2 }
|
||||
end
|
||||
|
||||
context 'Email notification' do
|
||||
it 'Notification email is sent when accompagnateur is create' do
|
||||
expect(GestionnaireMailer).to receive(:new_gestionnaire).and_return(GestionnaireMailer)
|
||||
expect(GestionnaireMailer).to receive(:deliver_now!)
|
||||
subject
|
||||
end
|
||||
|
||||
it 'Notification email is sent when accompagnateur is assign' do
|
||||
expect(GestionnaireMailer).to receive(:new_assignement).and_return(GestionnaireMailer)
|
||||
expect(GestionnaireMailer).to receive(:deliver_now!)
|
||||
subject
|
||||
end
|
||||
|
||||
context 'when accompagnateur is assign at a new admin' do
|
||||
before do
|
||||
create :gestionnaire, email: email, administrateurs: [admin]
|
||||
|
||||
sign_out admin
|
||||
sign_in admin_2
|
||||
end
|
||||
|
||||
it {
|
||||
expect(GestionnaireMailer).to receive(:new_assignement).and_return(GestionnaireMailer)
|
||||
expect(GestionnaireMailer).to receive(:deliver_now!)
|
||||
subject
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let(:email) { 'test@plop.com' }
|
||||
let!(:gestionnaire) { create :gestionnaire, email: email }
|
||||
let!(:admin) { create :administrateur }
|
||||
let!(:gestionnaire) { create :gestionnaire, email: email, administrateurs: [admin] }
|
||||
|
||||
subject { delete :destroy, id: gestionnaire.id }
|
||||
|
||||
context "when gestionaire_id is valid" do
|
||||
before do
|
||||
subject
|
||||
admin.reload
|
||||
gestionnaire.reload
|
||||
end
|
||||
|
||||
it { expect(response.status).to eq(302) }
|
||||
it { expect(response).to redirect_to admin_gestionnaires_path }
|
||||
it { expect{Gestionnaire.find(gestionnaire.id)}.to raise_error ActiveRecord::RecordNotFound}
|
||||
it { expect(admin.gestionnaires).not_to include gestionnaire }
|
||||
it { expect(gestionnaire.administrateurs).not_to include admin }
|
||||
end
|
||||
|
||||
it { expect{subject}.to change(Gestionnaire, :count).by(-1) }
|
||||
it { expect { subject }.not_to change(Gestionnaire, :count) }
|
||||
end
|
||||
|
||||
end
|
32
spec/services/accompagnateur_service_spec.rb
Normal file
32
spec/services/accompagnateur_service_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe AccompagnateurService do
|
||||
describe '#change_assignement!' do
|
||||
|
||||
let(:procedure) { create :procedure }
|
||||
let(:accompagnateur) { create :gestionnaire }
|
||||
|
||||
subject { AccompagnateurService.change_assignement! accompagnateur, procedure, to }
|
||||
|
||||
context 'when accompagnateur is not assign at the procedure' do
|
||||
let(:to) { AccompagnateurService::ASSIGN }
|
||||
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(accompagnateur.procedures).to include procedure }
|
||||
end
|
||||
|
||||
context 'when accompagnateur is assign at the procedure' do
|
||||
let(:to) { AccompagnateurService::NOT_ASSIGN }
|
||||
|
||||
before do
|
||||
create :assign_to, gestionnaire: accompagnateur, procedure: procedure
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(accompagnateur.procedures).not_to include procedure }
|
||||
end
|
||||
end
|
||||
end
|
60
spec/views/admin/accompagnateurs/show.html.haml_spec.rb
Normal file
60
spec/views/admin/accompagnateurs/show.html.haml_spec.rb
Normal file
|
@ -0,0 +1,60 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'admin/accompagnateurs/show.html.haml', type: :view do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:procedure) { create :procedure, administrateur: admin }
|
||||
|
||||
let(:assign_gestionnaires) { procedure.gestionnaires }
|
||||
let(:not_assign_gestionnaires) { admin.gestionnaires.where.not(id: assign_gestionnaires.ids) }
|
||||
|
||||
before do
|
||||
assign(:procedure, procedure)
|
||||
|
||||
assign(:accompagnateurs_assign, (smart_listing_create :accompagnateurs_assign,
|
||||
assign_gestionnaires,
|
||||
partial: "admin/accompagnateurs/list_assign",
|
||||
array: true))
|
||||
|
||||
assign(:accompagnateurs_not_assign, (smart_listing_create :accompagnateurs_not_assign,
|
||||
not_assign_gestionnaires,
|
||||
partial: "admin/accompagnateurs/list_not_assign",
|
||||
array: true))
|
||||
end
|
||||
|
||||
context 'when admin have none accompagnateur ' do
|
||||
before do
|
||||
render
|
||||
end
|
||||
|
||||
it { expect(rendered).to have_content('Aucun de disponible') }
|
||||
|
||||
context 'when administrateur have none accompagnateur assign' do
|
||||
it { expect(rendered).to have_content('Aucun d\'affecté') }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when administrateur have two accompagnateur' do
|
||||
let!(:accompagnateur_1) { create :gestionnaire, email: 'plop@plop.com', administrateurs: [admin] }
|
||||
let!(:accompagnateur_2) { create :gestionnaire, email: 'plip@plop.com', administrateurs: [admin] }
|
||||
|
||||
before do
|
||||
not_assign_gestionnaires.reload
|
||||
assign_gestionnaires.reload
|
||||
|
||||
assign(:accompagnateurs_assign, (smart_listing_create :accompagnateurs_assign,
|
||||
assign_gestionnaires,
|
||||
partial: "admin/accompagnateurs/list_assign",
|
||||
array: true))
|
||||
|
||||
assign(:accompagnateurs_not_assign, (smart_listing_create :accompagnateurs_not_assign,
|
||||
not_assign_gestionnaires,
|
||||
partial: "admin/accompagnateurs/list_not_assign",
|
||||
array: true))
|
||||
|
||||
render
|
||||
end
|
||||
|
||||
it { expect(rendered).to have_content(accompagnateur_1.email) }
|
||||
it { expect(rendered).to have_content(accompagnateur_2.email) }
|
||||
end
|
||||
end
|
|
@ -6,9 +6,9 @@ describe 'admin/gestionnaires/index.html.haml', type: :view do
|
|||
|
||||
before do
|
||||
assign(:gestionnaires, (smart_listing_create :gestionnaires,
|
||||
admin.gestionnaires,
|
||||
partial: "admin/gestionnaires/list",
|
||||
array: true))
|
||||
admin.gestionnaires,
|
||||
partial: "admin/gestionnaires/list",
|
||||
array: true))
|
||||
assign(:gestionnaire, Gestionnaire.new())
|
||||
end
|
||||
|
||||
|
@ -24,9 +24,9 @@ describe 'admin/gestionnaires/index.html.haml', type: :view do
|
|||
create(:gestionnaire, administrateurs: [admin])
|
||||
admin.reload
|
||||
assign(:gestionnaires, (smart_listing_create :gestionnaires,
|
||||
admin.gestionnaires,
|
||||
partial: "admin/gestionnaires/list",
|
||||
array: true))
|
||||
admin.gestionnaires,
|
||||
partial: "admin/gestionnaires/list",
|
||||
array: true))
|
||||
render
|
||||
end
|
||||
it { expect(rendered).to match(/plop\d+@plop.com/) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue