validators: rename revisions namespace to types_de_champ

This commit is contained in:
Pierre de La Morinerie 2022-01-26 18:06:39 +01:00
parent d680602c84
commit ca58e60dc0
4 changed files with 8 additions and 8 deletions

View file

@ -246,12 +246,12 @@ class Procedure < ApplicationRecord
validates :administrateurs, presence: true
validates :lien_site_web, presence: true, if: :publiee?
validates :draft_types_de_champ,
'revisions/no_empty_repetition': true,
'revisions/no_empty_drop_down': true,
'types_de_champ/no_empty_repetition': true,
'types_de_champ/no_empty_drop_down': true,
if: :validate_for_publication?
validates :draft_types_de_champ_private,
'revisions/no_empty_repetition': true,
'revisions/no_empty_drop_down': true,
'types_de_champ/no_empty_repetition': true,
'types_de_champ/no_empty_drop_down': true,
if: :validate_for_publication?
validate :check_juridique
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 }

View file

@ -1,4 +1,4 @@
class Revisions::NoEmptyDropDownValidator < ActiveModel::EachValidator
class TypesDeChamp::NoEmptyDropDownValidator < ActiveModel::EachValidator
def validate_each(procedure, attribute, types_de_champ)
types_de_champ.filter(&:drop_down_list?).each do |drop_down|
validate_drop_down_not_empty(procedure, attribute, drop_down)

View file

@ -1,4 +1,4 @@
class Revisions::NoEmptyRepetitionValidator < ActiveModel::EachValidator
class TypesDeChamp::NoEmptyRepetitionValidator < ActiveModel::EachValidator
def validate_each(procedure, attribute, types_de_champ)
types_de_champ.filter(&:repetition?).each do |repetition|
validate_repetition_not_empty(procedure, attribute, repetition)

View file

@ -299,7 +299,7 @@ describe Procedure do
it_behaves_like 'duree de conservation'
end
describe 'draft_revision' do
describe 'draft_types_de_champ validations' do
let(:repetition) { build(:type_de_champ_repetition, libelle: 'Enfants') }
let(:text_field) { build(:type_de_champ_text) }
let(:invalid_repetition_error_message) { 'Le champ « Enfants » doit comporter au moins un champ répétable' }
@ -310,7 +310,7 @@ describe Procedure do
let(:procedure) { create(:procedure, types_de_champ: [repetition, drop_down]) }
context 'on a draft procedure' do
it 'doesnt validate the draft revision' do
it 'doesnt validate the types de champs' do
procedure.validate
expect(procedure.errors[:draft_types_de_champ]).not_to be_present
end