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