specs: refactor instructeur procedures controller specs

This commit is contained in:
Pierre de La Morinerie 2020-04-22 13:52:28 +00:00
parent 93516c3101
commit abe692ecc2

View file

@ -224,16 +224,20 @@ describe Instructeurs::ProceduresController, type: :controller do
let!(:procedure) { create(:procedure, instructeurs: [instructeur]) }
let!(:gi_2) { procedure.groupe_instructeurs.create(label: '2') }
let!(:gi_3) { procedure.groupe_instructeurs.create(label: '3') }
let(:statut) { nil }
subject do
get :show, params: { procedure_id: procedure.id, statut: statut }
end
context "when logged in, and belonging to gi_1, gi_2" do
before do
sign_in(instructeur.user)
instructeur.groupe_instructeurs << gi_2
end
context "without anything" do
before { get :show, params: { procedure_id: procedure.id } }
context "without any dossier" do
before { subject }
it { expect(response).to have_http_status(:ok) }
it { expect(assigns(:procedure)).to eq(procedure) }
@ -242,9 +246,7 @@ describe Instructeurs::ProceduresController, type: :controller do
context 'with a new brouillon dossier' do
let!(:brouillon_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:brouillon)) }
before do
get :show, params: { procedure_id: procedure.id }
end
before { subject }
it { expect(assigns(:a_suivre_dossiers)).to be_empty }
it { expect(assigns(:followed_dossiers)).to be_empty }
@ -256,9 +258,7 @@ describe Instructeurs::ProceduresController, type: :controller do
context 'with a new dossier without follower' do
let!(:new_unfollow_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
before do
get :show, params: { procedure_id: procedure.id }
end
before { subject }
it { expect(assigns(:a_suivre_dossiers)).to match_array([new_unfollow_dossier]) }
it { expect(assigns(:followed_dossiers)).to be_empty }
@ -270,9 +270,7 @@ describe Instructeurs::ProceduresController, type: :controller 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
before { subject }
it { expect(assigns(:a_suivre_dossiers)).to match_array([new_unfollow_dossier, new_unfollow_dossier_on_gi_2]) }
it { expect(assigns(:all_state_dossiers)).to match_array([new_unfollow_dossier, new_unfollow_dossier_on_gi_2]) }
@ -284,7 +282,7 @@ describe Instructeurs::ProceduresController, type: :controller do
before do
instructeur.followed_dossiers << new_followed_dossier
get :show, params: { procedure_id: procedure.id }
subject
end
it { expect(assigns(:a_suivre_dossiers)).to be_empty }
@ -299,7 +297,7 @@ describe Instructeurs::ProceduresController, type: :controller do
before do
instructeur.followed_dossiers << new_follow_dossier_on_gi_2 << new_follow_dossier_on_gi_3
get :show, params: { procedure_id: procedure.id }
subject
end
# followed dossiers on another groupe should not be displayed
@ -311,9 +309,7 @@ describe Instructeurs::ProceduresController, type: :controller do
context 'with a termine dossier with a follower' do
let!(:termine_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:accepte)) }
before do
get :show, params: { procedure_id: procedure.id }
end
before { subject }
it { expect(assigns(:a_suivre_dossiers)).to be_empty }
it { expect(assigns(:followed_dossiers)).to be_empty }
@ -325,9 +321,7 @@ describe Instructeurs::ProceduresController, type: :controller 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
before { subject }
it { expect(assigns(:termines_dossiers)).to match_array([termine_dossier, termine_dossier_on_gi_2]) }
it { expect(assigns(:all_state_dossiers)).to match_array([termine_dossier, termine_dossier_on_gi_2]) }
@ -337,9 +331,7 @@ describe Instructeurs::ProceduresController, type: :controller do
context 'with an archived dossier' do
let!(:archived_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction), archived: true) }
before do
get :show, params: { procedure_id: procedure.id }
end
before { subject }
it { expect(assigns(:a_suivre_dossiers)).to be_empty }
it { expect(assigns(:followed_dossiers)).to be_empty }
@ -351,9 +343,7 @@ describe Instructeurs::ProceduresController, type: :controller 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
before { subject }
it { expect(assigns(:archived_dossiers)).to match_array([archived_dossier, archived_dossier_on_gi_2]) }
end
@ -367,7 +357,7 @@ describe Instructeurs::ProceduresController, type: :controller do
before do
instructeur.followed_dossiers << new_followed_dossier
get :show, params: { procedure_id: procedure.id, statut: statut }
subject
end
context 'when statut is empty' do