Merge d425349bdd into eb9d799f23
This commit is contained in:
commit
4a624f10eb
6 changed files with 73 additions and 3 deletions
|
|
@ -2,7 +2,7 @@ class ConferencesController < ApplicationController
|
|||
protect_from_forgery with: :null_session
|
||||
before_action :respond_to_options
|
||||
load_and_authorize_resource find_by: :short_title
|
||||
load_resource :program, through: :conference, singleton: true, except: :index
|
||||
load_resource :program, through: :conference, singleton: true, except: [:index, :current]
|
||||
|
||||
def index
|
||||
@current = Conference.where('end_date >= ?', Date.current).reorder(start_date: :asc)
|
||||
|
|
@ -11,6 +11,12 @@ class ConferencesController < ApplicationController
|
|||
|
||||
def show; end
|
||||
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
def respond_to_options
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class Ability
|
|||
|
||||
# Abilities for not signed in users (guests)
|
||||
def not_signed_in
|
||||
can [:index], Conference
|
||||
can [:index, :current], Conference
|
||||
can [:show], Conference do |conference|
|
||||
conference.splashpage && conference.splashpage.public == true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
require 'root_route_constraint'
|
||||
Osem::Application.routes.draw do
|
||||
|
||||
if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
|
||||
|
|
@ -152,6 +153,8 @@ Osem::Application.routes.draw do
|
|||
end
|
||||
|
||||
get '/admin' => redirect('/admin/conferences')
|
||||
|
||||
constraints RootRouteConstraint.new do
|
||||
get '/' => 'conferences#current'
|
||||
end
|
||||
root to: 'conferences#index', via: [:get, :options]
|
||||
end
|
||||
|
|
|
|||
16
lib/root_route_constraint.rb
Normal file
16
lib/root_route_constraint.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
class RootRouteConstraint
|
||||
def initialize
|
||||
@current = Conference.where('start_date <= ? AND end_date >= ?', Date.current, Date.current)
|
||||
@current = Conference.where('start_date = ?', Date.current + 1) if @current.blank?
|
||||
end
|
||||
|
||||
##
|
||||
# Checks if only one conference is live and has a public splashpage
|
||||
# If any conference is live it checks how many live conferences are there
|
||||
# ====Returns
|
||||
# * +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?(*)
|
||||
@current.present? && @current.first.splashpage.present? && @current.count == 1 && @current.first.splashpage.public?
|
||||
end
|
||||
end
|
||||
|
|
@ -26,6 +26,13 @@ describe ConferencesController do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'GET #current' do
|
||||
it 'redirects to first conference splashpage' do
|
||||
get :current
|
||||
expect(response).to redirect_to(conference_path(Conference.first.short_title))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'OPTIONS #index' do
|
||||
it 'Response code is 200' do
|
||||
process :index, 'OPTIONS'
|
||||
|
|
|
|||
38
spec/lib/root_route_constraint_spec.rb
Normal file
38
spec/lib/root_route_constraint_spec.rb
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe RootRouteConstraint do
|
||||
describe '#matches?' do
|
||||
|
||||
it 'returns false, if no conference is live' do
|
||||
constraint = RootRouteConstraint.new
|
||||
expect(constraint.matches?).to eq false
|
||||
end
|
||||
|
||||
it 'returns false, when one conference is live but no splashpage' do
|
||||
create(:conference)
|
||||
constraint = RootRouteConstraint.new
|
||||
expect(constraint.matches?).to eq false
|
||||
end
|
||||
|
||||
it 'returns false, when one conference is live but no public splashpage' do
|
||||
conference = create(:full_conference)
|
||||
conference.splashpage.public = false
|
||||
conference.splashpage.save
|
||||
constraint = RootRouteConstraint.new
|
||||
expect(constraint.matches?).to eq false
|
||||
end
|
||||
|
||||
it 'returns true, when one conference is live and has public splashpage' do
|
||||
create(:full_conference)
|
||||
constraint = RootRouteConstraint.new
|
||||
expect(constraint.matches?).to eq true
|
||||
end
|
||||
|
||||
it 'returns false, if more than one conference is live' do
|
||||
create(:full_conference)
|
||||
create(:full_conference)
|
||||
constraint = RootRouteConstraint.new
|
||||
expect(constraint.matches?).to eq false
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue