diff --git a/app/models/procedure.rb b/app/models/procedure.rb index bbd74e54d..36ea911dc 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -272,7 +272,9 @@ class Procedure < ApplicationRecord 'types_de_champ/no_empty_block': true, 'types_de_champ/no_empty_drop_down': true, on: :publication - validate :check_juridique + + validate :check_juridique, on: [:create, :publication] + 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/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 8334057eb..4a5508d2a 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -178,20 +178,20 @@ describe Procedure do end context 'juridique' do - it { is_expected.not_to allow_value(nil).for(:cadre_juridique) } - it { is_expected.to allow_value('text').for(:cadre_juridique) } + it { is_expected.not_to allow_value(nil).on(:publication).for(:cadre_juridique) } + it { is_expected.to allow_value('text').on(:publication).for(:cadre_juridique) } context 'with deliberation' do let(:procedure) { build(:procedure, cadre_juridique: nil) } - it { expect(procedure.valid?).to eq(false) } + it { expect(procedure.valid?(:publication)).to eq(false) } context 'when the deliberation is uploaded ' do before do procedure.deliberation = fixture_file_upload('spec/fixtures/files/file.pdf', 'application/pdf') end - it { expect(procedure.valid?).to eq(true) } + it { expect(procedure.valid?(:publication)).to eq(true) } end context 'when the deliberation is uploaded with an unauthorized format' do @@ -199,14 +199,14 @@ describe Procedure do procedure.deliberation = fixture_file_upload('spec/fixtures/files/french-flag.gif', 'image/gif') end - it { expect(procedure.valid?).to eq(false) } + it { expect(procedure.valid?(:publication)).to eq(false) } end end context 'when juridique_required is false' do let(:procedure) { build(:procedure, juridique_required: false, cadre_juridique: nil) } - it { expect(procedure.valid?).to eq(true) } + it { expect(procedure.valid?(:publication)).to eq(true) } end end