diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 7f95fbbab..9a189f517 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -223,6 +223,11 @@ class Procedure < ApplicationRecord accepte: 'accepte' } + enum closing_reason: { + internal_procedure: 'internal_procedure', + other: 'other' + } + scope :for_api_v2, -> { includes(:draft_revision, :published_revision, administrateurs: :user) } @@ -260,6 +265,9 @@ class Procedure < ApplicationRecord validate :check_juridique, on: [:create, :publication] + # TO DO add validation after data backfill + # validates :replaced_by_id, presence: true, if: -> { closing_reason == self.closing_reasons.fetch(:internal_procedure) } + validates :path, presence: true, format: { with: /\A[a-z0-9_\-]{3,200}\z/ }, uniqueness: { scope: [:path, :closed_at, :hidden_at, :unpublished_at], case_sensitive: false } validates :duree_conservation_dossiers_dans_ds, allow_nil: false, numericality: { diff --git a/db/migrate/20240201141520_add_closing_reason_and_closing_details.rb b/db/migrate/20240201141520_add_closing_reason_and_closing_details.rb new file mode 100644 index 000000000..48bf33f3b --- /dev/null +++ b/db/migrate/20240201141520_add_closing_reason_and_closing_details.rb @@ -0,0 +1,6 @@ +class AddClosingReasonAndClosingDetails < ActiveRecord::Migration[7.0] + def change + add_column :procedures, :closing_reason, :string + add_column :procedures, :closing_details, :string + end +end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index c1aedbd90..62f553e1e 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -178,6 +178,20 @@ describe Procedure do it { is_expected.to allow_value('Demande de subvention').for(:libelle) } end + context 'closing procedure' do + context 'without replacing procedure in DS' do + let(:procedure) { create(:procedure) } + + context 'valid' do + before do + procedure.update!(closing_details: "Bonjour,\nLa démarche est désormais hébergée sur une autre plateforme\nCordialement", closing_reason: Procedure.closing_reasons.fetch(:other)) + end + + it { expect(procedure).to be_valid } + end + end + end + context 'description' do it { is_expected.not_to allow_value(nil).for(:description) } it { is_expected.not_to allow_value('').for(:description) }