Skip to content

Commit

Permalink
Include full address in ical event
Browse files Browse the repository at this point in the history
When possible include the full address of the event's location in
the ical event instead of just the location name
  • Loading branch information
timkaechele committed Jun 18, 2024
1 parent 77394a2 commit 4146478
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/ical_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions app/models/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/models/location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down

0 comments on commit 4146478

Please sign in to comment.