Merge pull request #4065 from betagouv/better_champs_factories
Better champs factories
This commit is contained in:
commit
399d1e4ac2
5 changed files with 28 additions and 23 deletions
|
@ -41,12 +41,12 @@ FactoryBot.define do
|
|||
|
||||
factory :champ_date, class: 'Champs::DateChamp' do
|
||||
type_de_champ { create(:type_de_champ_date) }
|
||||
value { 1.day.ago.iso8601 }
|
||||
value { '2019-07-10' }
|
||||
end
|
||||
|
||||
factory :champ_datetime, class: 'Champs::DatetimeChamp' do
|
||||
type_de_champ { create(:type_de_champ_datetime) }
|
||||
value { 1.day.ago.iso8601 }
|
||||
value { '15/09/1962 15:35' }
|
||||
end
|
||||
|
||||
factory :champ_number, class: 'Champs::NumberChamp' do
|
||||
|
@ -96,17 +96,17 @@ FactoryBot.define do
|
|||
|
||||
factory :champ_drop_down_list, class: 'Champs::DropDownListChamp' do
|
||||
type_de_champ { create(:type_de_champ_drop_down_list) }
|
||||
value { '' }
|
||||
value { 'choix 1' }
|
||||
end
|
||||
|
||||
factory :champ_multiple_drop_down_list, class: 'Champs::MultipleDropDownListChamp' do
|
||||
type_de_champ { create(:type_de_champ_multiple_drop_down_list) }
|
||||
value { '' }
|
||||
value { '["choix 1", "choix 2"]' }
|
||||
end
|
||||
|
||||
factory :champ_linked_drop_down_list, class: 'Champs::LinkedDropDownListChamp' do
|
||||
type_de_champ { create(:type_de_champ_linked_drop_down_list) }
|
||||
value { '{}' }
|
||||
value { '["categorie 1", "choix 1"]' }
|
||||
end
|
||||
|
||||
factory :champ_pays, class: 'Champs::PaysChamp' do
|
||||
|
@ -116,12 +116,12 @@ FactoryBot.define do
|
|||
|
||||
factory :champ_regions, class: 'Champs::RegionChamp' do
|
||||
type_de_champ { create(:type_de_champ_regions) }
|
||||
value { '' }
|
||||
value { 'Guadeloupe' }
|
||||
end
|
||||
|
||||
factory :champ_departements, class: 'Champs::DepartementChamp' do
|
||||
type_de_champ { create(:type_de_champ_departements) }
|
||||
value { '' }
|
||||
value { '971 - Guadeloupe' }
|
||||
end
|
||||
|
||||
factory :champ_engagement, class: 'Champs::EngagementChamp' do
|
||||
|
@ -136,7 +136,7 @@ FactoryBot.define do
|
|||
|
||||
factory :champ_explication, class: 'Champs::ExplicationChamp' do
|
||||
type_de_champ { create(:type_de_champ_explication) }
|
||||
value { 'une explication' }
|
||||
value { '' }
|
||||
end
|
||||
|
||||
factory :champ_dossier_link, class: 'Champs::DossierLinkChamp' do
|
||||
|
@ -164,5 +164,15 @@ FactoryBot.define do
|
|||
|
||||
factory :champ_repetition, class: 'Champs::RepetitionChamp' do
|
||||
type_de_champ { create(:type_de_champ_repetition) }
|
||||
|
||||
after(:build) do |champ_repetition, _evaluator|
|
||||
type_de_champ_text = create(:type_de_champ_text, order_place: 0, parent: champ_repetition.type_de_champ, libelle: 'Nom')
|
||||
type_de_champ_number = create(:type_de_champ_number, order_place: 1, parent: champ_repetition.type_de_champ, libelle: 'Age')
|
||||
|
||||
create(:champ_text, row: 0, type_de_champ: type_de_champ_text, parent: champ_repetition)
|
||||
create(:champ_number, row: 0, type_de_champ: type_de_champ_number, parent: champ_repetition)
|
||||
create(:champ_text, row: 1, type_de_champ: type_de_champ_text, parent: champ_repetition)
|
||||
create(:champ_number, row: 1, type_de_champ: type_de_champ_number, parent: champ_repetition)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -395,7 +395,7 @@ describe Champ do
|
|||
|
||||
describe "repetition" do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:champ) { create(:champ_repetition, dossier: dossier) }
|
||||
let(:champ) { Champs::RepetitionChamp.create(dossier: dossier) }
|
||||
let(:champ_text) { create(:champ_text, row: 0) }
|
||||
let(:champ_integer_number) { create(:champ_integer_number, row: 0) }
|
||||
let(:champ_text_attrs) { attributes_for(:champ_text, row: 1) }
|
||||
|
|
|
@ -886,7 +886,7 @@ describe Dossier do
|
|||
|
||||
describe "#check_mandatory_champs" do
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ) }
|
||||
let(:dossier) { create(:dossier, :with_all_champs, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
|
||||
it 'no mandatory champs' do
|
||||
expect(dossier.check_mandatory_champs).to be_empty
|
||||
|
@ -945,7 +945,11 @@ describe Dossier do
|
|||
end
|
||||
|
||||
context "when no champs" do
|
||||
let(:champ_with_error) { dossier.champs.first }
|
||||
let(:champ_with_error) do
|
||||
repetition_champ = dossier.champs.first
|
||||
text_champ = repetition_champ.rows.first.first
|
||||
text_champ
|
||||
end
|
||||
|
||||
it 'should have errors' do
|
||||
errors = dossier.check_mandatory_champs
|
||||
|
|
|
@ -41,7 +41,7 @@ describe DossierSerializer do
|
|||
|
||||
expect(subject[3][:value]).to eq(42)
|
||||
expect(subject[4][:value]).to eq(42.1)
|
||||
expect(subject[5][:value]).to eq({ primary: nil, secondary: nil })
|
||||
expect(subject[5][:value]).to eq({ primary: 'categorie 1', secondary: 'choix 1' })
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -157,15 +157,6 @@ describe ProcedureExportV2Service do
|
|||
context 'with repetitions' do
|
||||
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :for_individual, procedure: procedure) }
|
||||
let(:champ_repetition) { dossier.champs.find { |champ| champ.type_champ == 'repetition' } }
|
||||
let(:type_de_champ_text) { create(:type_de_champ_text, order_place: 0, parent: champ_repetition.type_de_champ) }
|
||||
let(:type_de_champ_number) { create(:type_de_champ_number, order_place: 1, parent: champ_repetition.type_de_champ) }
|
||||
|
||||
before do
|
||||
create(:champ_text, row: 0, type_de_champ: type_de_champ_text, parent: champ_repetition)
|
||||
create(:champ_number, row: 0, type_de_champ: type_de_champ_number, parent: champ_repetition)
|
||||
create(:champ_text, row: 1, type_de_champ: type_de_champ_text, parent: champ_repetition)
|
||||
create(:champ_number, row: 1, type_de_champ: type_de_champ_number, parent: champ_repetition)
|
||||
end
|
||||
|
||||
it 'should have sheets' do
|
||||
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', champ_repetition.libelle])
|
||||
|
@ -175,8 +166,8 @@ describe ProcedureExportV2Service do
|
|||
expect(repetition_sheet.headers).to eq([
|
||||
"Dossier ID",
|
||||
"Ligne",
|
||||
type_de_champ_text.libelle,
|
||||
type_de_champ_number.libelle
|
||||
"Nom",
|
||||
"Age"
|
||||
])
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue