[#2179] Use new updated value for search terms

Rather than old in-database value
This commit is contained in:
Frederic Merizen 2018-08-22 17:48:25 +02:00
parent 333f4e8824
commit 3b2919a326
2 changed files with 18 additions and 4 deletions

View file

@ -85,12 +85,12 @@ class Dossier < ApplicationRecord
user&.email,
france_connect_information&.given_name,
france_connect_information&.family_name,
*ordered_champs.flat_map(&:search_terms),
*champs.flat_map(&:search_terms),
*etablissement&.search_terms,
individual&.nom,
individual&.prenom
].compact.join(' ')
self.private_search_terms = ordered_champs_private.flat_map(&:search_terms).compact.join(' ')
self.private_search_terms = champs_private.flat_map(&:search_terms).compact.join(' ')
end
def was_piece_justificative_uploaded_for_type_id?(type_id)

View file

@ -39,16 +39,30 @@ describe Dossier do
let(:dossier) { create(:dossier, etablissement: etablissement, user: user, procedure: procedure) }
let(:france_connect_information) { build(:france_connect_information, given_name: 'Chris', family_name: 'Harrisson') }
let(:user) { build(:user, france_connect_information: france_connect_information) }
let(:champ_public) { dossier.champs.first }
let(:champ_private) { dossier.champs_private.first }
before do
dossier.champs.each { |c| c.update_attribute(:value, "champ public") }
dossier.champs_private.each { |c| c.update_attribute(:value, "champ privé") }
champ_public.update_attribute(:value, "champ public")
champ_private.update_attribute(:value, "champ privé")
dossier.update_search_terms
end
it { expect(dossier.search_terms).to eq("#{user.email} #{france_connect_information.given_name} #{france_connect_information.family_name} champ public #{etablissement.entreprise_siren} #{etablissement.entreprise_numero_tva_intracommunautaire} #{etablissement.entreprise_forme_juridique} #{etablissement.entreprise_forme_juridique_code} #{etablissement.entreprise_nom_commercial} #{etablissement.entreprise_raison_sociale} #{etablissement.entreprise_siret_siege_social} #{etablissement.entreprise_nom} #{etablissement.entreprise_prenom} #{etablissement.association_rna} #{etablissement.association_titre} #{etablissement.association_objet} #{etablissement.siret} #{etablissement.naf} #{etablissement.libelle_naf} #{etablissement.adresse} #{etablissement.code_postal} #{etablissement.localite} #{etablissement.code_insee_localite}") }
it { expect(dossier.private_search_terms).to eq('champ privé') }
context 'with an update' do
before do
dossier.update(
champs_attributes: [{ id: champ_public.id, value: 'nouvelle valeur publique' }],
champs_private_attributes: [{ id: champ_private.id, value: 'nouvelle valeur privee' }]
)
end
it { expect(dossier.search_terms).to include('nouvelle valeur publique') }
it { expect(dossier.private_search_terms).to include('nouvelle valeur privee') }
end
end
describe '#types_de_piece_justificative' do