diff --git a/app/models/concerns/dossier_prefillable_concern.rb b/app/models/concerns/dossier_prefillable_concern.rb index 981936615..3ecbe7a04 100644 --- a/app/models/concerns/dossier_prefillable_concern.rb +++ b/app/models/concerns/dossier_prefillable_concern.rb @@ -13,14 +13,3 @@ module DossierPrefillableConcern save(validate: false) end end - - -# Pour être sûr de bien être alignés, on veut bien les format suivants ? - -# En POST, je prends un hash classique et je lui fais to_json -# Pour ton exemple ça donne: "{\"champ_id1\":\"text\",\"champ_id2\":[\"option1\",\"option2\"],\"champ_id3\":[{\"champ_id4\":\"text\",\"champ_id5\":true,\"champ_id6\":42,\"champ_id7\":[\"option1\",\"option2\"]},{\"champ_id4\":\"text2\",\"champ_id6\":32}]}" - -# En GET, je prends un hash et je lui applique to_query -# Pour ton exemple, et en escapant les caractères spéciaux: "champ_id1=text&champ_id2[]=option1&champ_id2[]=option2&champ_id3[][champ_id4]=text&champ_id3[][champ_id5]=true&champ_id3[][champ_id6]=42&champ_id3[][champ_id7][]=option1&champ_id3[][champ_id7][]=option2&champ_id3[][champ_id4]=text2&champ_id3[][champ_id6]=32" - -#Tu confirmes ? Je préfère checker car c'est un tout petit peu différent de ton exemple diff --git a/spec/models/prefill_params_spec.rb b/spec/models/prefill_params_spec.rb index 07ba823a6..55c7289e9 100644 --- a/spec/models/prefill_params_spec.rb +++ b/spec/models/prefill_params_spec.rb @@ -147,7 +147,7 @@ RSpec.describe PrefillParams do let(:type_de_champ_child_value) { "value" } let(:type_de_champ_child_value2) { "value2" } - let(:params) { { "champ_#{type_de_champ.to_typed_id_for_query}" => [{"champ_#{type_de_champ_child.to_typed_id_for_query}"=> type_de_champ_child_value}, {"champ_#{type_de_champ_child.to_typed_id_for_query}"=> type_de_champ_child_value2 }] } } + let(:params) { { "champ_#{type_de_champ.to_typed_id_for_query}" => [{ "champ_#{type_de_champ_child.to_typed_id_for_query}" => type_de_champ_child_value }, { "champ_#{type_de_champ_child.to_typed_id_for_query}" => type_de_champ_child_value2 }] } } it "builds an array of hash(id, value) matching the given params" do expect(prefill_params_array).to match([{ id: type_de_champ_child.champ.first.id, value: type_de_champ_child_value }, { id: type_de_champ_child.champ.second.id, value: type_de_champ_child_value2 }]) @@ -183,7 +183,7 @@ RSpec.describe PrefillParams do let(:type_de_champ_child_value) { "value" } let(:type_de_champ_child_value2) { "value2" } - let(:params) { { "champ_#{type_de_champ.to_typed_id_for_query}" => [{"champ_#{type_de_champ_child.to_typed_id_for_query}" => type_de_champ_child_value}, {"champ_#{type_de_champ_child.to_typed_id_for_query}" => type_de_champ_child_value2}] } } + let(:params) { { "champ_#{type_de_champ.to_typed_id_for_query}" => [{ "champ_#{type_de_champ_child.to_typed_id_for_query}" => type_de_champ_child_value }, { "champ_#{type_de_champ_child.to_typed_id_for_query}" => type_de_champ_child_value2 }] } } it "builds an array of hash(id, value) matching the given params" do expect(prefill_params_array).to match([{ id: type_de_champ_child.champ.first.id, value: type_de_champ_child_value }, { id: type_de_champ_child.champ.second.id, value: type_de_champ_child_value2 }]) diff --git a/spec/models/types_de_champ/prefill_repetition_type_de_champ_spec.rb b/spec/models/types_de_champ/prefill_repetition_type_de_champ_spec.rb index c9fcbc547..731129a48 100644 --- a/spec/models/types_de_champ/prefill_repetition_type_de_champ_spec.rb +++ b/spec/models/types_de_champ/prefill_repetition_type_de_champ_spec.rb @@ -34,7 +34,7 @@ RSpec.describe TypesDeChamp::PrefillRepetitionTypeDeChamp, type: :model, vcr: { describe '#example_value' do subject(:example_value) { described_class.new(type_de_champ, procedure.active_revision).example_value } - let(:expected_value) { [{"champ_#{text_repetition.to_typed_id_for_query}" => "Texte court", "champ_#{integer_repetition.to_typed_id_for_query}" => "42", "champ_#{region_repetition.to_typed_id_for_query}" => "53"}, {"champ_#{text_repetition.to_typed_id_for_query}" => "Texte court", "champ_#{integer_repetition.to_typed_id_for_query}" => "42", "champ_#{region_repetition.to_typed_id_for_query}" => "53"}] } + let(:expected_value) { [{ "champ_#{text_repetition.to_typed_id_for_query}" => "Texte court", "champ_#{integer_repetition.to_typed_id_for_query}" => "42", "champ_#{region_repetition.to_typed_id_for_query}" => "53" }, { "champ_#{text_repetition.to_typed_id_for_query}" => "Texte court", "champ_#{integer_repetition.to_typed_id_for_query}" => "42", "champ_#{region_repetition.to_typed_id_for_query}" => "53" }] } it { expect(example_value).to eq(expected_value) } end @@ -64,13 +64,13 @@ RSpec.describe TypesDeChamp::PrefillRepetitionTypeDeChamp, type: :model, vcr: { end context 'when the value is an array with some wrong keys' do - let(:value) { [{"champ_#{text_repetition.to_typed_id_for_query}" => "value", "blabla" => "value2"}, {"champ_#{integer_repetition.to_typed_id_for_query}" => "value3"}, {"blabla" =>"false"}] } + let(:value) { [{ "champ_#{text_repetition.to_typed_id_for_query}" => "value", "blabla" => "value2" }, { "champ_#{integer_repetition.to_typed_id_for_query}" => "value3" }, { "blabla" => "false" }] } it { is_expected.to match([[{ id: text_repetition.champ.first.id, value: "value" }], [{ id: integer_repetition.champ.second.id, value: "value3" }]]) } end context 'when the value is an array with right keys' do - let(:value) { [{"champ_#{text_repetition.to_typed_id_for_query}" =>"value"}, {"champ_#{text_repetition.to_typed_id_for_query}" => "value2"}] } + let(:value) { [{ "champ_#{text_repetition.to_typed_id_for_query}" => "value" }, { "champ_#{text_repetition.to_typed_id_for_query}" => "value2" }] } it { is_expected.to match([[{ id: text_repetition.champ.first.id, value: "value" }], [{ id: text_repetition.champ.second.id, value: "value2" }]]) } end