Skip to content

Commit

Permalink
Memoize statut
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoirenovel committed Oct 2, 2017
1 parent 3df9356 commit 801318b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
8 changes: 5 additions & 3 deletions app/controllers/new_gestionnaire/procedures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def show

@archived_dossiers = procedure.dossiers.includes(:user).archived

@statut = params[:statut].present? ? params[:statut] : 'a-suivre'

@dossiers = case @statut
@dossiers = case statut
when 'a-suivre'
@a_suivre_dossiers
when 'suivis'
Expand Down Expand Up @@ -138,6 +136,10 @@ def update_sort

private

def statut
@statut ||= params[:statut].present? ? params[:statut] : 'a-suivre'
end

def procedure
Procedure.find(params[:procedure_id])
end
Expand Down
31 changes: 27 additions & 4 deletions spec/controllers/new_gestionnaire/procedures_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,22 @@
context "when logged in" do
before do
sign_in(gestionnaire)
get :show, params: { procedure_id: procedure.id }
end

it { expect(response).to have_http_status(:ok) }
it { expect(assigns(:procedure)).to eq(procedure) }
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

context 'with a new draft dossier' do
let!(:draft_dossier) { create(:dossier, procedure: procedure, state: 'draft') }

before do
get :show, params: { procedure_id: procedure.id }
end

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 }
Expand All @@ -191,6 +198,10 @@
context 'with a new dossier without follower' do
let!(:new_unfollow_dossier) { create(:dossier, procedure: procedure, state: 'received') }

before do
get :show, params: { procedure_id: procedure.id }
end

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 }
Expand All @@ -201,7 +212,10 @@
context 'with a new dossier with a follower' do
let!(:new_followed_dossier) { create(:dossier, procedure: procedure, state: 'received') }

before { gestionnaire.followed_dossiers << new_followed_dossier }
before do
gestionnaire.followed_dossiers << new_followed_dossier
get :show, params: { procedure_id: procedure.id }
end

it { expect(assigns(:a_suivre_dossiers)).to be_empty }
it { expect(assigns(:followed_dossiers)).to match([new_followed_dossier]) }
Expand All @@ -213,6 +227,10 @@
context 'with a termine dossier with a follower' do
let!(:termine_dossier) { create(:dossier, procedure: procedure, state: 'closed') }

before do
get :show, params: { procedure_id: procedure.id }
end

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]) }
Expand All @@ -223,6 +241,10 @@
context 'with an archived dossier' do
let!(:archived_dossier) { create(:dossier, procedure: procedure, state: 'received', archived: true) }

before do
get :show, params: { procedure_id: procedure.id }
end

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 }
Expand All @@ -235,6 +257,7 @@
let!(:new_followed_dossier) { Timecop.freeze(2.day.ago){ create(:dossier, procedure: procedure, state: 'received') } }
let!(:termine_dossier) { Timecop.freeze(3.day.ago){ create(:dossier, procedure: procedure, state: 'closed') } }
let!(:archived_dossier) { Timecop.freeze(4.day.ago){ create(:dossier, procedure: procedure, state: 'received', archived: true) } }

before do
gestionnaire.followed_dossiers << new_followed_dossier
get :show, params: { procedure_id: procedure.id, statut: statut }
Expand Down

0 comments on commit 801318b

Please sign in to comment.