From 536414284860c7bbe459bb9bda0ac2d361683d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sede=C3=B1o?= Date: Wed, 6 Dec 2017 23:45:52 +0100 Subject: [PATCH 1/2] If there are only one conference in the future and it has a public splashpage, redirect to it in conferences#index. fix #1259 --- app/controllers/conferences_controller.rb | 5 +++ .../conferences_controller_spec.rb | 36 +++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index f141529d..38d1b2b7 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -6,6 +6,11 @@ class ConferencesController < ApplicationController def index @current = Conference.where('end_date >= ?', Date.current).reorder(start_date: :asc) @antiquated = @conferences - @current + + redirect_to @current.first if @current.count == 1 and + @current.first.splashpage and + @current.first.splashpage.public==true + end def show diff --git a/spec/controllers/conferences_controller_spec.rb b/spec/controllers/conferences_controller_spec.rb index cdbebf9f..8f495974 100644 --- a/spec/controllers/conferences_controller_spec.rb +++ b/spec/controllers/conferences_controller_spec.rb @@ -6,9 +6,39 @@ describe ConferencesController do let(:room) { create(:room, venue: conference.venue) } describe 'GET #index' do - it 'Response code is 200' do - get :index - expect(response.response_code).to eq(200) + context 'without conference' do + it 'Response code is 200' do + conference.destroy! + get :index + expect(response.response_code).to eq(200) + end + end + + context 'with one next conference' do + describe 'with splashpage' do + it 'Response code is 200 when is not public' do + current = Conference.first + current.splashpage.public = false + current.splashpage.save + get :index + expect(response.response_code).to eq(200) + end + it 'Response code is 302 when is public' do + get :index + expect(response.response_code).to eq(302) + end + it 'Redirect to conference#show' do + get :index + expect(response).to redirect_to(conference_path(conference)) + end + end + describe 'without splashpage' do + it 'Response code is 200' do + conference.splashpage.destroy! + get :index + expect(response.response_code).to eq(200) + end + end end end From f3358ec20ba9dd9a21bad29361a67f53ea6f0bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sede=C3=B1o?= Date: Thu, 7 Dec 2017 11:28:39 +0100 Subject: [PATCH 2/2] Fix incorrect use in if --- app/controllers/conferences_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index 38d1b2b7..be06341b 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -9,7 +9,7 @@ class ConferencesController < ApplicationController redirect_to @current.first if @current.count == 1 and @current.first.splashpage and - @current.first.splashpage.public==true + @current.first.splashpage.public end