From 17418edb547fac8f2c4ba443486c58482f5e8734 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Mon, 22 Oct 2018 19:27:33 +0200 Subject: [PATCH] Add SIRET champs support to the API --- app/serializers/champs/siret_champ_serializer.rb | 12 ++++++++++++ .../champs/siret_champ_serializer_spec.rb | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 app/serializers/champs/siret_champ_serializer.rb create mode 100644 spec/serializers/champs/siret_champ_serializer_spec.rb diff --git a/app/serializers/champs/siret_champ_serializer.rb b/app/serializers/champs/siret_champ_serializer.rb new file mode 100644 index 000000000..9bb54ce4d --- /dev/null +++ b/app/serializers/champs/siret_champ_serializer.rb @@ -0,0 +1,12 @@ +class Champs::SiretChampSerializer < ChampSerializer + has_one :etablissement + has_one :entreprise + + def etablissement + object.etablissement + end + + def entreprise + object.etablissement&.entreprise + end +end diff --git a/spec/serializers/champs/siret_champ_serializer_spec.rb b/spec/serializers/champs/siret_champ_serializer_spec.rb new file mode 100644 index 000000000..1614dc7bd --- /dev/null +++ b/spec/serializers/champs/siret_champ_serializer_spec.rb @@ -0,0 +1,16 @@ +describe Champs::SiretChampSerializer do + describe '#attributes' do + subject { Champs::SiretChampSerializer.new(champ).serializable_hash } + + context 'when type champ is siret' do + let(:etablissement) { create(:etablissement) } + let(:champ) { create(:type_de_champ_siret).champ.create(etablissement: etablissement, value: etablissement.siret) } + + it { + is_expected.to include(value: etablissement.siret) + expect(subject[:etablissement]).to include(siret: etablissement.siret) + expect(subject[:entreprise]).to include(capital_social: etablissement.entreprise_capital_social) + } + end + end +end