diff --git a/Gemfile b/Gemfile index 2489bf6c..31e67e64 100644 --- a/Gemfile +++ b/Gemfile @@ -263,6 +263,8 @@ group :test do gem 'json-schema' # For using 'assigns' in tests gem 'rails-controller-testing' + # For managing the environment + gem 'climate_control' end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 65e2d3e0..47e31962 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -113,6 +113,7 @@ GEM railties (> 3.1) chronic (0.10.2) chunky_png (1.3.8) + climate_control (0.2.0) cliver (0.3.2) cloudinary (1.1.6) aws_cf_signer @@ -586,6 +587,7 @@ DEPENDENCIES carrierwave carrierwave-bombshelter chart-js-rails + climate_control cloudinary cocoon countable-rails (~> 0.0.1) diff --git a/config/routes.rb b/config/routes.rb index 4e2fca74..ce1881e0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -214,5 +214,9 @@ Osem::Application.routes.draw do get '/admin' => redirect('/admin/conferences') - root to: 'conferences#index', via: [:get, :options] + unless ENV['OSEM_ROOT_CONFERENCE'].blank? + root to: redirect("/conferences/#{ENV['OSEM_ROOT_CONFERENCE']}") + else + root to: 'conferences#index', via: [:get, :options] + end end diff --git a/dotenv.example b/dotenv.example index 6d8dd025..10b5680b 100644 --- a/dotenv.example +++ b/dotenv.example @@ -16,6 +16,9 @@ OSEM_HOSTNAME="localhost:3000" # The address OSEM uses for sending mails OSEM_EMAIL_ADDRESS="no-reply@localhost" +# (Optional) The Conference#short_title to redirect the root URL to +#OSEM_ROOT_CONFERENCE='' + # The api key for transifex.com. # See TRANSLATION.md for details OSEM_TRANSIFEX_APIKEY="" diff --git a/spec/routing/routing_spec.rb b/spec/routing/routing_spec.rb new file mode 100644 index 00000000..1875150f --- /dev/null +++ b/spec/routing/routing_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +feature 'Routing', type: :routing do + let(:conference) { create(:conference) } + + context 'the root URL' do + it 'routes to conferences#index' do + expect(get: '/').to route_to( + controller: 'conferences', + action: 'index' + ) + end + + # FIXME: this doesn't work due to routes being statically loaded + # See https://github.com/rspec/rspec-rails/issues/817 for example + # context 'with OSEM_ROOT_CONFERENCE set' do + # it 'redirects to the conference' do + # ClimateControl.modify OSEM_ROOT_CONFERENCE: conference.short_title do + # expect(get: '/').to route_to( + # controller: 'conferences', + # action: 'show', + # id: conference.short_title + # ) + # end + # end + # end + end +end