osem-fcy/spec/controllers/schedules_controller_spec.rb
Asish Kumar c5e84221c2 Make iCalendar feed routes return calendar data
Both iCalendar routes were unusable:

* `/conferences/.../schedule.ics` raised
  `NoMethodError: undefined method 'icalendar_proposals'` because the
  `ConferenceHelper#icalendar_proposals` helper isn't auto-included in
  controllers; the action crashed before rendering.

* `/calendar.ics` silently redirected to `/`. The controller goes
  through `load_and_authorize_resource`, which authorises `:calendar`
  on `Conference` and is rejected for anonymous visitors because no
  ability grants it — CanCan's `AccessDenied` rescue redirects to
  root.

The helper is invoked through the controller `helpers` proxy so it
works in both contexts, and the calendar action is opted out of
resource loading and explicitly marked as not requiring authorization
since it serves a public feed across conferences. The helper is also
hardened so that proposals missing a room, difficulty level, track,
event type or scheduled time produce a valid event instead of
crashing the whole feed.
2026-05-14 11:02:49 +05:30

45 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
describe SchedulesController do
let(:conference) { create(:conference, splashpage: create(:splashpage, public: true), venue: create(:venue)) }
describe 'GET #show' do
before :each do
conference.program.update!(schedule_public: true)
create_pair(:event_scheduled, program: conference.program)
end
context 'XML' do
before :each do
get :show, params: { conference_id: conference.short_title, format: :xml }
end
it 'assigns variables' do
expect(assigns(:conference)).to eq conference
expect(assigns(:events_xml)).to eq conference.program.selected_event_schedules.map(&:event)
.group_by{ |event| event.time.to_date }
end
it 'has 200 status code' do
expect(response).to be_successful
end
end
context 'iCalendar' do
before :each do
get :show, params: { conference_id: conference.short_title, format: :ics }
end
it 'has 200 status code' do
expect(response).to be_successful
end
it 'returns iCalendar data' do
expect(response.content_type).to start_with('text/calendar')
expect(response.body).to start_with('BEGIN:VCALENDAR')
end
end
end
end