2017-06-29 15:31:29 +02:00
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe NewGestionnaire::DossiersController, type: :controller do
|
2017-09-20 10:42:16 +02:00
|
|
|
|
render_views
|
|
|
|
|
|
2017-06-29 15:31:29 +02:00
|
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
2018-01-30 19:11:07 +01:00
|
|
|
|
let(:gestionnaires) { [gestionnaire] }
|
|
|
|
|
let(:procedure) { create(:procedure, :published, gestionnaires: gestionnaires) }
|
2017-12-14 15:51:45 +01:00
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
2017-06-29 15:31:29 +02:00
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
before { sign_in(gestionnaire) }
|
2017-07-06 16:33:36 +02:00
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#attestation' do
|
2017-06-29 15:31:29 +02:00
|
|
|
|
context 'when a dossier has an attestation' do
|
|
|
|
|
let(:fake_pdf) { double(read: 'pdf content') }
|
2017-12-14 15:51:45 +01:00
|
|
|
|
let!(:dossier) { create(:dossier, :en_construction, attestation: Attestation.new, procedure: procedure) }
|
2017-07-18 15:26:33 +02:00
|
|
|
|
let!(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) }
|
2017-12-14 15:51:45 +01:00
|
|
|
|
let!(:dossier) { create(:dossier, :en_construction, attestation: Attestation.new, procedure: procedure) }
|
2017-06-29 15:31:29 +02:00
|
|
|
|
|
|
|
|
|
it 'returns the attestation pdf' do
|
|
|
|
|
allow_any_instance_of(Attestation).to receive(:pdf).and_return(fake_pdf)
|
|
|
|
|
|
|
|
|
|
expect(controller).to receive(:send_data)
|
|
|
|
|
.with('pdf content', filename: 'attestation.pdf', type: 'application/pdf') do
|
2018-01-24 14:44:28 +01:00
|
|
|
|
controller.head :ok
|
2017-06-29 15:31:29 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
get :attestation, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-07-11 15:45:20 +02:00
|
|
|
|
|
2018-01-30 19:11:07 +01:00
|
|
|
|
describe '#envoyer_a_accompagnateur' do
|
|
|
|
|
let(:recipient) { create(:gestionnaire) }
|
|
|
|
|
let(:gestionnaires) { [gestionnaire, recipient] }
|
|
|
|
|
let(:mail) { double("mail") }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
expect(mail).to receive(:deliver_later)
|
|
|
|
|
|
|
|
|
|
expect(GestionnaireMailer)
|
|
|
|
|
.to receive(:send_dossier)
|
|
|
|
|
.with(gestionnaire, dossier, recipient)
|
|
|
|
|
.and_return(mail)
|
|
|
|
|
|
|
|
|
|
post(
|
|
|
|
|
:envoyer_a_accompagnateur,
|
|
|
|
|
params: {
|
|
|
|
|
recipient: recipient,
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2018-02-21 15:56:41 +01:00
|
|
|
|
it { expect(response).to redirect_to(personnes_impliquees_gestionnaire_dossier_url) }
|
2018-01-30 19:11:07 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#follow' do
|
|
|
|
|
before do
|
|
|
|
|
patch :follow, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
2017-07-11 15:45:20 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
it { expect(gestionnaire.followed_dossiers).to match([dossier]) }
|
|
|
|
|
it { expect(flash.notice).to eq('Dossier suivi') }
|
2018-02-21 15:56:41 +01:00
|
|
|
|
it { expect(response).to redirect_to(gestionnaire_procedures_url) }
|
2017-07-26 14:33:48 +02:00
|
|
|
|
end
|
2017-07-11 15:56:23 +02:00
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#unfollow' do
|
|
|
|
|
before do
|
|
|
|
|
gestionnaire.followed_dossiers << dossier
|
|
|
|
|
patch :unfollow, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
gestionnaire.reload
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
it { expect(gestionnaire.followed_dossiers).to match([]) }
|
|
|
|
|
it { expect(flash.notice).to eq("Vous ne suivez plus le dossier nº #{dossier.id}") }
|
2018-02-21 15:56:41 +01:00
|
|
|
|
it { expect(response).to redirect_to(gestionnaire_procedures_url) }
|
2017-07-26 14:33:48 +02:00
|
|
|
|
end
|
2017-07-06 16:33:36 +02:00
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#archive' do
|
|
|
|
|
before do
|
2017-09-25 18:13:10 +02:00
|
|
|
|
gestionnaire.follow(dossier)
|
2017-07-26 14:33:48 +02:00
|
|
|
|
patch :archive, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
dossier.reload
|
2017-09-25 18:13:10 +02:00
|
|
|
|
gestionnaire.reload
|
2017-07-06 16:33:36 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
it { expect(dossier.archived).to be true }
|
2018-02-21 15:56:41 +01:00
|
|
|
|
it { expect(response).to redirect_to(gestionnaire_procedures_url) }
|
2017-09-25 18:13:10 +02:00
|
|
|
|
it { expect(gestionnaire.followed_dossiers).not_to include(dossier) }
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#unarchive' do
|
|
|
|
|
before do
|
2018-03-02 16:27:03 +01:00
|
|
|
|
dossier.update(archived: true)
|
2017-07-26 14:33:48 +02:00
|
|
|
|
patch :unarchive, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
dossier.reload
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
it { expect(dossier.archived).to be false }
|
2018-02-21 15:56:41 +01:00
|
|
|
|
it { expect(response).to redirect_to(gestionnaire_procedures_url) }
|
2017-07-26 14:33:48 +02:00
|
|
|
|
end
|
2017-07-06 16:33:36 +02:00
|
|
|
|
|
2017-11-30 17:11:46 +01:00
|
|
|
|
describe '#passer_en_instruction' do
|
|
|
|
|
before do
|
2017-12-14 15:51:45 +01:00
|
|
|
|
dossier.en_construction!
|
2017-11-30 17:11:46 +01:00
|
|
|
|
sign_in gestionnaire
|
|
|
|
|
post :passer_en_instruction, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
dossier.reload
|
|
|
|
|
end
|
|
|
|
|
|
2017-12-14 15:53:02 +01:00
|
|
|
|
it { expect(dossier.state).to eq('en_instruction') }
|
2018-02-21 14:40:41 +01:00
|
|
|
|
it { is_expected.to redirect_to gestionnaire_dossier_path(procedure, dossier) }
|
2017-11-30 17:11:46 +01:00
|
|
|
|
it { expect(gestionnaire.follow?(dossier)).to be true }
|
|
|
|
|
end
|
|
|
|
|
|
2017-11-30 17:18:06 +01:00
|
|
|
|
describe '#repasser_en_construction' do
|
|
|
|
|
before do
|
2017-12-14 15:53:02 +01:00
|
|
|
|
dossier.en_instruction!
|
2017-11-30 17:18:06 +01:00
|
|
|
|
sign_in gestionnaire
|
|
|
|
|
end
|
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
|
subject { post :repasser_en_construction, params: { procedure_id: procedure.id, dossier_id: dossier.id } }
|
2017-11-30 17:18:06 +01:00
|
|
|
|
|
2017-12-14 15:51:45 +01:00
|
|
|
|
it 'change state to en_construction' do
|
2017-11-30 17:18:06 +01:00
|
|
|
|
subject
|
|
|
|
|
|
|
|
|
|
dossier.reload
|
2017-12-14 15:51:45 +01:00
|
|
|
|
expect(dossier.state).to eq('en_construction')
|
2017-11-30 17:18:06 +01:00
|
|
|
|
end
|
|
|
|
|
|
2018-02-21 14:40:41 +01:00
|
|
|
|
it { is_expected.to redirect_to gestionnaire_dossier_path(procedure, dossier) }
|
2017-11-30 17:18:06 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-12-01 12:57:01 +01:00
|
|
|
|
describe '#terminer' do
|
2017-11-30 17:29:26 +01:00
|
|
|
|
context "with refuser" do
|
2017-12-01 12:57:01 +01:00
|
|
|
|
before do
|
2017-12-14 15:53:02 +01:00
|
|
|
|
dossier.en_instruction!
|
2017-12-01 12:57:01 +01:00
|
|
|
|
sign_in gestionnaire
|
|
|
|
|
end
|
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
|
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id } }
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2017-12-04 18:15:40 +01:00
|
|
|
|
it 'change state to refuse' do
|
2017-12-01 12:57:01 +01:00
|
|
|
|
subject
|
|
|
|
|
|
|
|
|
|
dossier.reload
|
2017-12-04 18:15:40 +01:00
|
|
|
|
expect(dossier.state).to eq('refuse')
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'Notification email is sent' do
|
2018-05-25 23:08:47 +02:00
|
|
|
|
expect(NotificationMailer).to receive(:send_refused_notification)
|
|
|
|
|
.with(dossier).and_return(NotificationMailer)
|
2018-05-25 18:05:28 +02:00
|
|
|
|
expect(NotificationMailer).to receive(:deliver_later)
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
|
2018-02-21 14:40:41 +01:00
|
|
|
|
it { is_expected.to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier) }
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-11-30 17:29:26 +01:00
|
|
|
|
context "with classer_sans_suite" do
|
2017-12-01 12:57:01 +01:00
|
|
|
|
before do
|
2017-12-14 15:53:02 +01:00
|
|
|
|
dossier.en_instruction!
|
2017-12-01 12:57:01 +01:00
|
|
|
|
sign_in gestionnaire
|
|
|
|
|
end
|
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
|
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id } }
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2017-12-04 20:23:57 +01:00
|
|
|
|
it 'change state to sans_suite' do
|
2017-12-01 12:57:01 +01:00
|
|
|
|
subject
|
|
|
|
|
|
|
|
|
|
dossier.reload
|
2017-12-04 20:23:57 +01:00
|
|
|
|
expect(dossier.state).to eq('sans_suite')
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'Notification email is sent' do
|
2018-05-25 23:08:47 +02:00
|
|
|
|
expect(NotificationMailer).to receive(:send_without_continuation_notification)
|
|
|
|
|
.with(dossier).and_return(NotificationMailer)
|
2018-05-25 18:05:28 +02:00
|
|
|
|
expect(NotificationMailer).to receive(:deliver_later)
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
|
2018-02-21 14:40:41 +01:00
|
|
|
|
it { is_expected.to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier) }
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-11-30 17:29:26 +01:00
|
|
|
|
context "with accepter" do
|
2017-12-01 12:57:01 +01:00
|
|
|
|
before do
|
2017-12-14 15:53:02 +01:00
|
|
|
|
dossier.en_instruction!
|
2017-12-01 12:57:01 +01:00
|
|
|
|
sign_in gestionnaire
|
|
|
|
|
|
2018-05-25 23:08:47 +02:00
|
|
|
|
expect(NotificationMailer).to receive(:send_closed_notification)
|
|
|
|
|
.with(dossier)
|
2017-12-01 12:57:01 +01:00
|
|
|
|
.and_return(NotificationMailer)
|
|
|
|
|
|
2018-05-25 18:05:28 +02:00
|
|
|
|
expect(NotificationMailer).to receive(:deliver_later)
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
|
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id } }
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2017-12-04 18:00:12 +01:00
|
|
|
|
it 'change state to accepte' do
|
2017-12-01 12:57:01 +01:00
|
|
|
|
subject
|
|
|
|
|
|
|
|
|
|
dossier.reload
|
2017-12-04 18:00:12 +01:00
|
|
|
|
expect(dossier.state).to eq('accepte')
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the dossier does not have any attestation' do
|
|
|
|
|
it 'Notification email is sent' do
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the dossier has an attestation' do
|
|
|
|
|
before do
|
|
|
|
|
attestation = Attestation.new
|
|
|
|
|
allow(attestation).to receive(:pdf).and_return(double(read: 'pdf', size: 2.megabytes))
|
|
|
|
|
|
|
|
|
|
allow_any_instance_of(Dossier).to receive(:build_attestation).and_return(attestation)
|
|
|
|
|
end
|
|
|
|
|
|
2018-03-08 17:17:18 +01:00
|
|
|
|
it 'The gestionnaire is sent back to the dossier page' do
|
|
|
|
|
subject
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2018-03-08 17:17:18 +01:00
|
|
|
|
is_expected.to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier)
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
2018-07-25 17:16:24 +02:00
|
|
|
|
|
|
|
|
|
context 'and the dossier has already an attestation' do
|
|
|
|
|
it 'should not crash' do
|
|
|
|
|
dossier.attestation = Attestation.new
|
|
|
|
|
dossier.save
|
|
|
|
|
expect(subject).to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier)
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
2017-12-21 17:21:31 +01:00
|
|
|
|
|
2017-12-22 16:42:21 +01:00
|
|
|
|
context 'when the attestation template uses the motivation field' do
|
2017-12-21 17:21:31 +01:00
|
|
|
|
let(:emailable) { false }
|
|
|
|
|
let(:template) { create(:attestation_template) }
|
|
|
|
|
let(:procedure) { create(:procedure, :published, attestation_template: template, gestionnaires: [gestionnaire]) }
|
|
|
|
|
|
|
|
|
|
subject do
|
2018-01-15 15:34:26 +01:00
|
|
|
|
post :terminer, params: {
|
|
|
|
|
process_action: "accepter",
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
|
dossier: { motivation: "Yallah" }
|
|
|
|
|
}
|
2017-12-21 17:21:31 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before do
|
2017-12-22 11:31:38 +01:00
|
|
|
|
Timecop.freeze(DateTime.now)
|
|
|
|
|
|
2017-12-21 17:21:31 +01:00
|
|
|
|
expect_any_instance_of(AttestationTemplate)
|
|
|
|
|
.to receive(:attestation_for)
|
2017-12-22 11:31:38 +01:00
|
|
|
|
.with(have_attributes(motivation: "Yallah", processed_at: DateTime.now))
|
2017-12-21 17:21:31 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-12-22 11:31:38 +01:00
|
|
|
|
after { Timecop.return }
|
|
|
|
|
|
2017-12-21 17:21:31 +01:00
|
|
|
|
it { subject }
|
|
|
|
|
end
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-07-24 11:45:03 +02:00
|
|
|
|
describe "#create_commentaire" do
|
2017-07-19 14:04:49 +02:00
|
|
|
|
let(:saved_commentaire) { dossier.commentaires.first }
|
2017-11-29 17:11:50 +01:00
|
|
|
|
let(:body) { "avant\napres" }
|
2017-10-30 16:16:20 +01:00
|
|
|
|
let(:file) { nil }
|
2017-11-08 16:37:04 +01:00
|
|
|
|
let(:scan_result) { true }
|
2017-07-19 14:04:49 +02:00
|
|
|
|
|
2017-11-08 16:37:04 +01:00
|
|
|
|
subject {
|
2017-07-19 14:04:49 +02:00
|
|
|
|
post :create_commentaire, params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id,
|
2017-10-30 16:16:20 +01:00
|
|
|
|
commentaire: {
|
2017-11-07 20:40:00 +01:00
|
|
|
|
body: body,
|
2017-10-30 16:16:20 +01:00
|
|
|
|
file: file
|
|
|
|
|
}
|
2017-07-19 14:04:49 +02:00
|
|
|
|
}
|
2017-11-08 16:37:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
|
2017-07-19 14:04:49 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-11-08 16:37:04 +01:00
|
|
|
|
it do
|
|
|
|
|
subject
|
|
|
|
|
|
2017-11-29 17:11:50 +01:00
|
|
|
|
expect(saved_commentaire.body).to eq("<p>avant\n<br />apres</p>")
|
2017-11-08 16:37:04 +01:00
|
|
|
|
expect(saved_commentaire.email).to eq(gestionnaire.email)
|
|
|
|
|
expect(saved_commentaire.dossier).to eq(dossier)
|
2018-02-21 13:42:11 +01:00
|
|
|
|
expect(response).to redirect_to(messagerie_gestionnaire_dossier_path(dossier.procedure, dossier))
|
2017-11-08 16:37:04 +01:00
|
|
|
|
expect(gestionnaire.followed_dossiers).to include(dossier)
|
|
|
|
|
expect(saved_commentaire.file.present?).to eq(false)
|
|
|
|
|
end
|
2017-10-30 16:16:20 +01:00
|
|
|
|
|
2017-11-07 20:40:00 +01:00
|
|
|
|
it { expect { subject }.to change(Commentaire, :count).by(1) }
|
|
|
|
|
|
|
|
|
|
context "without a body" do
|
|
|
|
|
let(:body) { nil }
|
|
|
|
|
|
|
|
|
|
it { expect { subject }.not_to change(Commentaire, :count) }
|
|
|
|
|
end
|
|
|
|
|
|
2017-10-30 16:16:20 +01:00
|
|
|
|
context "with a file" do
|
|
|
|
|
let(:file) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
|
|
|
|
|
|
2017-11-08 16:37:04 +01:00
|
|
|
|
it { subject; expect(saved_commentaire.file.present?).to eq(true) }
|
|
|
|
|
it { expect { subject }.to change(Commentaire, :count).by(1) }
|
|
|
|
|
|
|
|
|
|
context "and a virus" do
|
|
|
|
|
let(:scan_result) { false }
|
|
|
|
|
|
|
|
|
|
it { expect { subject }.not_to change(Commentaire, :count) }
|
|
|
|
|
end
|
2017-10-30 16:16:20 +01:00
|
|
|
|
end
|
2017-07-19 14:04:49 +02:00
|
|
|
|
end
|
2017-08-28 14:16:13 +02:00
|
|
|
|
|
|
|
|
|
describe "#create_avis" do
|
|
|
|
|
let(:saved_avis) { dossier.avis.first }
|
|
|
|
|
|
2018-02-27 16:58:22 +01:00
|
|
|
|
subject do
|
2017-08-28 14:16:13 +02:00
|
|
|
|
post :create_avis, params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id,
|
2018-02-27 16:58:22 +01:00
|
|
|
|
avis: { email: email, introduction: 'intro', confidentiel: true }
|
2017-08-28 14:16:13 +02:00
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2018-02-27 16:58:22 +01:00
|
|
|
|
before do
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:email) { 'email@a.com' }
|
|
|
|
|
|
2017-08-28 14:16:13 +02:00
|
|
|
|
it { expect(saved_avis.email).to eq('email@a.com') }
|
|
|
|
|
it { expect(saved_avis.introduction).to eq('intro') }
|
2017-09-20 10:42:16 +02:00
|
|
|
|
it { expect(saved_avis.confidentiel).to eq(true) }
|
2017-08-28 14:16:13 +02:00
|
|
|
|
it { expect(saved_avis.dossier).to eq(dossier) }
|
|
|
|
|
it { expect(saved_avis.claimant).to eq(gestionnaire) }
|
2018-02-21 13:42:11 +01:00
|
|
|
|
it { expect(response).to redirect_to(avis_gestionnaire_dossier_path(dossier.procedure, dossier)) }
|
2018-02-27 16:58:22 +01:00
|
|
|
|
|
|
|
|
|
context "with an invalid email" do
|
|
|
|
|
let(:email) { 'emaila.com' }
|
|
|
|
|
|
|
|
|
|
it { expect(response).to render_template :avis }
|
|
|
|
|
it { expect(flash.alert).to eq(["Email n'est pas valide"]) }
|
|
|
|
|
it { expect { subject }.not_to change(Avis, :count) }
|
|
|
|
|
end
|
2017-08-28 14:16:13 +02:00
|
|
|
|
end
|
2017-08-02 15:33:23 +02:00
|
|
|
|
|
|
|
|
|
describe "#update_annotations" do
|
|
|
|
|
let(:champ_multiple_drop_down_list) do
|
2018-02-14 15:12:57 +01:00
|
|
|
|
create(:type_de_champ_multiple_drop_down_list, :private, libelle: 'libelle').champ.create
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-07-12 10:37:27 +02:00
|
|
|
|
let(:champ_linked_drop_down_list) do
|
|
|
|
|
create(:type_de_champ_linked_drop_down_list, :private, libelle: 'libelle').champ.create
|
|
|
|
|
end
|
|
|
|
|
|
2017-08-02 15:33:23 +02:00
|
|
|
|
let(:champ_datetime) do
|
2018-02-14 15:12:57 +01:00
|
|
|
|
create(:type_de_champ_datetime, :private, libelle: 'libelle').champ.create
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:dossier) do
|
2018-07-12 10:37:27 +02:00
|
|
|
|
create(:dossier, :en_construction, procedure: procedure, champs_private: [champ_multiple_drop_down_list, champ_linked_drop_down_list, champ_datetime])
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
patch :update_annotations, params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
|
dossier: {
|
|
|
|
|
champs_private_attributes: {
|
|
|
|
|
'0': {
|
|
|
|
|
id: champ_multiple_drop_down_list.id,
|
|
|
|
|
value: ['', 'un', 'deux']
|
|
|
|
|
},
|
|
|
|
|
'1': {
|
|
|
|
|
id: champ_datetime.id,
|
|
|
|
|
'value(1i)': 2019,
|
|
|
|
|
'value(2i)': 12,
|
|
|
|
|
'value(3i)': 21,
|
|
|
|
|
'value(4i)': 13,
|
|
|
|
|
'value(5i)': 17
|
2018-07-12 10:37:27 +02:00
|
|
|
|
},
|
|
|
|
|
'2': {
|
|
|
|
|
id: champ_linked_drop_down_list.id,
|
|
|
|
|
primary_value: 'primary',
|
|
|
|
|
secondary_value: 'secondary'
|
2017-08-02 15:33:23 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
champ_multiple_drop_down_list.reload
|
2018-07-12 10:37:27 +02:00
|
|
|
|
champ_linked_drop_down_list.reload
|
2017-08-02 15:33:23 +02:00
|
|
|
|
champ_datetime.reload
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(champ_multiple_drop_down_list.value).to eq('["un", "deux"]') }
|
2018-07-12 10:37:27 +02:00
|
|
|
|
it { expect(champ_linked_drop_down_list.primary_value).to eq('primary') }
|
|
|
|
|
it { expect(champ_linked_drop_down_list.secondary_value).to eq('secondary') }
|
2017-08-02 15:33:23 +02:00
|
|
|
|
it { expect(champ_datetime.value).to eq('21/12/2019 13:17') }
|
2018-02-21 13:42:11 +01:00
|
|
|
|
it { expect(response).to redirect_to(annotations_privees_gestionnaire_dossier_path(dossier.procedure, dossier)) }
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
2017-06-29 15:31:29 +02:00
|
|
|
|
end
|