diff --git a/app/models/champ.rb b/app/models/champ.rb index 12dbec7eb..d984736d4 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -34,7 +34,6 @@ class Champ < ApplicationRecord delegate :libelle, :type_champ, :procedure, - :mandatory?, :description, :drop_down_list_options, :drop_down_other?, @@ -92,8 +91,12 @@ class Champ < ApplicationRecord @sections ||= dossier.sections_for(self) end + def mandatory? + type_de_champ.mandatory? && visible? + end + def mandatory_blank_and_visible? - mandatory? && blank? && visible? + mandatory? && blank? end def blank? diff --git a/app/models/champs/piece_justificative_champ.rb b/app/models/champs/piece_justificative_champ.rb index 25b2afff8..96923f3c2 100644 --- a/app/models/champs/piece_justificative_champ.rb +++ b/app/models/champs/piece_justificative_champ.rb @@ -39,7 +39,7 @@ class Champs::PieceJustificativeChamp < Champ end def mandatory_blank_and_visible? - mandatory? && !piece_justificative_file.attached? && visible? + mandatory? && !piece_justificative_file.attached? end def for_export diff --git a/app/models/champs/siret_champ.rb b/app/models/champs/siret_champ.rb index 7641978d4..d9c9d9852 100644 --- a/app/models/champs/siret_champ.rb +++ b/app/models/champs/siret_champ.rb @@ -25,6 +25,6 @@ class Champs::SiretChamp < Champ end def mandatory_blank_and_visible? - mandatory? && Siret.new(siret: value).invalid? && visible? + mandatory? && Siret.new(siret: value).invalid? end end diff --git a/app/models/champs/titre_identite_champ.rb b/app/models/champs/titre_identite_champ.rb index 22d679aee..a89486112 100644 --- a/app/models/champs/titre_identite_champ.rb +++ b/app/models/champs/titre_identite_champ.rb @@ -33,7 +33,7 @@ class Champs::TitreIdentiteChamp < Champ end def mandatory_blank_and_visible? - mandatory? && !piece_justificative_file.attached? && visible? + mandatory? && !piece_justificative_file.attached? end def for_export diff --git a/spec/system/users/brouillon_spec.rb b/spec/system/users/brouillon_spec.rb index 6d916a69b..edbc0d739 100644 --- a/spec/system/users/brouillon_spec.rb +++ b/spec/system/users/brouillon_spec.rb @@ -292,6 +292,18 @@ describe 'The user' do click_on 'Déposer le dossier' expect(page).to have_current_path(merci_dossier_path(user_dossier)) end + + scenario 'cannot submit a reveal dossier with a revealed mandatory champ ', js: true do + log_in(user, procedure) + + fill_individual + + fill_in('age', with: '18') + expect(page).to have_css('label', text: 'nom', visible: :visible) + + click_on 'Déposer le dossier' + expect(page).to have_current_path(brouillon_dossier_path(user_dossier)) + end end context 'with a visibilite in cascade' do