From 2b94ba02818d818e2fc35ccc788f0eb7f678e284 Mon Sep 17 00:00:00 2001 From: Gopesh Tulsyan Date: Tue, 17 Jun 2014 00:47:49 +0530 Subject: [PATCH] Adds routing error check in conference#show Adds make_conference_public to conference factory Added test --- app/controllers/application_controller.rb | 4 ++++ app/controllers/conference_controller.rb | 1 + .../controllers/conference_controller_spec.rb | 24 +++++++++++++------ spec/factories/conferences.rb | 1 + 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5e4ca356..42419769 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -72,4 +72,8 @@ class ApplicationController < ActionController::Base redirect_to root_path, :alert => exception.message end helper_method :organizer_or_admin? + + def not_found + raise ActionController::RoutingError.new('Not Found') + end end diff --git a/app/controllers/conference_controller.rb b/app/controllers/conference_controller.rb index 7a872c26..2bfeee3c 100644 --- a/app/controllers/conference_controller.rb +++ b/app/controllers/conference_controller.rb @@ -1,5 +1,6 @@ class ConferenceController < ApplicationController def show @conference = Conference.find_by_short_title(params[:id]) + not_found unless @conference.make_conference_public? end end diff --git a/spec/controllers/conference_controller_spec.rb b/spec/controllers/conference_controller_spec.rb index 15ff4989..b6ad2b80 100644 --- a/spec/controllers/conference_controller_spec.rb +++ b/spec/controllers/conference_controller_spec.rb @@ -3,14 +3,24 @@ require 'spec_helper' describe ConferenceController do let(:conference) { create(:conference) } describe 'GET #show' do - it 'assigns the requested conference to conference' do - get :show, id: conference.short_title - expect(assigns(:conference)).to eq conference - end + context 'conference made public' do + it 'assigns the requested conference to conference' do + get :show, id: conference.short_title + expect(assigns(:conference)).to eq conference + end - it 'renders the show template' do - get :show, id: conference.short_title - expect(response).to render_template :show + it 'renders the show template' do + get :show, id: conference.short_title + expect(response).to render_template :show + end + end + context 'conference is not public' do + it 'raises routing error' do + # rendered as 404 NOT FOUND in production environment + conference.update_attribute(:make_conference_public, false) + expect { get :show, id: conference.short_title }. + to raise_error(ActionController::RoutingError) + end end end end diff --git a/spec/factories/conferences.rb b/spec/factories/conferences.rb index 47596648..3b07782c 100644 --- a/spec/factories/conferences.rb +++ b/spec/factories/conferences.rb @@ -9,6 +9,7 @@ FactoryGirl.define do contact_email 'admin@example.com' start_date Date.today end_date Date.tomorrow + make_conference_public true venue end end