Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/serializers/workshop_calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def calendar

def setup_event
calendar.event do |e|
configure(e, host_name: workshop.host.name)
configure(e, host_name: workshop.host&.name || 'TBA')

e.location = address(workshop)
e.description = I18n.t('workshop.calendar.description', invitation_link: invitation_url)
Expand Down Expand Up @@ -55,7 +55,7 @@ def configure(event, host_name:)
end

def address(workshop)
AddressPresenter.new(workshop.host.address).to_s
workshop.host&.address ? AddressPresenter.new(workshop.host.address).to_s : 'TBA'
end

def start_and_end_time(event)
Expand Down
33 changes: 33 additions & 0 deletions spec/serializers/workshop_calendar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,39 @@
end
end

context 'with a physical workshop that has no host' do
let(:workshop) { Fabricate(:workshop_no_sponsor, virtual: false) }

it 'falls back to TBA for host name and address' do
event = calendar.events.first

expect(event.summary.to_s).to eq('codebar @ TBA')
expect(event.location.to_s).to eq('TBA')
expect(event.organizer.to_s).to eq(workshop.chapter.email)
expect(event.description).to include(invitation_url)
end

it 'serialises the fallback into the iCalendar output' do
expect(described_class.new(workshop, invitation_url).ical).to include('TBA')
end
end

context 'with a host whose address record has been removed' do
let(:workshop) do
Fabricate(:workshop).tap do |w|
w.host.address.destroy
w.reload
end
end

it 'keeps the host name and falls back to TBA for the address' do
event = calendar.events.first

expect(event.summary.to_s).to eq("codebar @ #{workshop.host.name}")
expect(event.location.to_s).to eq('TBA')
end
end

context 'with a virtual workshop' do
let(:workshop) { Fabricate(:virtual_workshop) }

Expand Down
Loading