From 71dab6b79c54dbfc1a008ed87a4aab62c168db6a Mon Sep 17 00:00:00 2001 From: Ana Date: Fri, 29 Jul 2016 22:02:01 +0200 Subject: [PATCH] SchedulesController introduced The actions #schedule and #events were moved from conference controller to the new controller --- app/controllers/conference_controller.rb | 35 -------------- app/controllers/schedules_controller.rb | 48 +++++++++++++++++++ app/models/email_settings.rb | 2 +- app/views/admin/commercials/index.html.haml | 2 +- .../conference/_conference_details.html.haml | 2 +- .../conference/_schedule_splashpage.html.haml | 2 +- app/views/proposal/show.html.haml | 2 +- .../_carousel.html.haml | 0 .../_event.html.haml | 0 .../_schedule.html.haml | 0 .../_schedule_item.html.haml | 0 .../_schedule_tabs.html.haml | 4 +- .../events.html.haml | 0 .../show.html.haml} | 0 .../show.xml.haml} | 0 config/routes.rb | 8 ++-- .../controllers/conference_controller_spec.rb | 23 --------- spec/controllers/schedules_controller_spec.rb | 28 +++++++++++ 18 files changed, 87 insertions(+), 69 deletions(-) create mode 100644 app/controllers/schedules_controller.rb rename app/views/{conference => schedules}/_carousel.html.haml (100%) rename app/views/{conference => schedules}/_event.html.haml (100%) rename app/views/{conference => schedules}/_schedule.html.haml (100%) rename app/views/{conference => schedules}/_schedule_item.html.haml (100%) rename app/views/{conference => schedules}/_schedule_tabs.html.haml (63%) rename app/views/{conference => schedules}/events.html.haml (100%) rename app/views/{conference/schedule.html.haml => schedules/show.html.haml} (100%) rename app/views/{conference/schedule.xml.haml => schedules/show.xml.haml} (100%) create mode 100644 spec/controllers/schedules_controller_spec.rb diff --git a/app/controllers/conference_controller.rb b/app/controllers/conference_controller.rb index 4a8324a7..75dce7c0 100644 --- a/app/controllers/conference_controller.rb +++ b/app/controllers/conference_controller.rb @@ -11,41 +11,6 @@ class ConferenceController < ApplicationController def show; end - def schedule - @rooms = @conference.venue.rooms if @conference.venue - unless @program.selected_schedule.present? && @program.events.scheduled(@program.selected_schedule.id).any? - redirect_to events_conference_path(@conference.short_title) - end - - @events = @conference.program.events - schedules = @program.selected_event_schedules - @events_xml = schedules.map(&:event).group_by{ |event| event.scheduled_start_time.to_date } if schedules - @dates = @conference.start_date..@conference.end_date - @step_minutes = EventType::LENGTH_STEP.minutes - @conf_start = 9 - conf_end = 20 - @conf_period = conf_end - @conf_start - - # the schedule takes you to today if it is a date of the schedule - @current_day = @conference.current_conference_day - @day = @current_day.present? ? @current_day : @dates.first - return unless @current_day - # the schedule takes you to the current time if it is beetween the start and the end time. - @hour_column = @conference.hours_from_start_time(@conf_start, conf_end) - end - - def events - @dates = @conference.start_date..@conference.end_date - - @events_schedules = @program.selected_event_schedules - @events_schedules = [] unless @events_schedules - - @unscheduled_events = @program.events.unscheduled(@program.selected_schedule.id) - - day = @conference.current_conference_day - @tag = day.strftime('%Y-%m-%d') if day - end - private def respond_to_options diff --git a/app/controllers/schedules_controller.rb b/app/controllers/schedules_controller.rb new file mode 100644 index 00000000..b0cc3dd0 --- /dev/null +++ b/app/controllers/schedules_controller.rb @@ -0,0 +1,48 @@ +class SchedulesController < ApplicationController + protect_from_forgery with: :null_session + before_action :respond_to_options + load_and_authorize_resource :conference, find_by: :short_title + load_resource :program, through: :conference, singleton: true, except: :index + + def show + @rooms = @conference.venue.rooms if @conference.venue + unless @program.selected_schedule.present? && @program.events.scheduled(@program.selected_schedule.id).any? + redirect_to events_conference_schedule_path(@conference.short_title) + end + + schedules = @program.selected_event_schedules + @events_xml = schedules.map(&:event).group_by{ |event| event.scheduled_start_time.to_date } if schedules + @dates = @conference.start_date..@conference.end_date + @step_minutes = EventType::LENGTH_STEP.minutes + @conf_start = 9 + conf_end = 20 + @conf_period = conf_end - @conf_start + + # the schedule takes you to today if it is a date of the schedule + @current_day = @conference.current_conference_day + @day = @current_day.present? ? @current_day : @dates.first + return unless @current_day + # the schedule takes you to the current time if it is beetween the start and the end time. + @hour_column = @conference.hours_from_start_time(@conf_start, conf_end) + end + + def events + @dates = @conference.start_date..@conference.end_date + + @events_schedules = @program.selected_event_schedules + @events_schedules = [] unless @events_schedules + + @unscheduled_events = @program.events.unscheduled(@program.selected_schedule.id) + + day = @conference.current_conference_day + @tag = day.strftime('%Y-%m-%d') if day + end + + private + + def respond_to_options + respond_to do |format| + format.html { head :ok } + end if request.options? + end +end diff --git a/app/models/email_settings.rb b/app/models/email_settings.rb index c27ea46e..c9632932 100644 --- a/app/models/email_settings.rb +++ b/app/models/email_settings.rb @@ -13,7 +13,7 @@ class EmailSettings < ActiveRecord::Base 'conference_splash_link' => Rails.application.routes.url_helpers.conference_url( conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')), - 'schedule_link' => Rails.application.routes.url_helpers.schedule_conference_url( + 'schedule_link' => Rails.application.routes.url_helpers.conference_schedule_url( conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')) } diff --git a/app/views/admin/commercials/index.html.haml b/app/views/admin/commercials/index.html.haml index 97efe401..5534ad03 100644 --- a/app/views/admin/commercials/index.html.haml +++ b/app/views/admin/commercials/index.html.haml @@ -4,7 +4,7 @@ %h1 Commercials %p.text-muted Conference commercials will be displayed on the events in the - = link_to "schedule,", schedule_conference_path(@conference.short_title) + = link_to "schedule,", conference_schedule_path(@conference.short_title) if the event speaker didn't add an event commercial. - if can? :create, @conference.commercials.new .row diff --git a/app/views/conference/_conference_details.html.haml b/app/views/conference/_conference_details.html.haml index d7a2e02b..40d04fb5 100644 --- a/app/views/conference/_conference_details.html.haml +++ b/app/views/conference/_conference_details.html.haml @@ -22,7 +22,7 @@ - if conference.splashpage && conference.splashpage.public = link_to "View Conference", conference_path(conference.short_title), :class =>"btn btn-default" - if conference.program and conference.program.schedule_public - = link_to "Schedule", schedule_conference_path(conference.short_title), :class =>"btn btn-default" + = link_to "Schedule", conference_schedule_path(conference.short_title), :class =>"btn btn-default" - if conference.registration_open? - if conference.user_registered?(current_user) = link_to "My Registration", conference_conference_registration_path(conference.short_title), :class =>"btn btn-default" diff --git a/app/views/conference/_schedule_splashpage.html.haml b/app/views/conference/_schedule_splashpage.html.haml index 12e50588..af23f8d7 100644 --- a/app/views/conference/_schedule_splashpage.html.haml +++ b/app/views/conference/_schedule_splashpage.html.haml @@ -22,7 +22,7 @@ .row .col-md-12 %p.cta-button.text-center - = link_to(schedule_conference_path(@conference.short_title), class: 'btn btn-default btn-lg') do + = link_to(conference_schedule_path(@conference.short_title), class: 'btn btn-default btn-lg') do Full Schedule diff --git a/app/views/proposal/show.html.haml b/app/views/proposal/show.html.haml index 501b22e2..4537450f 100644 --- a/app/views/proposal/show.html.haml +++ b/app/views/proposal/show.html.haml @@ -13,7 +13,7 @@ - if can? :edit, @event = link_to "Edit", edit_conference_program_proposal_path(@conference.short_title, @event), :class => "btn btn-mini btn-primary" - if can? :schedule, @conference - = link_to "Schedule", schedule_conference_path(@conference.short_title), :class =>"btn btn-success" + = link_to "Schedule", conference_schedule_path(@conference.short_title), :class =>"btn btn-success" - if @event.state == 'canceled' || @event.state == 'withdrawn' %span.label.label-danger CANCELED diff --git a/app/views/conference/_carousel.html.haml b/app/views/schedules/_carousel.html.haml similarity index 100% rename from app/views/conference/_carousel.html.haml rename to app/views/schedules/_carousel.html.haml diff --git a/app/views/conference/_event.html.haml b/app/views/schedules/_event.html.haml similarity index 100% rename from app/views/conference/_event.html.haml rename to app/views/schedules/_event.html.haml diff --git a/app/views/conference/_schedule.html.haml b/app/views/schedules/_schedule.html.haml similarity index 100% rename from app/views/conference/_schedule.html.haml rename to app/views/schedules/_schedule.html.haml diff --git a/app/views/conference/_schedule_item.html.haml b/app/views/schedules/_schedule_item.html.haml similarity index 100% rename from app/views/conference/_schedule_item.html.haml rename to app/views/schedules/_schedule_item.html.haml diff --git a/app/views/conference/_schedule_tabs.html.haml b/app/views/schedules/_schedule_tabs.html.haml similarity index 63% rename from app/views/conference/_schedule_tabs.html.haml rename to app/views/schedules/_schedule_tabs.html.haml index 6ca529b3..0317f8bc 100644 --- a/app/views/conference/_schedule_tabs.html.haml +++ b/app/views/schedules/_schedule_tabs.html.haml @@ -2,6 +2,6 @@ / Nav tabs %ul.nav.nav-tabs{ role: "tablist" } %li{ class: "schedule #{ 'active' if active == 'schedule' }", role: "presentation" } - = link_to('Schedule', schedule_conference_path(@conference.short_title)) + = link_to('Schedule', conference_schedule_path(@conference.short_title)) %li{ class: "program #{ 'active' if active == 'program' }", role: "presentation" } - = link_to('All events', events_conference_path(@conference.short_title)) + = link_to('All events', events_conference_schedule_path(@conference.short_title)) diff --git a/app/views/conference/events.html.haml b/app/views/schedules/events.html.haml similarity index 100% rename from app/views/conference/events.html.haml rename to app/views/schedules/events.html.haml diff --git a/app/views/conference/schedule.html.haml b/app/views/schedules/show.html.haml similarity index 100% rename from app/views/conference/schedule.html.haml rename to app/views/schedules/show.html.haml diff --git a/app/views/conference/schedule.xml.haml b/app/views/schedules/show.xml.haml similarity index 100% rename from app/views/conference/schedule.xml.haml rename to app/views/schedules/show.xml.haml diff --git a/config/routes.rb b/config/routes.rb index dff245e5..b6eee852 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -112,10 +112,10 @@ Osem::Application.routes.draw do resources :tickets, only: [:index] resources :ticket_purchases, only: [:create, :destroy] resource :subscriptions, only: [:create, :destroy] - - member do - get :schedule - get :events + resource :schedule, only: [:show] do + member do + get :events + end end end diff --git a/spec/controllers/conference_controller_spec.rb b/spec/controllers/conference_controller_spec.rb index 59437f8c..493fcb42 100644 --- a/spec/controllers/conference_controller_spec.rb +++ b/spec/controllers/conference_controller_spec.rb @@ -26,29 +26,6 @@ describe ConferenceController do end end - describe 'GET #schedule' 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 :schedule, id: conference.short_title, format: :xml - end - - it 'assigns variables' do - expect(assigns(:conference)).to eq conference - expect(assigns(:events_xml)).to eq conference.selected_event_schedules.map(&:event) - .group_by{ |event| event.scheduled_start_time.to_date } - end - - it 'renders successfully' do - expect(response).to be_success - end - end - end - describe 'OPTIONS #index' do it 'Response code is 200' do process :index, 'OPTIONS' diff --git a/spec/controllers/schedules_controller_spec.rb b/spec/controllers/schedules_controller_spec.rb new file mode 100644 index 00000000..35c3603a --- /dev/null +++ b/spec/controllers/schedules_controller_spec.rb @@ -0,0 +1,28 @@ +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, 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.selected_event_schedules.map(&:event) + .group_by{ |event| event.scheduled_start_time.to_date } + end + + it 'renders successfully' do + expect(response).to be_success + end + end + end +end