diff --git a/app/controllers/administrateurs/types_de_champ_controller.rb b/app/controllers/administrateurs/types_de_champ_controller.rb index 99b8f4e01..00ebc9d82 100644 --- a/app/controllers/administrateurs/types_de_champ_controller.rb +++ b/app/controllers/administrateurs/types_de_champ_controller.rb @@ -110,6 +110,7 @@ module Administrateurs flash.alert = errors else @coordinate = draft.remove_type_de_champ(params[:stable_id]) + @coordinate.association(:revision).target = ProcedureRevision.includes_for_compare.find(coordinate.revision.id) if @coordinate.present? @destroyed = @coordinate @morphed = champ_components_starting_at(@coordinate) diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index 2c1aa20c7..aac521a71 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -17,11 +17,23 @@ class ProcedureRevision < ApplicationRecord scope :ordered, -> { order(:created_at) } scope :includes_for_compare, -> { - includes(revision_types_de_champ: { - type_de_champ: { notice_explicative_attachment: :blob, piece_justificative_template_attachment: :blob, revision: [], procedure: [] }, - revision: [], - procedure: [] - }) + includes( + revision_types_de_champ: { + type_de_champ: { notice_explicative_attachment: :blob, piece_justificative_template_attachment: :blob, revision: [], procedure: [] }, + revision: [], + procedure: [] + }, + revision_types_de_champ_public: { + type_de_champ: { notice_explicative_attachment: :blob, piece_justificative_template_attachment: :blob, revision: [], procedure: [] }, + revision: [], + procedure: [] + }, + revision_types_de_champ_private: { + type_de_champ: { notice_explicative_attachment: :blob, piece_justificative_template_attachment: :blob, revision: [], procedure: [] }, + revision: [], + procedure: [] + } + ) } validate :conditions_are_valid? validate :header_sections_are_valid? @@ -60,7 +72,6 @@ class ProcedureRevision < ApplicationRecord revision_types_de_champ.create!(h) end - # they are not aware of the addition tdc rescue => e TypeDeChamp.new.tap { |tdc| tdc.errors.add(:base, e.message) } @@ -101,12 +112,8 @@ class ProcedureRevision < ApplicationRecord children.each(&:destroy_if_orphan) tdc.destroy_if_orphan - # they are not aware of the removal coordinate.siblings.where("position >= ?", coordinate.position).update_all("position = position - 1") - types_de_champ_public.reset - types_de_champ_private.reset - coordinate end diff --git a/spec/models/concern/initiation_procedure_concern_spec.rb b/spec/models/concern/initiation_procedure_concern_spec.rb index f3303b90f..39d19bc16 100644 --- a/spec/models/concern/initiation_procedure_concern_spec.rb +++ b/spec/models/concern/initiation_procedure_concern_spec.rb @@ -4,6 +4,8 @@ describe InitiationProcedureConcern do subject { Procedure.create_initiation_procedure(administrateur) } it "returns a new procedure" do + subject + subject.reload expect(subject).to be_valid expect(subject.defaut_groupe_instructeur.instructeurs.count).to eq(1) expect(subject.draft_revision.types_de_champ_public).not_to be_empty