2019-10-24 21:52:05 +02:00
|
|
|
|
describe Instructeurs::GroupeInstructeursController, type: :controller do
|
|
|
|
|
render_views
|
2024-02-15 17:10:11 +01:00
|
|
|
|
let(:administrateurs) { [create(:administrateur, user: instructeur.user)] }
|
2019-10-24 21:52:05 +02:00
|
|
|
|
let(:instructeur) { create(:instructeur) }
|
2024-02-15 17:10:11 +01:00
|
|
|
|
let(:procedure) { create(:procedure, :published, administrateurs:) }
|
2019-10-24 21:52:05 +02:00
|
|
|
|
let!(:gi_1_1) { procedure.defaut_groupe_instructeur }
|
2023-06-29 11:45:20 +02:00
|
|
|
|
let!(:gi_1_2) { create(:groupe_instructeur, label: 'groupe instructeur 2', procedure: procedure) }
|
2019-10-24 21:52:05 +02:00
|
|
|
|
|
|
|
|
|
let(:procedure2) { create(:procedure, :published) }
|
2023-06-29 11:45:20 +02:00
|
|
|
|
let!(:gi_2_2) { create(:groupe_instructeur, label: 'groupe instructeur 2 2', procedure: procedure2) }
|
2019-10-24 21:52:05 +02:00
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
gi_1_2.instructeurs << instructeur
|
|
|
|
|
sign_in(instructeur.user)
|
|
|
|
|
end
|
|
|
|
|
|
2024-02-15 16:47:16 +01:00
|
|
|
|
describe "before_action: ensure_allowed!" do
|
|
|
|
|
it "is present" do
|
|
|
|
|
before_actions = Instructeurs::GroupeInstructeursController
|
|
|
|
|
._process_action_callbacks
|
|
|
|
|
.filter { |process_action_callbacks| process_action_callbacks.kind == :before }
|
|
|
|
|
.map(&:filter)
|
|
|
|
|
|
|
|
|
|
expect(before_actions).to include(:ensure_allowed!)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-02-15 17:10:11 +01:00
|
|
|
|
describe '#index (plus, ensure_allowed!)' do
|
|
|
|
|
context 'when i own the procedure' do
|
|
|
|
|
before { get :index, params: { procedure_id: procedure.id } }
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when i am an instructeur of the procedure and instructeurs_self_management_enabled is true' do
|
2024-06-01 22:50:48 +02:00
|
|
|
|
let(:procedure) { create(:procedure, :published, instructeurs_self_management_enabled: true) }
|
2024-02-15 17:10:11 +01:00
|
|
|
|
before { get :index, params: { procedure_id: procedure.id } }
|
2019-10-24 21:52:05 +02:00
|
|
|
|
|
2024-06-03 11:53:03 +02:00
|
|
|
|
it 'when a procedure has multiple groups' do
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
|
expect(response.body).to include(gi_1_2.label)
|
|
|
|
|
expect(response.body).not_to include(gi_1_1.label)
|
|
|
|
|
expect(response.body).not_to include(gi_2_2.label)
|
2019-10-24 21:52:05 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2024-02-15 17:10:11 +01:00
|
|
|
|
|
|
|
|
|
context 'when i am an instructor of the procedure, and instructeurs_self_management_enabled is false' do
|
2024-06-01 22:50:48 +02:00
|
|
|
|
let(:procedure) { create(:procedure, :published, :new_administrateur, instructeurs_self_management_enabled: false) }
|
2024-02-15 17:10:11 +01:00
|
|
|
|
before { get :index, params: { procedure_id: procedure.id } }
|
|
|
|
|
|
2024-06-03 11:53:03 +02:00
|
|
|
|
it "works" do
|
|
|
|
|
expect(response).to have_http_status(:redirect)
|
|
|
|
|
expect(flash.alert).to eq("Vous n’avez pas le droit de gérer les instructeurs de cette démarche")
|
|
|
|
|
end
|
2024-02-15 17:10:11 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'i am an instructor, not on the procedure' do
|
2024-06-01 22:50:48 +02:00
|
|
|
|
let(:procedure) { create(:procedure, :published, :new_administrateur, instructeurs_self_management_enabled: true) }
|
2024-02-15 17:10:11 +01:00
|
|
|
|
before do
|
|
|
|
|
sign_in(create(:instructeur).user)
|
|
|
|
|
get :index, params: { procedure_id: procedure.id }
|
|
|
|
|
end
|
|
|
|
|
|
2024-06-03 11:53:03 +02:00
|
|
|
|
it "works" do
|
|
|
|
|
expect(response).to have_http_status(:redirect)
|
|
|
|
|
expect(flash.alert).to eq("Vous n’avez pas accès à cette démarche")
|
|
|
|
|
end
|
2024-02-15 17:10:11 +01:00
|
|
|
|
end
|
2019-10-24 21:52:05 +02:00
|
|
|
|
end
|
2019-10-24 22:17:55 +02:00
|
|
|
|
|
|
|
|
|
describe '#show' do
|
|
|
|
|
context 'of a group I belong to' do
|
|
|
|
|
before { get :show, params: { procedure_id: procedure.id, id: gi_1_2.id } }
|
|
|
|
|
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-10-25 09:26:31 +02:00
|
|
|
|
|
|
|
|
|
describe '#add_instructeur' do
|
2024-03-11 12:29:06 +01:00
|
|
|
|
subject do
|
2019-10-25 09:26:31 +02:00
|
|
|
|
post :add_instructeur,
|
|
|
|
|
params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
id: gi_1_2.id,
|
|
|
|
|
instructeur: { email: new_instructeur_email }
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'of a new instructeur' do
|
2024-07-04 14:25:09 +02:00
|
|
|
|
let(:new_instructeur_email) { 'new_instructeur@gmail.com' }
|
2024-03-11 12:29:06 +01:00
|
|
|
|
before { subject }
|
2019-10-25 09:26:31 +02:00
|
|
|
|
|
2024-06-03 11:53:03 +02:00
|
|
|
|
it "works" do
|
|
|
|
|
expect(gi_1_2.instructeurs.map(&:email)).to include(new_instructeur_email)
|
|
|
|
|
expect(flash.notice).to be_present
|
|
|
|
|
expect(response).to redirect_to(instructeur_groupe_path(procedure, gi_1_2))
|
|
|
|
|
end
|
2019-10-25 09:26:31 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'of an instructeur already in the group' do
|
|
|
|
|
let(:new_instructeur_email) { instructeur.email }
|
2024-03-11 12:29:06 +01:00
|
|
|
|
before { subject }
|
2019-10-25 09:26:31 +02:00
|
|
|
|
|
2024-06-03 11:53:03 +02:00
|
|
|
|
it "works" do
|
|
|
|
|
expect(flash.alert).to be_present
|
|
|
|
|
expect(response).to redirect_to(instructeur_groupe_path(procedure, gi_1_2))
|
|
|
|
|
end
|
2019-10-25 09:26:31 +02:00
|
|
|
|
end
|
2024-03-11 12:29:06 +01:00
|
|
|
|
|
|
|
|
|
context 'invalid email' do
|
|
|
|
|
let(:new_instructeur_email) { 'invalid' }
|
|
|
|
|
|
2024-06-03 11:53:03 +02:00
|
|
|
|
it "works" do
|
|
|
|
|
expect { subject }.not_to enqueue_email
|
|
|
|
|
expect(flash.alert).to include(new_instructeur_email)
|
|
|
|
|
end
|
2024-03-11 12:29:06 +01:00
|
|
|
|
end
|
2019-10-25 09:26:31 +02:00
|
|
|
|
end
|
2019-10-25 10:17:39 +02:00
|
|
|
|
|
|
|
|
|
describe '#remove_instructeur' do
|
2021-10-26 22:40:48 +02:00
|
|
|
|
let(:new_instructeur) { create(:instructeur) }
|
|
|
|
|
let(:dossier) { create(:dossier) }
|
2019-10-25 10:17:39 +02:00
|
|
|
|
|
2021-10-26 22:40:48 +02:00
|
|
|
|
before do
|
|
|
|
|
gi_1_1.instructeurs << instructeur << new_instructeur
|
|
|
|
|
gi_1_1.dossiers << dossier
|
|
|
|
|
new_instructeur.followed_dossiers << dossier
|
|
|
|
|
end
|
2019-10-25 10:17:39 +02:00
|
|
|
|
|
|
|
|
|
def remove_instructeur(instructeur)
|
|
|
|
|
delete :remove_instructeur,
|
|
|
|
|
params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
id: gi_1_1.id,
|
|
|
|
|
instructeur: { id: instructeur.id }
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when there are many instructeurs' do
|
|
|
|
|
before { remove_instructeur(new_instructeur) }
|
|
|
|
|
|
2024-06-03 11:53:03 +02:00
|
|
|
|
it "works" do
|
|
|
|
|
expect(gi_1_1.instructeurs).to include(instructeur)
|
|
|
|
|
expect(gi_1_1.reload.instructeurs.count).to eq(1)
|
|
|
|
|
expect(new_instructeur.reload.follows.count).to eq(0)
|
|
|
|
|
expect(response).to redirect_to(instructeur_groupe_path(procedure, gi_1_1))
|
|
|
|
|
end
|
2019-10-25 10:17:39 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when there is only one instructeur' do
|
|
|
|
|
before do
|
|
|
|
|
remove_instructeur(new_instructeur)
|
|
|
|
|
remove_instructeur(instructeur)
|
|
|
|
|
end
|
|
|
|
|
|
2024-06-03 11:53:03 +02:00
|
|
|
|
it "works" do
|
|
|
|
|
expect(gi_1_1.instructeurs).to include(instructeur)
|
|
|
|
|
expect(gi_1_1.instructeurs.count).to eq(1)
|
|
|
|
|
expect(flash.alert).to eq('Suppression impossible : il doit y avoir au moins un instructeur dans le groupe')
|
|
|
|
|
expect(response).to redirect_to(instructeur_groupe_path(procedure, gi_1_1))
|
|
|
|
|
end
|
2019-10-25 10:17:39 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2023-09-21 13:51:04 +02:00
|
|
|
|
|
|
|
|
|
describe '#add_signature' do
|
|
|
|
|
let(:signature) { fixture_file_upload('spec/fixtures/files/black.png', 'image/png') }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
post :add_signature,
|
|
|
|
|
params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
id: gi_1_2.id,
|
|
|
|
|
groupe_instructeur: {
|
|
|
|
|
signature: signature
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2024-06-03 11:53:03 +02:00
|
|
|
|
it "works" do
|
|
|
|
|
expect(response).to redirect_to(instructeur_groupe_path(procedure, gi_1_2))
|
|
|
|
|
expect(gi_1_2.reload.signature).to be_attached
|
|
|
|
|
end
|
2023-09-21 13:51:04 +02:00
|
|
|
|
end
|
2019-10-24 21:52:05 +02:00
|
|
|
|
end
|