fix(procedure): valid juridique on create and publication

This commit is contained in:
simon lehericey 2022-11-22 15:17:37 +01:00
parent 9043bed3a0
commit 528b2c2b88
2 changed files with 9 additions and 7 deletions

View file

@ -272,7 +272,9 @@ class Procedure < ApplicationRecord
'types_de_champ/no_empty_block': true, 'types_de_champ/no_empty_block': true,
'types_de_champ/no_empty_drop_down': true, 'types_de_champ/no_empty_drop_down': true,
on: :publication 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 :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, validates :duree_conservation_dossiers_dans_ds, allow_nil: false,
numericality: { numericality: {

View file

@ -178,20 +178,20 @@ describe Procedure do
end end
context 'juridique' do context 'juridique' do
it { is_expected.not_to allow_value(nil).for(:cadre_juridique) } it { is_expected.not_to allow_value(nil).on(:publication).for(:cadre_juridique) }
it { is_expected.to allow_value('text').for(:cadre_juridique) } it { is_expected.to allow_value('text').on(:publication).for(:cadre_juridique) }
context 'with deliberation' do context 'with deliberation' do
let(:procedure) { build(:procedure, cadre_juridique: nil) } 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 context 'when the deliberation is uploaded ' do
before do before do
procedure.deliberation = fixture_file_upload('spec/fixtures/files/file.pdf', 'application/pdf') procedure.deliberation = fixture_file_upload('spec/fixtures/files/file.pdf', 'application/pdf')
end end
it { expect(procedure.valid?).to eq(true) } it { expect(procedure.valid?(:publication)).to eq(true) }
end end
context 'when the deliberation is uploaded with an unauthorized format' do 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') procedure.deliberation = fixture_file_upload('spec/fixtures/files/french-flag.gif', 'image/gif')
end end
it { expect(procedure.valid?).to eq(false) } it { expect(procedure.valid?(:publication)).to eq(false) }
end end
end end
context 'when juridique_required is false' do context 'when juridique_required is false' do
let(:procedure) { build(:procedure, juridique_required: false, cadre_juridique: nil) } 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
end end