gestionnaire: display draft procedures in the list

Fix #3088
This commit is contained in:
Pierre de La Morinerie 2018-12-03 12:57:59 +00:00
parent 421f125c45
commit e206f3d4d4
3 changed files with 35 additions and 5 deletions

View file

@ -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)

View file

@ -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))

View file

@ -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 }