From 6c1f33e87d0988415dec0796779d14370b5bb51a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Ferrandis?= Date: Thu, 14 Nov 2024 17:23:17 +0100 Subject: [PATCH] =?UTF-8?q?Bugfix:=20le=20RDV=20affiche=20l'adresse=20du?= =?UTF-8?q?=20proche=20plut=C3=B4t=20que=20celle=20du=20responsable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/rdv/address_concern.rb | 5 +++++ app/models/rdv.rb | 5 ----- spec/models/rdv_spec.rb | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/models/concerns/rdv/address_concern.rb b/app/models/concerns/rdv/address_concern.rb index 2a39d9faa7..d1965e820c 100644 --- a/app/models/concerns/rdv/address_concern.rb +++ b/app/models/concerns/rdv/address_concern.rb @@ -53,4 +53,9 @@ def address_without_personal_information Motif.human_attribute_value(:location_type, :phone) end end + + def user_for_home_rdv + proches, responsables = users.partition(&:responsible_id) + (responsables + proches).select(&:address).first || users.first + end end diff --git a/app/models/rdv.rb b/app/models/rdv.rb index f22203dea5..1e52d59338 100644 --- a/app/models/rdv.rb +++ b/app/models/rdv.rb @@ -211,11 +211,6 @@ def creneaux_available(date_range) CreneauxSearch::Calculator.available_slots(motif, lieu, date_range) end - def user_for_home_rdv - responsibles = users.loaded? ? users.select(&:responsible_id) : users.where.not(responsible_id: [nil]) - [responsibles, users].flatten.select(&:address).first || users.first - end - # Ces plages d'ouvertures sont utilisé pour afficher des infos # s'il y a un chevauchement avec le RDV. # diff --git a/spec/models/rdv_spec.rb b/spec/models/rdv_spec.rb index 68839b60b2..d9b7e050c9 100644 --- a/spec/models/rdv_spec.rb +++ b/spec/models/rdv_spec.rb @@ -186,17 +186,17 @@ end context "when rdv is at home" do - let(:responsible) { create(:user) } - let(:child) { create(:user, responsible: responsible) } - let(:rdv) { create(:rdv, :at_home, users: [child]) } + let(:responsable) { create(:user, address: "1 rue du Responsable, 74000 Annecy") } + let(:proche) { create(:user, responsible: responsable, address: "33 impasse du Proche, 42300 Roanne") } + let(:rdv) { create(:rdv, :at_home, users: [responsable, proche]) } - it { is_expected.to eq responsible.address } + it { is_expected.to eq responsable.address } end context "when rdv is by phone" do - let(:responsible) { create(:user) } - let(:child) { create(:user, responsible: responsible) } - let(:rdv) { create(:rdv, :by_phone, users: [child]) } + let(:responsable) { create(:user) } + let(:proche) { create(:user, responsible: responsable) } + let(:rdv) { create(:rdv, :by_phone, users: [responsable, proche]) } it { is_expected.to be_blank } end