From 5d188c191d1f9aa287cfd5cf6121ba83691fae10 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 19 Mar 2018 15:41:20 +0100 Subject: [PATCH] Move transform_keys calls directly to #process_params methods --- app/lib/api_entreprise/entreprise_adapter.rb | 2 +- app/lib/api_entreprise/rna_adapter.rb | 2 +- app/services/api_entreprise_service.rb | 4 ++-- .../api_entreprise/entreprise_adapter_spec.rb | 24 +++++++++---------- spec/lib/api_entreprise/rna_adapter_spec.rb | 12 +++++----- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/lib/api_entreprise/entreprise_adapter.rb b/app/lib/api_entreprise/entreprise_adapter.rb index 015c64ec2..b32305c47 100644 --- a/app/lib/api_entreprise/entreprise_adapter.rb +++ b/app/lib/api_entreprise/entreprise_adapter.rb @@ -9,7 +9,7 @@ class ApiEntreprise::EntrepriseAdapter < ApiEntreprise::Adapter def process_params params = data_source[:entreprise].slice(*attr_to_fetch) params[:date_creation] = Time.at(params[:date_creation]).to_datetime - params + params.transform_keys { |k| :"entreprise_#{k}" } end def attr_to_fetch diff --git a/app/lib/api_entreprise/rna_adapter.rb b/app/lib/api_entreprise/rna_adapter.rb index 333a382cc..9d0612788 100644 --- a/app/lib/api_entreprise/rna_adapter.rb +++ b/app/lib/api_entreprise/rna_adapter.rb @@ -9,7 +9,7 @@ class ApiEntreprise::RNAAdapter < ApiEntreprise::Adapter if data_source[:association][:id].present? params = data_source[:association].slice(*attr_to_fetch) params[:rna] = data_source[:association][:id] - params + params.transform_keys { |k| :"association_#{k}" } else {} end diff --git a/app/services/api_entreprise_service.rb b/app/services/api_entreprise_service.rb index e3ea78622..63335105f 100644 --- a/app/services/api_entreprise_service.rb +++ b/app/services/api_entreprise_service.rb @@ -8,8 +8,8 @@ class ApiEntrepriseService exercices_params = ApiEntreprise::ExercicesAdapter.new(siret, procedure_id).to_params params = etablissement_params - .merge(entreprise_params.transform_keys { |k| "entreprise_#{k}" }) - .merge(association_params.transform_keys { |k| "association_#{k}" }) + .merge(entreprise_params) + .merge(association_params) .merge(exercices_params) params diff --git a/spec/lib/api_entreprise/entreprise_adapter_spec.rb b/spec/lib/api_entreprise/entreprise_adapter_spec.rb index f9eaf62eb..52b70e490 100644 --- a/spec/lib/api_entreprise/entreprise_adapter_spec.rb +++ b/spec/lib/api_entreprise/entreprise_adapter_spec.rb @@ -17,51 +17,51 @@ describe ApiEntreprise::EntrepriseAdapter do context 'Attributs Entreprises' do it 'L\'entreprise contient bien un siren' do - expect(subject[:siren]).to eq(siren) + expect(subject[:entreprise_siren]).to eq(siren) end it 'L\'entreprise contient bien un capital_social' do - expect(subject[:capital_social]).to eq(462308) + expect(subject[:entreprise_capital_social]).to eq(462308) end it 'L\'entreprise contient bien un numero_tva_intracommunautaire' do - expect(subject[:numero_tva_intracommunautaire]).to eq('FR16418166096') + expect(subject[:entreprise_numero_tva_intracommunautaire]).to eq('FR16418166096') end it 'L\'entreprise contient bien une forme_juridique' do - expect(subject[:forme_juridique]).to eq('SA à directoire (s.a.i.)') + expect(subject[:entreprise_forme_juridique]).to eq('SA à directoire (s.a.i.)') end it 'L\'entreprise contient bien un forme_juridique_code' do - expect(subject[:forme_juridique_code]).to eq('5699') + expect(subject[:entreprise_forme_juridique_code]).to eq('5699') end it 'L\'entreprise contient bien un nom_commercial' do - expect(subject[:nom_commercial]).to eq('OCTO-TECHNOLOGY') + expect(subject[:entreprise_nom_commercial]).to eq('OCTO-TECHNOLOGY') end it 'L\'entreprise contient bien une raison_sociale' do - expect(subject[:raison_sociale]).to eq('OCTO-TECHNOLOGY') + expect(subject[:entreprise_raison_sociale]).to eq('OCTO-TECHNOLOGY') end it 'L\'entreprise contient bien un siret_siege_social' do - expect(subject[:siret_siege_social]).to eq('41816609600051') + expect(subject[:entreprise_siret_siege_social]).to eq('41816609600051') end it 'L\'entreprise contient bien un code_effectif_entreprise' do - expect(subject[:code_effectif_entreprise]).to eq('31') + expect(subject[:entreprise_code_effectif_entreprise]).to eq('31') end it 'L\'entreprise contient bien une date_creation' do - expect(subject[:date_creation]).to eq('Wed, 01 Apr 1998 00:00:00.000000000 +0200') + expect(subject[:entreprise_date_creation]).to eq('Wed, 01 Apr 1998 00:00:00.000000000 +0200') end it 'L\'entreprise contient bien un nom' do - expect(subject[:nom]).to eq('test_nom') + expect(subject[:entreprise_nom]).to eq('test_nom') end it 'L\'entreprise contient bien un prenom' do - expect(subject[:prenom]).to eq('test_prenom') + expect(subject[:entreprise_prenom]).to eq('test_prenom') end end end diff --git a/spec/lib/api_entreprise/rna_adapter_spec.rb b/spec/lib/api_entreprise/rna_adapter_spec.rb index 2df856cbe..b567c47ec 100644 --- a/spec/lib/api_entreprise/rna_adapter_spec.rb +++ b/spec/lib/api_entreprise/rna_adapter_spec.rb @@ -25,16 +25,16 @@ describe ApiEntreprise::RNAAdapter do it { expect(subject).to be_an_instance_of(Hash) } describe 'Attributs Associations' do - it { expect(subject[:rna]).to eq('W595001988') } + it { expect(subject[:association_rna]).to eq('W595001988') } - it { expect(subject[:titre]).to eq('UN SUR QUATRE') } + it { expect(subject[:association_titre]).to eq('UN SUR QUATRE') } - it { expect(subject[:objet]).to eq("valoriser, transmettre et partager auprès des publics les plus larges possibles, les bienfaits de l'immigration, la richesse de la diversité et la curiosité de l'autre autrement") } + it { expect(subject[:association_objet]).to eq("valoriser, transmettre et partager auprès des publics les plus larges possibles, les bienfaits de l'immigration, la richesse de la diversité et la curiosité de l'autre autrement") } - it { expect(subject[:date_creation]).to eq('2014-01-23') } + it { expect(subject[:association_date_creation]).to eq('2014-01-23') } - it { expect(subject[:date_declaration]).to eq('2014-01-24') } + it { expect(subject[:association_date_declaration]).to eq('2014-01-24') } - it { expect(subject[:date_publication]).to eq('2014-02-08') } + it { expect(subject[:association_date_publication]).to eq('2014-02-08') } end end