diff --git a/app/serializers/workshop_calendar.rb b/app/serializers/workshop_calendar.rb index 196a9e68f..955a21c06 100644 --- a/app/serializers/workshop_calendar.rb +++ b/app/serializers/workshop_calendar.rb @@ -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) @@ -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) diff --git a/spec/serializers/workshop_calendar_spec.rb b/spec/serializers/workshop_calendar_spec.rb index 05f85844f..6ac84a34c 100644 --- a/spec/serializers/workshop_calendar_spec.rb +++ b/spec/serializers/workshop_calendar_spec.rb @@ -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) }