From d425349bdd209840cd78a0c60cba7b72bd3e7aa2 Mon Sep 17 00:00:00 2001 From: divyanshumehta Date: Sun, 16 Apr 2017 10:42:46 +0530 Subject: [PATCH] Redirect home to conference#show if only one conference live tommorow --- app/controllers/conferences_controller.rb | 1 + lib/root_route_constraint.rb | 9 +++------ spec/lib/root_route_constraint_spec.rb | 1 - 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index a9717296..dcb38eeb 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -13,6 +13,7 @@ class ConferencesController < ApplicationController def current current = Conference.where('start_date <= ? AND end_date >= ?', Date.current, Date.current).first + current = Conference.where('start_date = ?', Date.current + 1).first if current.blank? redirect_to conference_path(current.short_title) end diff --git a/lib/root_route_constraint.rb b/lib/root_route_constraint.rb index c957a18d..5aee9b7c 100644 --- a/lib/root_route_constraint.rb +++ b/lib/root_route_constraint.rb @@ -1,6 +1,7 @@ class RootRouteConstraint def initialize - @current = Conference.where('start_date <= ? AND end_date >= ?', Date.current, Date.current).reorder(start_date: :asc) + @current = Conference.where('start_date <= ? AND end_date >= ?', Date.current, Date.current) + @current = Conference.where('start_date = ?', Date.current + 1) if @current.blank? end ## @@ -10,10 +11,6 @@ class RootRouteConstraint # * +true+ -> only one conferene is live AND the conference has public splashpage # * +false+ -> no or more than one conferences are live or the only live conferece has no public splashpage def matches?(*) - if @current.present? && @current.first.splashpage.present? - @current.count == 1 && @current.first.splashpage.public? - else - false - end + @current.present? && @current.first.splashpage.present? && @current.count == 1 && @current.first.splashpage.public? end end diff --git a/spec/lib/root_route_constraint_spec.rb b/spec/lib/root_route_constraint_spec.rb index 338dbea0..ed9a5ac6 100644 --- a/spec/lib/root_route_constraint_spec.rb +++ b/spec/lib/root_route_constraint_spec.rb @@ -34,6 +34,5 @@ describe RootRouteConstraint do constraint = RootRouteConstraint.new expect(constraint.matches?).to eq false end - end end