refactor(champ): mandatory_blank_and_visible? -> mandatory_blank?
As the method does not check visibility
This commit is contained in:
parent
6832b12bd4
commit
9bba2093be
8 changed files with 18 additions and 18 deletions
|
@ -101,7 +101,7 @@ class Champ < ApplicationRecord
|
||||||
type_de_champ.mandatory? && visible?
|
type_de_champ.mandatory? && visible?
|
||||||
end
|
end
|
||||||
|
|
||||||
def mandatory_blank_and_visible?
|
def mandatory_blank?
|
||||||
mandatory? && blank?
|
mandatory? && blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Champs::CheckboxChamp < Champs::YesNoChamp
|
||||||
true? ? 'on' : 'off'
|
true? ? 'on' : 'off'
|
||||||
end
|
end
|
||||||
|
|
||||||
def mandatory_blank_and_visible?
|
def mandatory_blank?
|
||||||
mandatory? && (blank? || !true?)
|
mandatory? && (blank? || !true?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,7 @@ class Champs::PieceJustificativeChamp < Champ
|
||||||
# We don’t know how to search inside documents yet
|
# We don’t know how to search inside documents yet
|
||||||
end
|
end
|
||||||
|
|
||||||
def mandatory_blank_and_visible?
|
def mandatory_blank?
|
||||||
mandatory? && !piece_justificative_file.attached?
|
mandatory? && !piece_justificative_file.attached?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Champs::SiretChamp < Champ
|
||||||
etablissement.present? ? etablissement.search_terms : [value]
|
etablissement.present? ? etablissement.search_terms : [value]
|
||||||
end
|
end
|
||||||
|
|
||||||
def mandatory_blank_and_visible?
|
def mandatory_blank?
|
||||||
mandatory? && Siret.new(siret: value).invalid?
|
mandatory? && Siret.new(siret: value).invalid?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Champs::TitreIdentiteChamp < Champ
|
||||||
# We don’t know how to search inside documents yet
|
# We don’t know how to search inside documents yet
|
||||||
end
|
end
|
||||||
|
|
||||||
def mandatory_blank_and_visible?
|
def mandatory_blank?
|
||||||
mandatory? && !piece_justificative_file.attached?
|
mandatory? && !piece_justificative_file.attached?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -983,7 +983,7 @@ class Dossier < ApplicationRecord
|
||||||
|
|
||||||
def check_mandatory_champs
|
def check_mandatory_champs
|
||||||
(champs + champs.filter(&:block?).filter(&:visible?).flat_map(&:champs))
|
(champs + champs.filter(&:block?).filter(&:visible?).flat_map(&:champs))
|
||||||
.filter(&:mandatory_blank_and_visible?)
|
.filter(&:mandatory_blank?)
|
||||||
.map do |champ|
|
.map do |champ|
|
||||||
"Le champ #{champ.libelle.truncate(200)} doit être rempli."
|
"Le champ #{champ.libelle.truncate(200)} doit être rempli."
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
shared_examples 'champ_spec' do
|
shared_examples 'champ_spec' do
|
||||||
describe 'mandatory_blank_and_visible?' do
|
describe 'mandatory_blank?' do
|
||||||
let(:type_de_champ) { build(:type_de_champ, mandatory: mandatory) }
|
let(:type_de_champ) { build(:type_de_champ, mandatory: mandatory) }
|
||||||
let(:champ) { build(:champ, type_de_champ: type_de_champ, value: value) }
|
let(:champ) { build(:champ, type_de_champ: type_de_champ, value: value) }
|
||||||
let(:value) { '' }
|
let(:value) { '' }
|
||||||
let(:mandatory) { true }
|
let(:mandatory) { true }
|
||||||
|
|
||||||
context 'when mandatory and blank' do
|
context 'when mandatory and blank' do
|
||||||
it { expect(champ.mandatory_blank_and_visible?).to be(true) }
|
it { expect(champ.mandatory_blank?).to be(true) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when carte mandatory and blank' do
|
context 'when carte mandatory and blank' do
|
||||||
let(:type_de_champ) { build(:type_de_champ_carte, mandatory: mandatory) }
|
let(:type_de_champ) { build(:type_de_champ_carte, mandatory: mandatory) }
|
||||||
let(:champ) { build(:champ_carte, type_de_champ: type_de_champ, value: value) }
|
let(:champ) { build(:champ_carte, type_de_champ: type_de_champ, value: value) }
|
||||||
let(:value) { nil }
|
let(:value) { nil }
|
||||||
it { expect(champ.mandatory_blank_and_visible?).to be(true) }
|
it { expect(champ.mandatory_blank?).to be(true) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when multiple_drop_down_list mandatory and blank' do
|
context 'when multiple_drop_down_list mandatory and blank' do
|
||||||
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, mandatory: mandatory) }
|
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, mandatory: mandatory) }
|
||||||
let(:champ) { build(:champ_multiple_drop_down_list, type_de_champ: type_de_champ, value: value) }
|
let(:champ) { build(:champ_multiple_drop_down_list, type_de_champ: type_de_champ, value: value) }
|
||||||
let(:value) { '[]' }
|
let(:value) { '[]' }
|
||||||
it { expect(champ.mandatory_blank_and_visible?).to be(true) }
|
it { expect(champ.mandatory_blank?).to be(true) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when repetition blank' do
|
context 'when repetition blank' do
|
||||||
|
@ -39,18 +39,18 @@ shared_examples 'champ_spec' do
|
||||||
|
|
||||||
context 'when not blank' do
|
context 'when not blank' do
|
||||||
let(:value) { 'yop' }
|
let(:value) { 'yop' }
|
||||||
it { expect(champ.mandatory_blank_and_visible?).to be(false) }
|
it { expect(champ.mandatory_blank?).to be(false) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when not mandatory' do
|
context 'when not mandatory' do
|
||||||
let(:mandatory) { false }
|
let(:mandatory) { false }
|
||||||
it { expect(champ.mandatory_blank_and_visible?).to be(false) }
|
it { expect(champ.mandatory_blank?).to be(false) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when not mandatory or blank' do
|
context 'when not mandatory or blank' do
|
||||||
let(:value) { 'u' }
|
let(:value) { 'u' }
|
||||||
let(:mandatory) { false }
|
let(:mandatory) { false }
|
||||||
it { expect(champ.mandatory_blank_and_visible?).to be(false) }
|
it { expect(champ.mandatory_blank?).to be(false) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ describe Champs::LinkedDropDownListChamp do
|
||||||
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, drop_down_list_value: value) }
|
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, drop_down_list_value: value) }
|
||||||
|
|
||||||
it 'blank is fine' do
|
it 'blank is fine' do
|
||||||
is_expected.not_to be_mandatory_blank_and_visible
|
is_expected.not_to be_mandatory_blank
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -86,27 +86,27 @@ describe Champs::LinkedDropDownListChamp do
|
||||||
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, mandatory: true, drop_down_list_value: value) }
|
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, mandatory: true, drop_down_list_value: value) }
|
||||||
|
|
||||||
context 'when there is no value' do
|
context 'when there is no value' do
|
||||||
it { is_expected.to be_mandatory_blank_and_visible }
|
it { is_expected.to be_mandatory_blank }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when there is a primary value' do
|
context 'when there is a primary value' do
|
||||||
before { subject.primary_value = 'Primary' }
|
before { subject.primary_value = 'Primary' }
|
||||||
|
|
||||||
context 'when there is no secondary value' do
|
context 'when there is no secondary value' do
|
||||||
it { is_expected.to be_mandatory_blank_and_visible }
|
it { is_expected.to be_mandatory_blank }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when there is a secondary value' do
|
context 'when there is a secondary value' do
|
||||||
before { subject.secondary_value = 'Secondary' }
|
before { subject.secondary_value = 'Secondary' }
|
||||||
|
|
||||||
it { is_expected.not_to be_mandatory_blank_and_visible }
|
it { is_expected.not_to be_mandatory_blank }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when there is nothing to select for the secondary value' do
|
context 'when there is nothing to select for the secondary value' do
|
||||||
let(:value) { "--A--\nAbbott\nAbelard\n--B--\n--C--\nCynthia" }
|
let(:value) { "--A--\nAbbott\nAbelard\n--B--\n--C--\nCynthia" }
|
||||||
before { subject.primary_value = 'B' }
|
before { subject.primary_value = 'B' }
|
||||||
|
|
||||||
it { is_expected.not_to be_mandatory_blank_and_visible }
|
it { is_expected.not_to be_mandatory_blank }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue