From 421f125c4512db7023b664c4797f4bbf5f12db10 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 3 Dec 2018 12:51:45 +0000 Subject: [PATCH 1/2] gestionnaire_spec: factorize a assign helper --- spec/models/gestionnaire_spec.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index 00fdfac58..e725099d6 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -6,10 +6,10 @@ describe Gestionnaire, type: :model do let!(:procedure_2) { create :procedure, :published, administrateur: admin } let!(:procedure_3) { create :procedure, :published, administrateur: admin } let(:gestionnaire) { create :gestionnaire, administrateurs: [admin] } - let!(:procedure_assign) { create :assign_to, gestionnaire: gestionnaire, procedure: procedure } + let!(:procedure_assign) { assign(procedure) } before do - create :assign_to, gestionnaire: gestionnaire, procedure: procedure_2 + assign(procedure_2) end describe 'follow' do @@ -390,4 +390,10 @@ describe Gestionnaire, type: :model do it { expect(follow.demande_seen_at).to eq(freeze_date) } end end + + private + + def assign(procedure_to_assign) + create :assign_to, gestionnaire: gestionnaire, procedure: procedure_to_assign + end end From e206f3d4d496a2acfc13228a750dd96a3e3fcdfb Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 3 Dec 2018 12:57:59 +0000 Subject: [PATCH 2/2] gestionnaire: display draft procedures in the list Fix #3088 --- app/models/gestionnaire.rb | 6 +----- spec/factories/procedure.rb | 9 +++++++++ spec/models/gestionnaire_spec.rb | 25 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 7f6fdcf3b..8008cb46b 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -19,11 +19,7 @@ class Gestionnaire < ApplicationRecord has_many :dossiers_from_avis, through: :avis, source: :dossier def visible_procedures - if Flipflop.publish_draft? - procedures.avec_lien - else - procedures.publiees_ou_archivees - end + procedures.merge(Procedure.avec_lien.or(Procedure.archivees)) end def can_view_dossier?(dossier_id) diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index f9a848939..7b38f42d2 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -134,6 +134,15 @@ FactoryBot.define do end end + trait :archived_automatically do + # For now the behavior is the same than :archived + # (it may be different in the future though) + after(:build) do |procedure, _evaluator| + procedure.publish!(generate(:published_path)) + procedure.archive! + end + end + trait :hidden do after(:build) do |procedure, _evaluator| procedure.publish!(generate(:published_path)) diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index e725099d6..e860c3231 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -12,6 +12,31 @@ describe Gestionnaire, type: :model do assign(procedure_2) end + describe '#visible_procedures' do + let(:procedure_not_assigned) { create :procedure, administrateur: admin } + let(:procedure_without_link) { create :procedure, administrateur: admin } + let(:procedure_with_link) { create :procedure, :with_path, administrateur: admin } + let(:procedure_archived_manually) { create :procedure, :archived, administrateur: admin } + let(:procedure_archived_automatically) { create :procedure, :archived_automatically, administrateur: admin } + + before do + assign(procedure_without_link) + assign(procedure_with_link) + assign(procedure_archived_manually) + assign(procedure_archived_automatically) + end + + subject { gestionnaire.visible_procedures } + + it do + expect(subject).not_to include(procedure_not_assigned) + expect(subject).not_to include(procedure_without_link) + expect(subject).to include(procedure_with_link) + expect(subject).to include(procedure_archived_manually) + expect(subject).to include(procedure_archived_automatically) + end + end + describe 'follow' do let(:dossier) { create :dossier } let(:already_followed_dossier) { create :dossier }