refactor(repetition): use less champs and public_id methods
This commit is contained in:
parent
b4ed11c788
commit
3817f334c9
4 changed files with 47 additions and 44 deletions
|
@ -8,31 +8,50 @@ describe Champ do
|
|||
let(:champ) { Champ.new(value: value) }
|
||||
let(:value) { '' }
|
||||
let(:mandatory) { true }
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(type_de_champ) }
|
||||
|
||||
context 'when mandatory and blank' do
|
||||
it { expect(champ.mandatory_blank?).to be(true) }
|
||||
end
|
||||
context 'with champ' do
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(type_de_champ) }
|
||||
|
||||
context 'when carte mandatory and blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_carte, mandatory: mandatory) }
|
||||
let(:champ) { Champs::CarteChamp.new(value: value) }
|
||||
let(:value) { nil }
|
||||
it { expect(champ.mandatory_blank?).to be(true) }
|
||||
end
|
||||
context 'when mandatory and blank' do
|
||||
it { expect(champ.mandatory_blank?).to be(true) }
|
||||
end
|
||||
|
||||
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(:champ) { Champs::MultipleDropDownListChamp.new(value: value) }
|
||||
let(:value) { '[]' }
|
||||
it { expect(champ.mandatory_blank?).to be(true) }
|
||||
end
|
||||
context 'when carte mandatory and blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_carte, mandatory: mandatory) }
|
||||
let(:champ) { Champs::CarteChamp.new(value: value) }
|
||||
let(:value) { nil }
|
||||
it { expect(champ.mandatory_blank?).to be(true) }
|
||||
end
|
||||
|
||||
context 'when repetition blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_repetition) }
|
||||
let(:champ) { Champs::RepetitionChamp.new }
|
||||
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(:champ) { Champs::MultipleDropDownListChamp.new(value: value) }
|
||||
let(:value) { '[]' }
|
||||
it { expect(champ.mandatory_blank?).to be(true) }
|
||||
end
|
||||
|
||||
it { expect(champ.blank?).to be(true) }
|
||||
context 'when repetition blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_repetition) }
|
||||
let(:champ) { Champs::RepetitionChamp.new(dossier: Dossier.new(revision: ProcedureRevision.new)) }
|
||||
|
||||
it { expect(champ.blank?).to be(true) }
|
||||
end
|
||||
|
||||
context 'when not blank' do
|
||||
let(:value) { 'yop' }
|
||||
it { expect(champ.mandatory_blank?).to be(false) }
|
||||
end
|
||||
|
||||
context 'when not mandatory' do
|
||||
let(:mandatory) { false }
|
||||
it { expect(champ.mandatory_blank?).to be(false) }
|
||||
end
|
||||
|
||||
context 'when not mandatory or blank' do
|
||||
let(:value) { 'u' }
|
||||
let(:mandatory) { false }
|
||||
it { expect(champ.mandatory_blank?).to be(false) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when repetition not blank' do
|
||||
|
@ -42,22 +61,6 @@ describe Champ do
|
|||
|
||||
it { expect(champ.blank?).to be(false) }
|
||||
end
|
||||
|
||||
context 'when not blank' do
|
||||
let(:value) { 'yop' }
|
||||
it { expect(champ.mandatory_blank?).to be(false) }
|
||||
end
|
||||
|
||||
context 'when not mandatory' do
|
||||
let(:mandatory) { false }
|
||||
it { expect(champ.mandatory_blank?).to be(false) }
|
||||
end
|
||||
|
||||
context 'when not mandatory or blank' do
|
||||
let(:value) { 'u' }
|
||||
let(:mandatory) { false }
|
||||
it { expect(champ.mandatory_blank?).to be(false) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "associations" do
|
||||
|
@ -125,7 +128,7 @@ describe Champ do
|
|||
let(:standalone_champ) { build(:champ, type_de_champ: build(:type_de_champ), dossier: build(:dossier)) }
|
||||
let(:public_sections) { dossier.champs_public.filter(&:header_section?) }
|
||||
let(:private_sections) { dossier.champs_private.filter(&:header_section?) }
|
||||
let(:sections_in_repetition) { champ_in_repetition.parent.champs.filter(&:header_section?) }
|
||||
let(:sections_in_repetition) { dossier.champs.filter(&:child?).filter(&:header_section?) }
|
||||
|
||||
it 'returns the sibling sections of a champ' do
|
||||
expect(public_sections).not_to be_empty
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue