build raison sociale from nom and nom

This commit is contained in:
Christophe Robillard 2023-07-14 15:17:02 +02:00
parent 9bd6cea38d
commit 67b9bb264a
2 changed files with 34 additions and 0 deletions

View file

@ -66,6 +66,16 @@ class Etablissement < ApplicationRecord
fermé: "fermé" fermé: "fermé"
}, _prefix: true }, _prefix: true
def entreprise_raison_sociale
read_attribute(:entreprise_raison_sociale).presence || raison_sociale_for_ei
end
def raison_sociale_for_ei
if entreprise_nom || entreprise_prenom
[entreprise_nom, entreprise_prenom].join(' ')
end
end
def search_terms def search_terms
[ [
entreprise_siren, entreprise_siren,

View file

@ -36,6 +36,30 @@ describe Etablissement do
end end
end end
describe '#entreprise_raison_sociale' do
subject { etablissement.entreprise_raison_sociale }
context "with nom and prenom" do
context "without raison sociale" do
let(:etablissement) { create(:etablissement, entreprise_raison_sociale: nil, entreprise_prenom: "Stef", entreprise_nom: "Sanseverino") }
it { is_expected.to eq "Sanseverino Stef" }
end
context "with raison sociale" do
let(:etablissement) { create(:etablissement, entreprise_raison_sociale: "Sansev Prod", entreprise_prenom: "Stef", entreprise_nom: "Sanseverino") }
it { is_expected.to eq "Sansev Prod" }
end
end
context "without nom and prenom" do
let(:etablissement) { create(:etablissement, entreprise_raison_sociale: "ENGIE", entreprise_prenom: nil, entreprise_nom: nil) }
it { is_expected.to eq "ENGIE" }
end
end
describe '.entreprise_bilans_bdf_to_csv' do describe '.entreprise_bilans_bdf_to_csv' do
let(:etablissement) { build(:etablissement, entreprise_bilans_bdf: bilans) } let(:etablissement) { build(:etablissement, entreprise_bilans_bdf: bilans) }
let(:ordered_headers) { let(:ordered_headers) {