feat(dossier): use persisted dossier for preview
This commit is contained in:
parent
27f9a820cc
commit
68ca9efba0
4 changed files with 21 additions and 4 deletions
|
@ -44,7 +44,7 @@ module Administrateurs
|
|||
end
|
||||
|
||||
def apercu
|
||||
@dossier = procedure_without_control.draft_revision.new_dossier
|
||||
@dossier = procedure_without_control.draft_revision.dossier_for_preview(current_user)
|
||||
@tab = apercu_tab
|
||||
end
|
||||
|
||||
|
|
|
@ -544,7 +544,7 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def can_transition_to_en_construction?
|
||||
brouillon? && procedure.dossier_can_transition_to_en_construction?
|
||||
brouillon? && procedure.dossier_can_transition_to_en_construction? && !for_procedure_preview?
|
||||
end
|
||||
|
||||
def can_repasser_en_instruction?
|
||||
|
@ -1246,7 +1246,7 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def send_draft_notification_email
|
||||
if brouillon? && !procedure.declarative?
|
||||
if brouillon? && !procedure.declarative? && !for_procedure_preview?
|
||||
DossierMailer.notify_new_draft(self).deliver_later
|
||||
end
|
||||
end
|
||||
|
|
|
@ -132,6 +132,19 @@ class ProcedureRevision < ApplicationRecord
|
|||
)
|
||||
end
|
||||
|
||||
def dossier_for_preview(user)
|
||||
dossier = Dossier
|
||||
.create_with(groupe_instructeur: procedure.defaut_groupe_instructeur_for_new_dossier)
|
||||
.find_or_initialize_by(revision: self, user: user, for_procedure_preview: true, state: Dossier.states.fetch(:brouillon))
|
||||
|
||||
if dossier.new_record?
|
||||
dossier.build_default_individual
|
||||
dossier.save!
|
||||
end
|
||||
|
||||
dossier
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def compare_attestation_template(from_at, to_at)
|
||||
|
|
|
@ -23,7 +23,11 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
get :apercu, params: { id: procedure.id }
|
||||
end
|
||||
|
||||
it { expect(response).to have_http_status(:ok) }
|
||||
it do
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(procedure.dossiers.visible_by_user).to be_empty
|
||||
expect(procedure.dossiers.for_procedure_preview).not_to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
let(:procedure_params) {
|
||||
|
|
Loading…
Reference in a new issue