From e65ca7fb58039a2316bf1e794ecd073095e21c05 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Fri, 14 Nov 2014 17:24:24 +0100 Subject: [PATCH] Get rid of the home controller --- app/controllers/conference_controller.rb | 14 ++++++++ app/controllers/home_controller.rb | 15 --------- app/models/ability.rb | 2 +- app/models/conference.rb | 2 ++ .../_conference_details.html.haml | 0 app/views/conference/index.html.haml | 29 +++++++++++++++++ app/views/home/index.html.haml | 5 --- config/routes.rb | 4 +-- .../controllers/conference_controller_spec.rb | 15 +++++++++ spec/controllers/home_controller_spec.rb | 32 ------------------- .../index.html.haml_spec.rb | 2 +- 11 files changed, 64 insertions(+), 56 deletions(-) delete mode 100644 app/controllers/home_controller.rb rename app/views/{home => conference}/_conference_details.html.haml (100%) create mode 100644 app/views/conference/index.html.haml delete mode 100644 app/views/home/index.html.haml delete mode 100644 spec/controllers/home_controller_spec.rb rename spec/views/{home => conference}/index.html.haml_spec.rb (91%) diff --git a/app/controllers/conference_controller.rb b/app/controllers/conference_controller.rb index fe7e0622..969b77dd 100644 --- a/app/controllers/conference_controller.rb +++ b/app/controllers/conference_controller.rb @@ -1,6 +1,12 @@ class ConferenceController < ApplicationController + before_filter :respond_to_options load_and_authorize_resource find_by: :short_title + def index + @current = Conference.where('end_date >= ?', Date.current).order('start_date ASC') + @antiquated = @conferences - @current + end + def show @keynote_speakers = @conference.keynote_speakers end @@ -9,4 +15,12 @@ class ConferenceController < ApplicationController @photos = @conference.photos render 'photos', formats: [:js] end + + private + + def respond_to_options + respond_to do |format| + format.html { head :ok } + end if request.options? + end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb deleted file mode 100644 index 8a53dfcb..00000000 --- a/app/controllers/home_controller.rb +++ /dev/null @@ -1,15 +0,0 @@ -class HomeController < ApplicationController - before_filter :respond_to_options - skip_authorization_check - - def index - @today = Date.current - @current = Conference.where('end_date >= ?', @today).order('start_date ASC') - end - - def respond_to_options - respond_to do |format| - format.html { head :ok } - end if request.options? - end -end diff --git a/app/models/ability.rb b/app/models/ability.rb index 1ccc55a6..ba6f1093 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -112,7 +112,7 @@ class Ability def guest ## Abilities for everyone, even guests (not logged in users) - can [:show, :gallery_photos], Conference do |conference| + can [:index, :show, :gallery_photos], Conference do |conference| conference.splashpage && conference.splashpage.public == true end diff --git a/app/models/conference.rb b/app/models/conference.rb index fec05c77..4d732f95 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -6,6 +6,8 @@ class Conference < ActiveRecord::Base serialize :events_per_week, Hash resourcify # Needed to call 'Conference.with_role' in /models/ability.rb + default_scope { order('start_date DESC') } + attr_accessible :title, :short_title, :timezone, :html_export_path, :start_date, :end_date, :rooms_attributes, :tracks_attributes, :dietary_choices_attributes, :use_dietary_choices, diff --git a/app/views/home/_conference_details.html.haml b/app/views/conference/_conference_details.html.haml similarity index 100% rename from app/views/home/_conference_details.html.haml rename to app/views/conference/_conference_details.html.haml diff --git a/app/views/conference/index.html.haml b/app/views/conference/index.html.haml new file mode 100644 index 00000000..8e1b05f0 --- /dev/null +++ b/app/views/conference/index.html.haml @@ -0,0 +1,29 @@ +.container + .row + .col-md-12 + .page-header + %h2 Upcoming Conferences + - @current.each do |conference| + = render :partial => "conference_details", :locals => {:conference => conference} + -if @antiquated and @antiquated.any? + .row + .col-md-12 + %p.text-right + %button{:type=>"button", :class=>"btn btn-link btn-sm", "data-toggle"=>"collapse", "data-target"=>"#antiquated", "aria-expanded"=>"true", "aria-controls"=>"antiquated"} + Older conferences + = "(#{@antiquated.count})" + %i.fa.fa-chevron-right + %i.fa.fa-chevron-down{:style => 'display: none'} + #antiquated.collapse + - @antiquated.each do |conference| + = render :partial => "conference_details", :locals => {:conference => conference} + +:javascript + $('#antiquated').on('hidden.bs.collapse', function () { + $( ".fa-chevron-down" ).hide(); + $( ".fa-chevron-right" ).show(); + }) + $('#antiquated').on('shown.bs.collapse', function () { + $( ".fa-chevron-down" ).show(); + $( ".fa-chevron-right" ).hide(); + }) diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml deleted file mode 100644 index 2df959ce..00000000 --- a/app/views/home/index.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -.row - .col-md-12.page-header - %h2.text-center Upcoming Conferences -- @current.each do |conference| - = render :partial => "conference_details", :locals => {:conference => conference} diff --git a/config/routes.rb b/config/routes.rb index 148918d6..1886fdc0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -96,7 +96,7 @@ Osem::Application.routes.draw do end end - resources :conference, only: [:show] do + resources :conference, only: [:index, :show] do resources :proposal do resources :commercials, except: [:show, :index] resources :event_attachment, controller: 'event_attachments' @@ -138,5 +138,5 @@ Osem::Application.routes.draw do get '/admin' => redirect('/admin/conference') - root to: 'home#index', via: [:get, :options] + root to: 'conference#index', via: [:get, :options] end diff --git a/spec/controllers/conference_controller_spec.rb b/spec/controllers/conference_controller_spec.rb index b30cdcba..0dfb8c3e 100644 --- a/spec/controllers/conference_controller_spec.rb +++ b/spec/controllers/conference_controller_spec.rb @@ -3,6 +3,13 @@ require 'spec_helper' describe ConferenceController do let(:conference) { create(:conference, splashpage: create(:splashpage, public: true)) } + describe 'GET #index' do + it 'Response code is 200' do + get :index + expect(response.response_code).to eq(200) + end + end + describe 'GET #show' do context 'conference made public' do it 'assigns the requested conference to conference' do @@ -28,4 +35,12 @@ describe ConferenceController do end end end + + describe 'OPTIONS #index' do + it 'Response code is 200' do + process :index, 'OPTIONS' + expect(response.response_code).to eq(200) + end + end + end diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb deleted file mode 100644 index d66df460..00000000 --- a/spec/controllers/home_controller_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'spec_helper' - -describe HomeController do - let(:conference) { create(:conference) } - describe 'GET #index' do - it 'Response code is 200' do - get :index - expect(response.response_code).to eq(200) - end - - it 'Assigns conference' do - get :index - expect(assigns(:current)).to eq [conference] - end - - it 'Assigns only pending conferences' do - create(:conference, - end_date: Date.today - 7, - start_date: Date.today - 14) - get :index - expect(assigns(:current)).to eq [conference] - end - - end - - describe 'OPTIONS #index' do - it 'Response code is 200' do - process :index, 'OPTIONS' - expect(response.response_code).to eq(200) - end - end -end diff --git a/spec/views/home/index.html.haml_spec.rb b/spec/views/conference/index.html.haml_spec.rb similarity index 91% rename from spec/views/home/index.html.haml_spec.rb rename to spec/views/conference/index.html.haml_spec.rb index 2beff825..a08f664e 100644 --- a/spec/views/home/index.html.haml_spec.rb +++ b/spec/views/conference/index.html.haml_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'home/index' do +describe 'conference/index' do it 'renders _conference partial for each conference' do allow(view).to receive(:date_string).and_return('January 17 - 21 2014') assign(:current, [create(:conference), create(:conference)])