2017-06-29 15:30:42 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
describe Instructeurs::ProceduresController, type: :controller do
|
2017-07-04 10:26:50 +02:00
|
|
|
describe "before_action: ensure_ownership!" do
|
|
|
|
it "is present" do
|
2019-08-06 11:02:54 +02:00
|
|
|
before_actions = Instructeurs::ProceduresController
|
2017-06-29 15:30:42 +02:00
|
|
|
._process_action_callbacks
|
2019-09-12 11:26:22 +02:00
|
|
|
.filter { |process_action_callbacks| process_action_callbacks.kind == :before }
|
2017-06-29 15:30:42 +02:00
|
|
|
.map(&:filter)
|
|
|
|
|
|
|
|
expect(before_actions).to include(:ensure_ownership!)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-04 10:26:50 +02:00
|
|
|
describe "ensure_ownership!" do
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { create(:instructeur) }
|
2017-06-29 15:30:42 +02:00
|
|
|
|
|
|
|
before do
|
2018-01-23 18:28:09 +01:00
|
|
|
@controller.params = @controller.params.merge(procedure_id: asked_procedure.id)
|
2019-08-06 11:02:54 +02:00
|
|
|
expect(@controller).to receive(:current_instructeur).and_return(instructeur)
|
2017-06-29 15:30:42 +02:00
|
|
|
allow(@controller).to receive(:redirect_to)
|
|
|
|
|
|
|
|
@controller.send(:ensure_ownership!)
|
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context "when a instructeur asks for its procedure" do
|
|
|
|
let(:asked_procedure) { create(:procedure, instructeurs: [instructeur]) }
|
2017-06-29 15:30:42 +02:00
|
|
|
|
2017-07-04 10:26:50 +02:00
|
|
|
it "does not redirects nor flash" do
|
2017-06-29 15:30:42 +02:00
|
|
|
expect(@controller).not_to have_received(:redirect_to)
|
|
|
|
expect(flash.alert).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context "when a instructeur asks for another procedure" do
|
2017-06-29 15:30:42 +02:00
|
|
|
let(:asked_procedure) { create(:procedure) }
|
|
|
|
|
2017-07-04 10:26:50 +02:00
|
|
|
it "redirects and flash" do
|
2017-06-29 15:30:42 +02:00
|
|
|
expect(@controller).to have_received(:redirect_to).with(root_path)
|
2018-09-05 14:48:42 +02:00
|
|
|
expect(flash.alert).to eq("Vous n'avez pas accès à cette démarche")
|
2017-06-29 15:30:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-07-04 13:52:08 +02:00
|
|
|
|
2017-09-07 16:04:53 +02:00
|
|
|
describe "before_action: redirect_to_avis_if_needed" do
|
|
|
|
it "is present" do
|
2019-08-06 11:02:54 +02:00
|
|
|
before_actions = Instructeurs::ProceduresController
|
2017-09-07 16:04:53 +02:00
|
|
|
._process_action_callbacks
|
2019-09-12 11:26:22 +02:00
|
|
|
.filter { |process_action_callbacks| process_action_callbacks.kind == :before }
|
2017-09-07 16:04:53 +02:00
|
|
|
.map(&:filter)
|
|
|
|
|
|
|
|
expect(before_actions).to include(:redirect_to_avis_if_needed)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "redirect_to_avis_if_needed" do
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { create(:instructeur) }
|
2017-09-07 16:04:53 +02:00
|
|
|
|
|
|
|
before do
|
2019-08-06 11:02:54 +02:00
|
|
|
expect(@controller).to receive(:current_instructeur).at_least(:once).and_return(instructeur)
|
2017-09-07 16:04:53 +02:00
|
|
|
allow(@controller).to receive(:redirect_to)
|
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context "when a instructeur has some procedures" do
|
|
|
|
let!(:some_procedure) { create(:procedure, instructeurs: [instructeur]) }
|
2017-09-07 16:04:53 +02:00
|
|
|
|
|
|
|
before { @controller.send(:redirect_to_avis_if_needed) }
|
|
|
|
|
|
|
|
it "does not redirects nor flash" do
|
|
|
|
expect(@controller).not_to have_received(:redirect_to)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context "when a instructeur has no procedure and some avis" do
|
2017-09-07 16:04:53 +02:00
|
|
|
before do
|
2019-08-06 11:02:54 +02:00
|
|
|
Avis.create!(dossier: create(:dossier), claimant: create(:instructeur), instructeur: instructeur)
|
2017-09-07 16:04:53 +02:00
|
|
|
@controller.send(:redirect_to_avis_if_needed)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "redirects avis" do
|
2019-08-06 11:02:54 +02:00
|
|
|
expect(@controller).to have_received(:redirect_to).with(instructeur_avis_index_path)
|
2017-09-07 16:04:53 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-04 13:52:08 +02:00
|
|
|
describe "#index" do
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { create(:instructeur) }
|
2017-07-04 13:52:08 +02:00
|
|
|
subject { get :index }
|
|
|
|
|
|
|
|
context "when not logged" do
|
|
|
|
before { subject }
|
2018-01-15 21:54:40 +01:00
|
|
|
it { expect(response).to redirect_to(new_user_session_path) }
|
2017-07-04 13:52:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in" do
|
2019-08-07 11:15:16 +02:00
|
|
|
before { sign_in(instructeur.user) }
|
2017-07-04 13:52:08 +02:00
|
|
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
|
|
|
|
|
|
|
context "with procedures assigned" do
|
|
|
|
let(:procedure1) { create(:procedure, :published) }
|
2019-11-14 09:43:45 +01:00
|
|
|
let(:procedure2) { create(:procedure, :closed) }
|
2017-07-04 13:52:08 +02:00
|
|
|
let(:procedure3) { create(:procedure) }
|
|
|
|
|
|
|
|
before do
|
2019-08-20 18:03:33 +02:00
|
|
|
instructeur.groupe_instructeurs << procedure1.defaut_groupe_instructeur
|
|
|
|
instructeur.groupe_instructeurs << procedure2.defaut_groupe_instructeur
|
|
|
|
instructeur.groupe_instructeurs << procedure3.defaut_groupe_instructeur
|
2017-07-04 13:52:08 +02:00
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
2017-07-18 15:26:33 +02:00
|
|
|
it { expect(assigns(:procedures)).to include(procedure1, procedure2) }
|
2017-07-04 13:52:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with dossiers" do
|
|
|
|
let(:procedure) { create(:procedure, :published) }
|
|
|
|
let(:dossier) { create(:dossier, state: state, procedure: procedure) }
|
|
|
|
|
|
|
|
before do
|
2019-08-20 18:03:33 +02:00
|
|
|
instructeur.groupe_instructeurs << procedure.defaut_groupe_instructeur
|
2017-07-04 13:52:08 +02:00
|
|
|
dossier
|
|
|
|
end
|
|
|
|
|
2017-12-04 16:17:15 +01:00
|
|
|
context "with brouillon state" do
|
2018-08-28 14:10:55 +02:00
|
|
|
let(:state) { Dossier.states.fetch(:brouillon) }
|
2017-07-04 13:52:08 +02:00
|
|
|
before { subject }
|
|
|
|
|
2019-09-12 17:26:59 +02:00
|
|
|
it { expect(assigns(:dossiers_count_per_procedure)[procedure.id]).to eq(nil) }
|
|
|
|
it { expect(assigns(:dossiers_a_suivre_count_per_procedure)[procedure.id]).to eq(nil) }
|
|
|
|
it { expect(assigns(:dossiers_archived_count_per_procedure)[procedure.id]).to eq(nil) }
|
|
|
|
it { expect(assigns(:followed_dossiers_count_per_procedure)[procedure.id]).to eq(nil) }
|
|
|
|
it { expect(assigns(:dossiers_termines_count_per_procedure)[procedure.id]).to eq(nil) }
|
2017-07-04 13:52:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with not draft state on multiple procedures" do
|
|
|
|
let(:procedure2) { create(:procedure, :published) }
|
2018-08-28 14:10:55 +02:00
|
|
|
let(:state) { Dossier.states.fetch(:en_construction) }
|
2017-07-04 13:52:08 +02:00
|
|
|
|
|
|
|
before do
|
2018-08-28 14:10:55 +02:00
|
|
|
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_construction))
|
|
|
|
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction))
|
|
|
|
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:sans_suite), archived: true)
|
2017-07-17 11:22:12 +02:00
|
|
|
|
2019-08-20 18:03:33 +02:00
|
|
|
instructeur.groupe_instructeurs << procedure2.defaut_groupe_instructeur
|
2018-08-28 14:10:55 +02:00
|
|
|
create(:dossier, :followed, procedure: procedure2, state: Dossier.states.fetch(:en_construction))
|
|
|
|
create(:dossier, procedure: procedure2, state: Dossier.states.fetch(:accepte))
|
2019-08-06 11:02:54 +02:00
|
|
|
instructeur.followed_dossiers << create(:dossier, procedure: procedure2, state: Dossier.states.fetch(:en_instruction))
|
2017-07-17 11:22:12 +02:00
|
|
|
|
2017-07-04 13:52:08 +02:00
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
2019-09-12 17:26:59 +02:00
|
|
|
it { expect(assigns(:dossiers_count_per_procedure)[procedure.id]).to eq(3) }
|
|
|
|
it { expect(assigns(:dossiers_a_suivre_count_per_procedure)[procedure.id]).to eq(3) }
|
|
|
|
it { expect(assigns(:followed_dossiers_count_per_procedure)[procedure.id]).to eq(nil) }
|
|
|
|
it { expect(assigns(:dossiers_archived_count_per_procedure)[procedure.id]).to eq(1) }
|
|
|
|
it { expect(assigns(:dossiers_termines_count_per_procedure)[procedure.id]).to eq(nil) }
|
|
|
|
|
|
|
|
it { expect(assigns(:dossiers_count_per_procedure)[procedure2.id]).to eq(3) }
|
|
|
|
it { expect(assigns(:dossiers_a_suivre_count_per_procedure)[procedure2.id]).to eq(nil) }
|
|
|
|
it { expect(assigns(:followed_dossiers_count_per_procedure)[procedure2.id]).to eq(1) }
|
|
|
|
it { expect(assigns(:dossiers_archived_count_per_procedure)[procedure2.id]).to eq(nil) }
|
|
|
|
it { expect(assigns(:dossiers_termines_count_per_procedure)[procedure2.id]).to eq(1) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a routed procedure" do
|
|
|
|
let!(:procedure) { create(:procedure, :published) }
|
|
|
|
let!(:gi_p1_1) { procedure.defaut_groupe_instructeur }
|
|
|
|
let!(:gi_p1_2) { GroupeInstructeur.create(label: '2', procedure: procedure) }
|
|
|
|
|
|
|
|
context 'with multiple dossiers en construction on each group' do
|
|
|
|
before do
|
|
|
|
alternate_gis = 0.upto(20).map { |i| i.even? ? gi_p1_1 : gi_p1_2 }
|
|
|
|
|
|
|
|
alternate_gis.take(4).each { |gi| create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_construction), groupe_instructeur: gi) }
|
|
|
|
|
|
|
|
alternate_gis.take(6).each do |gi|
|
|
|
|
instructeur.followed_dossiers << create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction), groupe_instructeur: gi)
|
|
|
|
end
|
|
|
|
|
|
|
|
alternate_gis.take(10).each { |gi| create(:dossier, procedure: procedure, state: Dossier.states.fetch(:sans_suite), groupe_instructeur: gi) }
|
|
|
|
alternate_gis.take(14).each { |gi| create(:dossier, procedure: procedure, state: Dossier.states.fetch(:sans_suite), archived: true, groupe_instructeur: gi) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an instructeur belongs to the 2 gi' do
|
|
|
|
before do
|
|
|
|
instructeur.groupe_instructeurs << gi_p1_1 << gi_p1_2
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(assigns(:dossiers_a_suivre_count_per_procedure)[procedure.id]).to eq(4) }
|
|
|
|
it { expect(assigns(:followed_dossiers_count_per_procedure)[procedure.id]).to eq(6) }
|
|
|
|
it { expect(assigns(:dossiers_termines_count_per_procedure)[procedure.id]).to eq(10) }
|
|
|
|
it { expect(assigns(:dossiers_count_per_procedure)[procedure.id]).to eq(4 + 6 + 10) }
|
|
|
|
it { expect(assigns(:dossiers_archived_count_per_procedure)[procedure.id]).to eq(14) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an instructeur only belongs to one of them gi' do
|
|
|
|
before do
|
|
|
|
instructeur.groupe_instructeurs << gi_p1_1
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(assigns(:dossiers_a_suivre_count_per_procedure)[procedure.id]).to eq(2) }
|
|
|
|
# An instructeur cannot follow a dossier which belongs to another groupe
|
|
|
|
it { expect(assigns(:followed_dossiers_count_per_procedure)[procedure.id]).to eq(3) }
|
|
|
|
it { expect(assigns(:dossiers_termines_count_per_procedure)[procedure.id]).to eq(5) }
|
|
|
|
it { expect(assigns(:dossiers_count_per_procedure)[procedure.id]).to eq(2 + 3 + 5) }
|
|
|
|
it { expect(assigns(:dossiers_archived_count_per_procedure)[procedure.id]).to eq(7) }
|
|
|
|
end
|
2017-07-04 13:52:08 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-07-11 16:09:03 +02:00
|
|
|
|
|
|
|
describe "#show" do
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { create(:instructeur) }
|
|
|
|
let!(:procedure) { create(:procedure, instructeurs: [instructeur]) }
|
2019-09-18 13:44:00 +02:00
|
|
|
let!(:gi_2) { procedure.groupe_instructeurs.create(label: '2') }
|
|
|
|
let!(:gi_3) { procedure.groupe_instructeurs.create(label: '3') }
|
2017-07-11 16:09:03 +02:00
|
|
|
|
2019-09-18 13:44:00 +02:00
|
|
|
context "when logged in, and belonging to gi_1, gi_2" do
|
2017-07-11 16:09:03 +02:00
|
|
|
before do
|
2019-08-07 11:15:16 +02:00
|
|
|
sign_in(instructeur.user)
|
2019-09-18 13:44:00 +02:00
|
|
|
|
|
|
|
instructeur.groupe_instructeurs << gi_2
|
2017-07-11 16:09:03 +02:00
|
|
|
end
|
|
|
|
|
2017-09-28 19:07:18 +02:00
|
|
|
context "without anything" do
|
|
|
|
before { get :show, params: { procedure_id: procedure.id } }
|
|
|
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
|
|
|
it { expect(assigns(:procedure)).to eq(procedure) }
|
|
|
|
end
|
2017-07-11 16:09:03 +02:00
|
|
|
|
2017-12-04 16:17:15 +01:00
|
|
|
context 'with a new brouillon dossier' do
|
2018-08-28 14:10:55 +02:00
|
|
|
let!(:brouillon_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:brouillon)) }
|
2017-07-11 16:09:03 +02:00
|
|
|
|
2017-09-28 19:07:18 +02:00
|
|
|
before do
|
|
|
|
get :show, params: { procedure_id: procedure.id }
|
|
|
|
end
|
|
|
|
|
2017-07-11 16:09:03 +02:00
|
|
|
it { expect(assigns(:a_suivre_dossiers)).to be_empty }
|
|
|
|
it { expect(assigns(:followed_dossiers)).to be_empty }
|
|
|
|
it { expect(assigns(:termines_dossiers)).to be_empty }
|
|
|
|
it { expect(assigns(:all_state_dossiers)).to be_empty }
|
|
|
|
it { expect(assigns(:archived_dossiers)).to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a new dossier without follower' do
|
2018-08-28 14:10:55 +02:00
|
|
|
let!(:new_unfollow_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
|
2017-07-11 16:09:03 +02:00
|
|
|
|
2017-09-28 19:07:18 +02:00
|
|
|
before do
|
|
|
|
get :show, params: { procedure_id: procedure.id }
|
|
|
|
end
|
|
|
|
|
2017-07-11 16:09:03 +02:00
|
|
|
it { expect(assigns(:a_suivre_dossiers)).to match([new_unfollow_dossier]) }
|
|
|
|
it { expect(assigns(:followed_dossiers)).to be_empty }
|
|
|
|
it { expect(assigns(:termines_dossiers)).to be_empty }
|
|
|
|
it { expect(assigns(:all_state_dossiers)).to match([new_unfollow_dossier]) }
|
|
|
|
it { expect(assigns(:archived_dossiers)).to be_empty }
|
2019-09-18 13:44:00 +02:00
|
|
|
|
|
|
|
context 'and dossiers without follower on each of the others groups' do
|
|
|
|
let!(:new_unfollow_dossier_on_gi_2) { create(:dossier, groupe_instructeur: gi_2, state: Dossier.states.fetch(:en_instruction)) }
|
|
|
|
let!(:new_unfollow_dossier_on_gi_3) { create(:dossier, groupe_instructeur: gi_3, state: Dossier.states.fetch(:en_instruction)) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
get :show, params: { procedure_id: procedure.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(assigns(:a_suivre_dossiers)).to match([new_unfollow_dossier, new_unfollow_dossier_on_gi_2]) }
|
|
|
|
it { expect(assigns(:all_state_dossiers)).to match([new_unfollow_dossier, new_unfollow_dossier_on_gi_2]) }
|
|
|
|
end
|
2017-07-11 16:09:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a new dossier with a follower' do
|
2018-08-28 14:10:55 +02:00
|
|
|
let!(:new_followed_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
|
2017-07-11 16:09:03 +02:00
|
|
|
|
2017-09-28 19:07:18 +02:00
|
|
|
before do
|
2019-08-06 11:02:54 +02:00
|
|
|
instructeur.followed_dossiers << new_followed_dossier
|
2017-09-28 19:07:18 +02:00
|
|
|
get :show, params: { procedure_id: procedure.id }
|
|
|
|
end
|
2017-07-11 16:09:03 +02:00
|
|
|
|
|
|
|
it { expect(assigns(:a_suivre_dossiers)).to be_empty }
|
|
|
|
it { expect(assigns(:followed_dossiers)).to match([new_followed_dossier]) }
|
|
|
|
it { expect(assigns(:termines_dossiers)).to be_empty }
|
|
|
|
it { expect(assigns(:all_state_dossiers)).to match([new_followed_dossier]) }
|
|
|
|
it { expect(assigns(:archived_dossiers)).to be_empty }
|
2019-09-18 13:44:00 +02:00
|
|
|
|
|
|
|
context 'and dossier with a follower on each of the others groups' do
|
|
|
|
let!(:new_follow_dossier_on_gi_2) { create(:dossier, groupe_instructeur: gi_2, state: Dossier.states.fetch(:en_instruction)) }
|
|
|
|
let!(:new_follow_dossier_on_gi_3) { create(:dossier, groupe_instructeur: gi_3, state: Dossier.states.fetch(:en_instruction)) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
instructeur.followed_dossiers << new_follow_dossier_on_gi_2 << new_follow_dossier_on_gi_3
|
|
|
|
get :show, params: { procedure_id: procedure.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
# followed dossiers on another groupe should not be displayed
|
|
|
|
it { expect(assigns(:followed_dossiers)).to contain_exactly(new_followed_dossier, new_follow_dossier_on_gi_2) }
|
|
|
|
it { expect(assigns(:all_state_dossiers)).to contain_exactly(new_followed_dossier, new_follow_dossier_on_gi_2) }
|
|
|
|
end
|
2017-07-11 16:09:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a termine dossier with a follower' do
|
2018-08-28 14:10:55 +02:00
|
|
|
let!(:termine_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:accepte)) }
|
2017-07-11 16:09:03 +02:00
|
|
|
|
2017-09-28 19:07:18 +02:00
|
|
|
before do
|
|
|
|
get :show, params: { procedure_id: procedure.id }
|
|
|
|
end
|
|
|
|
|
2017-07-11 16:09:03 +02:00
|
|
|
it { expect(assigns(:a_suivre_dossiers)).to be_empty }
|
|
|
|
it { expect(assigns(:followed_dossiers)).to be_empty }
|
|
|
|
it { expect(assigns(:termines_dossiers)).to match([termine_dossier]) }
|
|
|
|
it { expect(assigns(:all_state_dossiers)).to match([termine_dossier]) }
|
|
|
|
it { expect(assigns(:archived_dossiers)).to be_empty }
|
2019-09-18 13:44:00 +02:00
|
|
|
|
|
|
|
context 'and terminer dossiers on each of the others groups' do
|
|
|
|
let!(:termine_dossier_on_gi_2) { create(:dossier, groupe_instructeur: gi_2, state: Dossier.states.fetch(:accepte)) }
|
|
|
|
let!(:termine_dossier_on_gi_3) { create(:dossier, groupe_instructeur: gi_3, state: Dossier.states.fetch(:accepte)) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
get :show, params: { procedure_id: procedure.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(assigns(:termines_dossiers)).to match([termine_dossier, termine_dossier_on_gi_2]) }
|
|
|
|
it { expect(assigns(:all_state_dossiers)).to match([termine_dossier, termine_dossier_on_gi_2]) }
|
|
|
|
end
|
2017-07-11 16:09:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an archived dossier' do
|
2018-08-28 14:10:55 +02:00
|
|
|
let!(:archived_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction), archived: true) }
|
2017-07-11 16:09:03 +02:00
|
|
|
|
2017-09-28 19:07:18 +02:00
|
|
|
before do
|
|
|
|
get :show, params: { procedure_id: procedure.id }
|
|
|
|
end
|
|
|
|
|
2017-07-11 16:09:03 +02:00
|
|
|
it { expect(assigns(:a_suivre_dossiers)).to be_empty }
|
|
|
|
it { expect(assigns(:followed_dossiers)).to be_empty }
|
|
|
|
it { expect(assigns(:termines_dossiers)).to be_empty }
|
|
|
|
it { expect(assigns(:all_state_dossiers)).to be_empty }
|
|
|
|
it { expect(assigns(:archived_dossiers)).to match([archived_dossier]) }
|
2019-09-18 13:44:00 +02:00
|
|
|
|
|
|
|
context 'and terminer dossiers on each of the others groups' do
|
|
|
|
let!(:archived_dossier_on_gi_2) { create(:dossier, groupe_instructeur: gi_2, state: Dossier.states.fetch(:en_instruction), archived: true) }
|
|
|
|
let!(:archived_dossier_on_gi_3) { create(:dossier, groupe_instructeur: gi_3, state: Dossier.states.fetch(:en_instruction), archived: true) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
get :show, params: { procedure_id: procedure.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(assigns(:archived_dossiers)).to match([archived_dossier, archived_dossier_on_gi_2]) }
|
|
|
|
end
|
2017-07-11 16:09:03 +02:00
|
|
|
end
|
2017-07-11 15:40:09 +02:00
|
|
|
|
|
|
|
describe 'statut' do
|
2018-12-24 17:28:20 +01:00
|
|
|
let!(:a_suivre__dossier) { Timecop.freeze(1.day.ago) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) } }
|
|
|
|
let!(:new_followed_dossier) { Timecop.freeze(2.days.ago) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) } }
|
|
|
|
let!(:termine_dossier) { Timecop.freeze(3.days.ago) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:accepte)) } }
|
|
|
|
let!(:archived_dossier) { Timecop.freeze(4.days.ago) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction), archived: true) } }
|
2017-09-28 19:07:18 +02:00
|
|
|
|
2017-07-11 15:40:09 +02:00
|
|
|
before do
|
2019-08-06 11:02:54 +02:00
|
|
|
instructeur.followed_dossiers << new_followed_dossier
|
2017-07-11 15:40:09 +02:00
|
|
|
get :show, params: { procedure_id: procedure.id, statut: statut }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when statut is empty' do
|
|
|
|
let(:statut) { nil }
|
|
|
|
|
|
|
|
it { expect(assigns(:dossiers)).to match([a_suivre__dossier]) }
|
|
|
|
it { expect(assigns(:statut)).to eq('a-suivre') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when statut is a-suivre' do
|
|
|
|
let(:statut) { 'a-suivre' }
|
|
|
|
|
|
|
|
it { expect(assigns(:statut)).to eq('a-suivre') }
|
|
|
|
it { expect(assigns(:dossiers)).to match([a_suivre__dossier]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when statut is suivis' do
|
|
|
|
let(:statut) { 'suivis' }
|
|
|
|
|
|
|
|
it { expect(assigns(:statut)).to eq('suivis') }
|
|
|
|
it { expect(assigns(:dossiers)).to match([new_followed_dossier]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when statut is traites' do
|
|
|
|
let(:statut) { 'traites' }
|
|
|
|
|
|
|
|
it { expect(assigns(:statut)).to eq('traites') }
|
|
|
|
it { expect(assigns(:dossiers)).to match([termine_dossier]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when statut is tous' do
|
|
|
|
let(:statut) { 'tous' }
|
|
|
|
|
|
|
|
it { expect(assigns(:statut)).to eq('tous') }
|
2017-11-01 20:40:33 +01:00
|
|
|
it { expect(assigns(:dossiers)).to match_array([a_suivre__dossier, new_followed_dossier, termine_dossier]) }
|
2017-07-11 15:40:09 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when statut is archives' do
|
|
|
|
let(:statut) { 'archives' }
|
|
|
|
|
|
|
|
it { expect(assigns(:statut)).to eq('archives') }
|
|
|
|
it { expect(assigns(:dossiers)).to match([archived_dossier]) }
|
|
|
|
end
|
|
|
|
end
|
2017-07-11 16:09:03 +02:00
|
|
|
end
|
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
|
|
|
|
describe "#download_dossiers" do
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { create(:instructeur) }
|
|
|
|
let!(:procedure) { create(:procedure, instructeurs: [instructeur]) }
|
2019-09-18 16:51:45 +02:00
|
|
|
let!(:gi_2) { procedure.groupe_instructeurs.create(label: '2') }
|
|
|
|
let!(:dossier_1) { create(:dossier, procedure: procedure) }
|
|
|
|
let!(:dossier_2) { create(:dossier, groupe_instructeur: gi_2) }
|
2018-11-22 00:14:16 +01:00
|
|
|
|
|
|
|
context "when logged in" do
|
|
|
|
before do
|
2019-08-07 11:15:16 +02:00
|
|
|
sign_in(instructeur.user)
|
2018-11-22 00:14:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "csv" do
|
2019-09-18 16:51:45 +02:00
|
|
|
before do
|
|
|
|
expect_any_instance_of(Procedure).to receive(:to_csv)
|
2019-06-25 15:46:10 +02:00
|
|
|
.with(instructeur.dossiers.for_procedure(procedure))
|
2019-09-18 16:51:45 +02:00
|
|
|
|
|
|
|
get :download_dossiers, params: { procedure_id: procedure.id }, format: 'csv'
|
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "xlsx" do
|
|
|
|
before { get :download_dossiers, params: { procedure_id: procedure.id }, format: 'xlsx' }
|
|
|
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "ods" do
|
|
|
|
before { get :download_dossiers, params: { procedure_id: procedure.id }, format: 'ods' }
|
|
|
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-03-13 17:37:07 +01:00
|
|
|
|
|
|
|
describe '#update_email_notifications' do
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { create(:instructeur) }
|
|
|
|
let!(:procedure) { create(:procedure, instructeurs: [instructeur]) }
|
2019-03-13 17:37:07 +01:00
|
|
|
|
|
|
|
context "when logged in" do
|
2019-08-07 11:15:16 +02:00
|
|
|
before { sign_in(instructeur.user) }
|
2019-03-13 17:37:07 +01:00
|
|
|
|
2019-08-22 17:58:31 +02:00
|
|
|
it { expect(instructeur.groupe_instructeur_with_email_notifications).to be_empty }
|
2019-03-13 17:37:07 +01:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'when the instructeur update its preferences' do
|
2019-08-26 16:17:25 +02:00
|
|
|
let(:assign_to) { instructeur.assign_to.joins(:groupe_instructeur).find_by(groupe_instructeurs: { procedure: procedure }) }
|
2019-03-13 17:37:07 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
patch :update_email_notifications, params: { procedure_id: procedure.id, assign_to: { id: assign_to.id, email_notifications_enabled: true } }
|
|
|
|
end
|
|
|
|
|
2019-08-22 17:58:31 +02:00
|
|
|
it { expect(instructeur.groupe_instructeur_with_email_notifications).to eq([procedure.defaut_groupe_instructeur]) }
|
2019-03-13 17:37:07 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-06-29 15:30:42 +02:00
|
|
|
end
|