-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10703 from mfo/US/dry-rna-rnf-siret-addresses-view
ETQ instructeur, je souhaite acceder aux information liées à l'adresses des champs RNA/RNF/SIRET
- Loading branch information
Showing
16 changed files
with
137 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddressProxy | ||
ADDRESS_PARTS = [ | ||
:street_address, | ||
:city_name, | ||
:postal_code, | ||
:city_code, | ||
:departement_name, | ||
:departement_code, | ||
:region_name, | ||
:region_code | ||
] | ||
|
||
class ChampAddressPresenter | ||
ADDRESS_PARTS.each do |address_part| | ||
define_method(address_part) do | ||
@data[address_part] | ||
end | ||
end | ||
|
||
def initialize(champ) | ||
@data = champ.value_json.with_indifferent_access | ||
end | ||
end | ||
|
||
class EtablissementAddressPresenter | ||
attr_reader(*ADDRESS_PARTS) | ||
|
||
def initialize(etablissement) | ||
@street_address = [etablissement.numero_voie, etablissement.type_voie, etablissement.nom_voie].compact.join(" ") | ||
@city_name = etablissement.localite | ||
@postal_code = etablissement.code_postal | ||
@city_code = etablissement.code_insee_localite | ||
@departement_name = APIGeoService.departement_name_by_postal_code(@postal_code) | ||
@departement_code = APIGeoService.departement_code(@departement_name) | ||
@region_code = APIGeoService.region_code_by_departement(@departement_code) | ||
@region_name = APIGeoService.region_name(@region_code) | ||
end | ||
end | ||
|
||
delegate(*ADDRESS_PARTS, to: :@presenter) | ||
|
||
def initialize(champ_or_etablissement) | ||
@presenter = make(champ_or_etablissement) | ||
end | ||
|
||
def make(champ_or_etablissement) | ||
case champ_or_etablissement | ||
when Champ then ChampAddressPresenter.new(champ_or_etablissement) | ||
when Etablissement then EtablissementAddressPresenter.new(champ_or_etablissement) | ||
else raise NotImplementedError("Unsupported address from #{champ_or_etablissement.class.name}") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
- if champ.etablissement.present? | ||
= render partial: "shared/dossiers/identite_entreprise", locals: { etablissement: champ.etablissement, profile: profile } | ||
= render partial: "shared/dossiers/identite_entreprise", locals: { etablissement: champ.etablissement, profile: profile, champ: } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.normalized_address.full_address")) do |c| | ||
- c.with_value do | ||
%p | ||
= address.street_address | ||
%br | ||
= [address.city_name, address.postal_code].join(" ") | ||
|
||
|
||
- ['city_code', 'postal_code'].each do |scope| | ||
- if address.public_send(scope).present? | ||
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.normalized_address.#{scope}")) do |c| | ||
- c.with_value do | ||
%p= address.public_send(scope) | ||
|
||
- if address.departement_name.present? | ||
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.normalized_address.department")) do |c| | ||
- c.with_value do | ||
%p= "#{address.departement_name} – #{address.departement_code}" | ||
|
||
- if address.region_name.present? | ||
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.normalized_address.region")) do |c| | ||
- c.with_value do | ||
%p= "#{address.region_name} – #{address.region_code}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
en: | ||
activemodel: | ||
attributes: | ||
normalized_address: | ||
full_address: Address | ||
city_code: INSEE code | ||
postal_code: Postal code | ||
department: Department | ||
region: Region & region code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fr: | ||
activemodel: | ||
attributes: | ||
normalized_address: | ||
full_address: Adresse | ||
city_code: Code INSEE | ||
postal_code: Code postal | ||
department: Département | ||
region: Région & code région |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
spec/views/shared/dossiers/_normalized_address.html.haml_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
describe 'shared/dossiers/normalized_address', type: :view do | ||
before { render 'shared/dossiers/normalized_address', address: } | ||
|
||
context 'given an champ' do | ||
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }]) } | ||
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) } | ||
let(:address) { AddressProxy.new(dossier.champs.first) } | ||
|
||
it 'render address' do | ||
AddressProxy::ADDRESS_PARTS.each do |address_part| | ||
expect(rendered).to have_text(address_part) | ||
end | ||
end | ||
end | ||
|
||
context 'given an etablissement' do | ||
let(:etablissement) { create(:etablissement) } | ||
let(:address) { AddressProxy.new(etablissement) } | ||
|
||
it 'render address' do | ||
expect(rendered).to have_text("6 RUE RAOUL NORDLING") | ||
expect(rendered).to have_text("BOIS COLOMBES 92270") | ||
expect(rendered).to have_text("92009") | ||
expect(rendered).to have_text("92270") | ||
expect(rendered).to have_text("Hauts-de-Seine – 92") | ||
expect(rendered).to have_text("Île-de-France – 11") | ||
end | ||
end | ||
end |