Merge pull request #5479 from betagouv/improve-factories
Amélioration mineures des factories
This commit is contained in:
commit
4f0d9afbd6
2 changed files with 14 additions and 17 deletions
|
@ -48,7 +48,7 @@ FactoryBot.define do
|
||||||
factory :simple_procedure do
|
factory :simple_procedure do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
procedure.for_individual = true
|
procedure.for_individual = true
|
||||||
procedure.types_de_champ << create(:type_de_champ, libelle: 'Texte obligatoire', mandatory: true)
|
procedure.types_de_champ << build(:type_de_champ, libelle: 'Texte obligatoire', mandatory: true)
|
||||||
procedure.path = generate(:published_path)
|
procedure.path = generate(:published_path)
|
||||||
procedure.publish!
|
procedure.publish!
|
||||||
end
|
end
|
||||||
|
@ -97,7 +97,7 @@ FactoryBot.define do
|
||||||
|
|
||||||
after(:build) do |procedure, evaluator|
|
after(:build) do |procedure, evaluator|
|
||||||
evaluator.types_de_champ_count.times do
|
evaluator.types_de_champ_count.times do
|
||||||
type_de_champ = create(:type_de_champ)
|
type_de_champ = build(:type_de_champ)
|
||||||
|
|
||||||
procedure.types_de_champ << type_de_champ
|
procedure.types_de_champ << type_de_champ
|
||||||
end
|
end
|
||||||
|
@ -111,7 +111,7 @@ FactoryBot.define do
|
||||||
|
|
||||||
after(:build) do |procedure, evaluator|
|
after(:build) do |procedure, evaluator|
|
||||||
evaluator.types_de_champ_private_count.times do
|
evaluator.types_de_champ_private_count.times do
|
||||||
type_de_champ = create(:type_de_champ, :private)
|
type_de_champ = build(:type_de_champ, :private)
|
||||||
|
|
||||||
procedure.types_de_champ_private << type_de_champ
|
procedure.types_de_champ_private << type_de_champ
|
||||||
end
|
end
|
||||||
|
@ -120,7 +120,7 @@ FactoryBot.define do
|
||||||
|
|
||||||
trait :with_type_de_champ_mandatory do
|
trait :with_type_de_champ_mandatory do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
type_de_champ = create(:type_de_champ, mandatory: true)
|
type_de_champ = build(:type_de_champ, mandatory: true)
|
||||||
|
|
||||||
procedure.types_de_champ << type_de_champ
|
procedure.types_de_champ << type_de_champ
|
||||||
end
|
end
|
||||||
|
@ -128,7 +128,7 @@ FactoryBot.define do
|
||||||
|
|
||||||
trait :with_datetime do
|
trait :with_datetime do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
type_de_champ = create(:type_de_champ_datetime, mandatory: true)
|
type_de_champ = build(:type_de_champ_datetime, mandatory: true)
|
||||||
|
|
||||||
procedure.types_de_champ << type_de_champ
|
procedure.types_de_champ << type_de_champ
|
||||||
end
|
end
|
||||||
|
@ -136,7 +136,7 @@ FactoryBot.define do
|
||||||
|
|
||||||
trait :with_dossier_link do
|
trait :with_dossier_link do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
type_de_champ = create(:type_de_champ_dossier_link)
|
type_de_champ = build(:type_de_champ_dossier_link)
|
||||||
|
|
||||||
procedure.types_de_champ << type_de_champ
|
procedure.types_de_champ << type_de_champ
|
||||||
end
|
end
|
||||||
|
@ -144,7 +144,7 @@ FactoryBot.define do
|
||||||
|
|
||||||
trait :with_yes_no do
|
trait :with_yes_no do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
type_de_champ = create(:type_de_champ_yes_no)
|
type_de_champ = build(:type_de_champ_yes_no)
|
||||||
|
|
||||||
procedure.types_de_champ << type_de_champ
|
procedure.types_de_champ << type_de_champ
|
||||||
end
|
end
|
||||||
|
@ -152,23 +152,24 @@ FactoryBot.define do
|
||||||
|
|
||||||
trait :with_piece_justificative do
|
trait :with_piece_justificative do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
type_de_champ = create(:type_de_champ_piece_justificative)
|
type_de_champ = build(:type_de_champ_piece_justificative)
|
||||||
|
|
||||||
procedure.types_de_champ << type_de_champ
|
procedure.types_de_champ << type_de_champ
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :with_repetition do
|
trait :with_repetition do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
type_de_champ = create(:type_de_champ_repetition)
|
type_de_champ = build(:type_de_champ_repetition)
|
||||||
procedure.types_de_champ << type_de_champ
|
procedure.types_de_champ << type_de_champ
|
||||||
|
|
||||||
type_de_champ.types_de_champ << create(:type_de_champ, libelle: 'sub type de champ')
|
type_de_champ.types_de_champ << build(:type_de_champ, libelle: 'sub type de champ')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :with_number do
|
trait :with_number do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
type_de_champ = create(:type_de_champ_number)
|
type_de_champ = build(:type_de_champ_number)
|
||||||
|
|
||||||
procedure.types_de_champ << type_de_champ
|
procedure.types_de_champ << type_de_champ
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :type_de_champ do
|
factory :type_de_champ do
|
||||||
private { false }
|
|
||||||
|
|
||||||
# Previous line is kept blank so that rubocop does not complain
|
|
||||||
sequence(:libelle) { |n| "Libelle du champ #{n}" }
|
sequence(:libelle) { |n| "Libelle du champ #{n}" }
|
||||||
sequence(:description) { |n| "description du champ #{n}" }
|
sequence(:description) { |n| "description du champ #{n}" }
|
||||||
type_champ { TypeDeChamp.type_champs.fetch(:text) }
|
type_champ { TypeDeChamp.type_champs.fetch(:text) }
|
||||||
order_place { 1 }
|
order_place { 1 }
|
||||||
mandatory { false }
|
mandatory { false }
|
||||||
|
add_attribute(:private) { false }
|
||||||
|
|
||||||
factory :type_de_champ_text do
|
factory :type_de_champ_text do
|
||||||
type_champ { TypeDeChamp.type_champs.fetch(:text) }
|
type_champ { TypeDeChamp.type_champs.fetch(:text) }
|
||||||
|
@ -117,9 +115,7 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :private do
|
trait :private do
|
||||||
private { true }
|
add_attribute(:private) { true }
|
||||||
|
|
||||||
# Previous line is kept blank so that rubocop does not complain
|
|
||||||
sequence(:libelle) { |n| "Libelle champ privé #{n}" }
|
sequence(:libelle) { |n| "Libelle champ privé #{n}" }
|
||||||
sequence(:description) { |n| "description du champ privé #{n}" }
|
sequence(:description) { |n| "description du champ privé #{n}" }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue