diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index df0529cfe..e4da229c8 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -19,8 +19,8 @@ class ProcedureRevision < ApplicationRecord has_many :types_de_champ_private, through: :revision_types_de_champ_private, source: :type_de_champ has_many :owned_types_de_champ, class_name: 'TypeDeChamp', foreign_key: :revision_id, dependent: :destroy, inverse_of: :revision - has_one :draft_procedure, class_name: 'Procedure', foreign_key: :draft_revision_id, dependent: :nullify, inverse_of: :draft_revision - has_one :published_procedure, class_name: 'Procedure', foreign_key: :published_revision_id, dependent: :nullify, inverse_of: :published_revision + has_one :draft_procedure, -> { with_discarded }, class_name: 'Procedure', foreign_key: :draft_revision_id, dependent: :nullify, inverse_of: :draft_revision + has_one :published_procedure, -> { with_discarded }, class_name: 'Procedure', foreign_key: :published_revision_id, dependent: :nullify, inverse_of: :published_revision def build_champs types_de_champ.map(&:build_champ) diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 011eba63e..f4101ccc1 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -1032,9 +1032,14 @@ describe Procedure do end describe "#destroy" do - let(:procedure) { create(:procedure, :with_type_de_champ) } + let(:procedure) { create(:procedure, :closed, :with_type_de_champ) } + + before do + procedure.discard! + end it "can destroy procedure" do + expect(procedure.revisions.count).to eq(2) expect(procedure.destroy).to be_truthy end end