From 23c68211f01aa3958cf32303af48c45807ae9377 Mon Sep 17 00:00:00 2001 From: Gopesh Tulsyan Date: Sun, 3 Aug 2014 11:27:54 +0530 Subject: [PATCH] Redirect to root path if splash is not public --- app/controllers/conference_controller.rb | 2 +- .../controllers/conference_controller_spec.rb | 26 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/controllers/conference_controller.rb b/app/controllers/conference_controller.rb index b3f6dae2..04e128b0 100644 --- a/app/controllers/conference_controller.rb +++ b/app/controllers/conference_controller.rb @@ -1,7 +1,7 @@ class ConferenceController < ApplicationController def show @conference = Conference.find_by_short_title(params[:id]) - not_found unless @conference.make_conference_public? + redirect_to root_path, notice: "Conference not ready yet!!" unless @conference.make_conference_public? end def gallery_photos diff --git a/spec/controllers/conference_controller_spec.rb b/spec/controllers/conference_controller_spec.rb index b6ad2b80..23454ec5 100644 --- a/spec/controllers/conference_controller_spec.rb +++ b/spec/controllers/conference_controller_spec.rb @@ -15,11 +15,27 @@ describe ConferenceController do 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) + before(:each) { conference.update_attribute(:make_conference_public, false) } + + it 'redirects to root path' do + get :show, id: conference.short_title + expect(response).to redirect_to root_path + end + + it 'renders flash saying conference not ready' do + get :show, id: conference.short_title + expect(flash[:notice]).to eq("Conference not ready yet!!") + end + end + context 'gallery photos for splash' do + it 'return conference photos' do + xhr :get, :gallery_photos, id: conference.short_title + expect(assigns(:photos)).to eq conference.photos + end + + it 'renders photos template' do + xhr :get, :gallery_photos, id: conference.short_title + expect(response).to render_template :photos end end end