models: require belong_to associations on champ

- Make `champ.dossier` a requirement;
- Move the dossier_id assignation to `before_validation` (otherwise
the record is invalid, and never gets saved);
- Allow specs to only build the champ (instead of saving it to the
database), which bypasses the requirement to have a dossier.
This commit is contained in:
Pierre de La Morinerie 2020-07-20 15:18:44 +00:00
parent eb22dc9d8f
commit 6328011f60
13 changed files with 318 additions and 274 deletions

View file

@ -232,10 +232,10 @@ FactoryBot.define do
if libelle == 'drop_down_list'
libelle = 'simple_drop_down_list'
end
build(:"type_de_champ_#{type_champ}", mandatory: true, libelle: libelle, order_place: index)
build(:"type_de_champ_#{type_champ}", procedure: procedure, mandatory: true, libelle: libelle, order_place: index)
end
procedure.types_de_champ << build(:type_de_champ_drop_down_list, :long, mandatory: true, libelle: 'simple_choice_drop_down_list_long')
procedure.types_de_champ << build(:type_de_champ_multiple_drop_down_list, :long, mandatory: true, libelle: 'multiple_choice_drop_down_list_long')
procedure.types_de_champ << build(:type_de_champ_drop_down_list, :long, procedure: procedure, mandatory: true, libelle: 'simple_choice_drop_down_list_long')
procedure.types_de_champ << build(:type_de_champ_multiple_drop_down_list, :long, procedure: procedure, mandatory: true, libelle: 'multiple_choice_drop_down_list_long')
end
end
@ -245,7 +245,7 @@ FactoryBot.define do
if libelle == 'drop_down_list'
libelle = 'simple_drop_down_list'
end
build(:"type_de_champ_#{type_champ}", libelle: libelle, order_place: index)
build(:"type_de_champ_#{type_champ}", procedure: procedure, libelle: libelle, order_place: index)
end
end
end
@ -256,7 +256,7 @@ FactoryBot.define do
if libelle == 'drop_down_list'
libelle = 'simple_drop_down_list'
end
build(:"type_de_champ_#{type_champ}", private: true, libelle: libelle, order_place: index)
build(:"type_de_champ_#{type_champ}", procedure: procedure, private: true, libelle: libelle, order_place: index)
end
end
end