fix(dossier): update search terms when etablissement or individual changed
This commit is contained in:
parent
ee465b38ff
commit
4408824882
4 changed files with 34 additions and 12 deletions
|
@ -17,6 +17,8 @@ class Etablissement < ApplicationRecord
|
|||
fermé: "fermé"
|
||||
}, _prefix: true
|
||||
|
||||
after_commit -> { dossier&.debounce_update_search_terms }
|
||||
|
||||
def entreprise_raison_sociale
|
||||
read_attribute(:entreprise_raison_sociale).presence || raison_sociale_for_ei
|
||||
end
|
||||
|
|
|
@ -17,6 +17,8 @@ class Individual < ApplicationRecord
|
|||
|
||||
validates :email, presence: true, if: -> { dossier.for_tiers? && self.email? }, on: :update
|
||||
|
||||
after_commit -> { dossier.debounce_update_search_terms }, if: -> { nom_previously_changed? || prenom_previously_changed? }
|
||||
|
||||
GENDER_MALE = "M."
|
||||
GENDER_FEMALE = 'Mme'
|
||||
|
||||
|
|
|
@ -115,6 +115,16 @@ describe Etablissement do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'update search terms' do
|
||||
let(:etablissement) { create(:etablissement, dossier: build(:dossier)) }
|
||||
|
||||
it "schedule update search terms" do
|
||||
assert_enqueued_jobs(1, only: DossierUpdateSearchTermsJob) do
|
||||
etablissement.update(entreprise_nom: "nom")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def csv_to_array_of_hash(lines)
|
||||
|
|
|
@ -7,41 +7,49 @@ describe Individual do
|
|||
describe "#save" do
|
||||
let(:individual) { build(:individual) }
|
||||
|
||||
subject { individual.save }
|
||||
subject do
|
||||
individual.save
|
||||
individual
|
||||
end
|
||||
|
||||
context "with birthdate" do
|
||||
before do
|
||||
individual.birthdate = birthdate_from_user
|
||||
subject
|
||||
end
|
||||
|
||||
context "and the format is dd/mm/yyy " do
|
||||
let(:birthdate_from_user) { "12/11/1980" }
|
||||
|
||||
it { expect(individual.birthdate).to eq(Date.new(1980, 11, 12)) }
|
||||
it { expect(subject.birthdate).to eq(Date.new(1980, 11, 12)) }
|
||||
end
|
||||
|
||||
context "and the format is ISO" do
|
||||
let(:birthdate_from_user) { "1980-11-12" }
|
||||
|
||||
it { expect(individual.birthdate).to eq(Date.new(1980, 11, 12)) }
|
||||
it { expect(subject.birthdate).to eq(Date.new(1980, 11, 12)) }
|
||||
end
|
||||
|
||||
context "and the format is WTF" do
|
||||
let(:birthdate_from_user) { "1980 1 12" }
|
||||
|
||||
it { expect(individual.birthdate).to be_nil }
|
||||
it { expect(subject.birthdate).to be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when an individual has an invalid notification_method' do
|
||||
let(:invalid_individual) { build(:individual, notification_method: 'invalid_method') }
|
||||
|
||||
it 'raises an ArgumentError' do
|
||||
expect {
|
||||
invalid_individual.valid?
|
||||
}.to raise_error(ArgumentError, "'invalid_method' is not a valid notification_method")
|
||||
it "schedule update search terms" do
|
||||
assert_enqueued_jobs(1, only: DossierUpdateSearchTermsJob) do
|
||||
subject
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when an individual has an invalid notification_method' do
|
||||
let(:invalid_individual) { build(:individual, notification_method: 'invalid_method') }
|
||||
|
||||
it 'raises an ArgumentError' do
|
||||
expect {
|
||||
invalid_individual.valid?
|
||||
}.to raise_error(ArgumentError, "'invalid_method' is not a valid notification_method")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue