From 4146478823ccd4a3b4a575cc594b344df7929d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20K=C3=A4chele?= Date: Sat, 3 Feb 2024 14:47:18 +0100 Subject: [PATCH] Include full address in ical event When possible include the full address of the event's location in the ical event instead of just the location name --- app/helpers/ical_helper.rb | 2 +- app/models/location.rb | 8 ++++++++ spec/models/location_spec.rb | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/helpers/ical_helper.rb b/app/helpers/ical_helper.rb index d54708599..a056a6f34 100644 --- a/app/helpers/ical_helper.rb +++ b/app/helpers/ical_helper.rb @@ -10,7 +10,7 @@ def icalendar(*events) item.dtstart = event.date item.dtend = event.end_date item.url = event_url(event) - item.location = event.location.name if event.location + item.location = event.location.calendar_event_address if event.location end end end.to_s diff --git a/app/models/location.rb b/app/models/location.rb index 5a12ea50e..278cbe796 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -30,6 +30,14 @@ def address "#{street} #{house_number}, #{zip} #{city}" end + def calendar_event_address + if [street, house_number, zip, city].all?(&:present?) + address + else + name + end + end + def nice_url URI.parse(url).host end diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index 0aee0693b..6d31c4393 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -43,6 +43,16 @@ end end + describe "#calendar_event_address" do + it "returns the full address if all fields are present" do + expect(@location.calendar_event_address).to eq(@location.address) + end + + it "returns the location name if not all fields are present" do + expect(@virtual_location.calendar_event_address).to eq(@virtual_location.name) + end + end + describe '#geocoding' do it 'geocodes once a location is saved' do Location.all.find_each do |locn|