Skip to content

Commit

Permalink
Bugfix: le RDV affiche l'adresse du proche plutôt que celle du respon…
Browse files Browse the repository at this point in the history
…sable
  • Loading branch information
francois-ferrandis committed Nov 15, 2024
1 parent fb68d72 commit 6c1f33e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
5 changes: 5 additions & 0 deletions app/models/concerns/rdv/address_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 0 additions & 5 deletions app/models/rdv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
14 changes: 7 additions & 7 deletions spec/models/rdv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6c1f33e

Please sign in to comment.