Skip to content

Commit f462c53

Browse files
committed
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
1 parent 31fc08b commit f462c53

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

app/helpers/ical_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def icalendar(*events)
1010
item.dtstart = event.date
1111
item.dtend = event.end_date
1212
item.url = event_url(event)
13-
item.location = event.location.name if event.location
13+
item.location = event.location.calendar_event_address if event.location
1414
end
1515
end
1616
end.to_s

app/models/location.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ def address
3030
"#{street} #{house_number}, #{zip} #{city}"
3131
end
3232

33+
def calendar_event_address
34+
if [street, house_number, zip, city].all?(&:present?)
35+
address
36+
else
37+
name
38+
end
39+
end
40+
3341
def nice_url
3442
URI.parse(url).host
3543
end

spec/models/location_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@
4343
end
4444
end
4545

46+
describe "#calendar_event_address" do
47+
it "returns the full address if all fields are present" do
48+
expect(@location.calendar_event_address).to eq(@location.address)
49+
end
50+
51+
it "returns the location name if not all fields are present" do
52+
expect(@virtual_location.calendar_event_address).to eq(@virtual_location.name)
53+
end
54+
end
55+
4656
describe '#geocoding' do
4757
it 'geocodes once a location is saved' do
4858
Location.all.each do |locn|

0 commit comments

Comments
 (0)