osem-fcy/spec/controllers/schedules_controller_spec.rb
Asish Kumar fae6332c36 Stop offering the schedule page when no schedule is published
The home and splash page render a link to the schedule based purely on
the `schedule_public` flag, even when an admin has not yet selected a
schedule or scheduled any events. Following that link rendered the
schedule view, which then failed inside `_carousel.html.haml` because
`@rooms` (and the selected schedule) had no data — a 500 error instead
of a graceful response.

Treat `schedule_public` as an allowance rather than an unchecked
control: introduce `Program#any_published_schedule?` (true only when
the flag is on *and* there is at least one event in a selected
schedule) and use it to decide whether to render the link from the
home and splash pages. The schedule controller now returns 404 when no
event has been scheduled, so bookmarked URLs surface as "not found"
instead of an internal server error.
2026-05-14 09:28:58 +05:30

42 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
context 'XML' do
before :each do
conference.program.schedule_public = true
conference.program.save!
create(:event_scheduled, program: conference.program)
create(:event_scheduled, program: conference.program)
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 'when schedule is public but no events are scheduled' do
before :each do
conference.program.update!(schedule_public: true)
end
it 'returns 404 instead of rendering a broken page' do
expect do
get :show, params: { conference_id: conference.short_title }
end.to raise_error(ActionController::RoutingError)
end
end
end
end