Skip to content
Open
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
5 changes: 4 additions & 1 deletion app/helpers/conference_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def conference_color(conference)
# adds events to icalendar for proposals in a conference
def icalendar_proposals(calendar, proposals, conference)
proposals.each do |proposal|
# some 2021 events have nil time or event_type
next if proposal.time.nil? || proposal.event_type.nil?

calendar.event do |e|
e.dtstart = proposal.time
e.dtend = proposal.time + (proposal.event_type.length * 60)
Expand All @@ -49,7 +52,7 @@ def icalendar_proposals(calendar, proposals, conference)
if v
e.geo = v.latitude, v.longitude if v.latitude && v.longitude
location = ''
location += "#{proposal.room.name} - " if proposal.room.name
location += "#{proposal.room.name} - " if proposal.room&.name
location += " - #{v.street}, " if v.street
location += "#{v.postalcode} #{v.city}, " if v.postalcode && v.city
location += "#{v.country_name}, " if v.country_name
Expand Down
54 changes: 54 additions & 0 deletions spec/helpers/conference_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,60 @@
end
end

describe '#icalendar_proposals' do
let!(:conference_with_venue) do
create(:conference, venue: create(:venue))
end
let!(:contact_for_venue_conf) { create(:contact, conference: conference_with_venue) }
context 'when an event has a nil event_type' do
it 'skips the event and adds no VEVENT to the calendar' do
cal = Icalendar::Calendar.new
event = create(:event, program: conference_with_venue.program)
# Bypass validation to simulate legacy 2021 data with nil event_type
event.update_column(:event_type_id, nil)
event.reload

icalendar_proposals(cal, [event], conference_with_venue)
expect(cal.events).to be_empty
end
end

context 'when an event has a nil time (no event_schedule for selected schedule)' do
it 'skips the event and adds no VEVENT to the calendar' do
cal = Icalendar::Calendar.new
event = create(:event, program: conference_with_venue.program)
# Event exists but has no event_schedule, so event.time returns nil

icalendar_proposals(cal, [event], conference_with_venue)
expect(cal.events).to be_empty
end
end

context 'when an event has a nil room and conference has a venue' do
it 'still adds the event but builds location without room name' do
cal = Icalendar::Calendar.new
event = create(:event_scheduled, program: conference_with_venue.program)
# Nullify the room on the event_schedule to simulate missing room data
event.event_schedules.each { |es| es.update_column(:room_id, nil) }

icalendar_proposals(cal, [event], conference_with_venue)
expect(cal.events.size).to eq(1)
expect(cal.events.first.summary).to eq(event.title)
end
end

context 'with valid events' do
it 'adds the event to the calendar with correct summary' do
cal = Icalendar::Calendar.new
event = create(:event_scheduled, program: conference_with_venue.program)

icalendar_proposals(cal, [event], conference_with_venue)
expect(cal.events.size).to eq(1)
expect(cal.events.first.summary).to eq(event.title)
end
end
end

describe '#get_happening_next_events_schedules' do
let!(:conference2) do
create(:full_conference, start_date: 1.day.ago, end_date: 7.days.from_now, start_hour: 0, end_hour: 24)
Expand Down
Loading