2021-03-30 17:55:35 +02:00
|
|
|
describe NewAdministrateur::ExpertsProceduresController, type: :controller do
|
|
|
|
let(:admin) { create(:administrateur) }
|
2021-04-06 13:55:43 +02:00
|
|
|
let(:procedure) { create :procedure, administrateur: admin }
|
2021-03-30 17:55:35 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin.user)
|
|
|
|
end
|
2021-04-06 13:42:21 +02:00
|
|
|
|
2021-04-06 13:55:43 +02:00
|
|
|
describe '#index' do
|
|
|
|
subject do
|
|
|
|
get :index, params: { procedure_id: procedure.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response.status).to eq 200 }
|
|
|
|
end
|
|
|
|
|
2021-04-06 13:42:21 +02:00
|
|
|
describe '#create' do
|
2021-03-30 17:55:35 +02:00
|
|
|
let(:expert) { create(:expert) }
|
|
|
|
let(:expert2) { create(:expert) }
|
|
|
|
|
|
|
|
subject do
|
2021-04-06 13:42:21 +02:00
|
|
|
post :create, params: {
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
emails: "[\"#{expert.email}\",\"#{expert2.email}\"]"
|
|
|
|
}
|
2021-03-30 17:55:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'of multiple experts' do
|
|
|
|
it { expect(procedure.experts.include?(expert)).to be_truthy }
|
|
|
|
it { expect(procedure.experts.include?(expert2)).to be_truthy }
|
|
|
|
it { expect(flash.notice).to be_present }
|
2021-04-06 13:55:43 +02:00
|
|
|
it { expect(response).to redirect_to(admin_procedure_experts_path(procedure)) }
|
2021-03-30 17:55:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-06 13:42:21 +02:00
|
|
|
describe '#delete' do
|
2021-03-30 17:55:35 +02:00
|
|
|
let(:expert) { create(:expert) }
|
|
|
|
let(:expert_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) }
|
|
|
|
|
|
|
|
subject do
|
2021-04-06 13:42:21 +02:00
|
|
|
delete :destroy, params: { procedure_id: procedure.id, id: expert_procedure.id }
|
2021-03-30 17:55:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
expert_procedure.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'of multiple experts' do
|
|
|
|
it { expect(expert_procedure.revoked_at).to be_present }
|
|
|
|
it { expect(flash.notice).to be_present }
|
2021-04-06 13:55:43 +02:00
|
|
|
it { expect(response).to redirect_to(admin_procedure_experts_path(procedure)) }
|
2021-03-30 17:55:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|