diff options
-rw-r--r-- | app/views/general/_before_body_end.rhtml | 2 | ||||
-rw-r--r-- | config/environment.rb | 4 | ||||
-rw-r--r-- | config/routes.rb | 2 | ||||
-rw-r--r-- | doc/INSTALL.md | 2 | ||||
-rw-r--r-- | lib/routing_filters.rb | 9 | ||||
-rw-r--r-- | spec/controllers/general_controller_spec.rb | 23 | ||||
-rw-r--r-- | spec/controllers/request_game_controller_spec.rb | 2 |
7 files changed, 40 insertions, 4 deletions
diff --git a/app/views/general/_before_body_end.rhtml b/app/views/general/_before_body_end.rhtml index 4374a3f28..42206b021 100644 --- a/app/views/general/_before_body_end.rhtml +++ b/app/views/general/_before_body_end.rhtml @@ -1 +1 @@ -<!-- TO DO: add here Analytics Scripts (Google or something else) --> +<%# This file may be overwritten by a local theme, to add analytics code %> diff --git a/config/environment.rb b/config/environment.rb index 86c66ad18..ec6a4096f 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -82,6 +82,10 @@ Rails::Initializer.run do |config| # Make Active Record use UTC-base instead of local time config.active_record.default_timezone = :utc + config.after_initialize do + require 'routing_filters.rb' + end + # See Rails::Configuration for more options ENV['RECAPTCHA_PUBLIC_KEY'] = MySociety::Config::get("RECAPTCHA_PUBLIC_KEY", 'x'); ENV['RECAPTCHA_PRIVATE_KEY'] = MySociety::Config::get("RECAPTCHA_PRIVATE_KEY", 'x'); diff --git a/config/routes.rb b/config/routes.rb index 451c13e3b..6dfd03634 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -195,8 +195,8 @@ ActionController::Routing::Routes.draw do |map| rule.admin_rule_update '/admin/censor/update', :action => 'update' rule.admin_rule_destroy '/admin/censor/destroy/:censor_rule_id', :action => 'destroy' end - # map.filter('locale') + # map.filter('conditionallyprependlocale') # Allow downloading Web Service WSDL as a file with an extension # instead of a file named 'wsdl' diff --git a/doc/INSTALL.md b/doc/INSTALL.md index c729a0737..5283f46e8 100644 --- a/doc/INSTALL.md +++ b/doc/INSTALL.md @@ -18,7 +18,7 @@ First, get hold of the source code from github: git clone https://github.com/sebbacon/alaveteli.git -(You may need to install git first, e.g. with `sudo apt-get install git-code`) +(You may need to install git first, e.g. with `sudo apt-get install git-core`) Now, in a terminal, navigate to the alaveteli folder where this install guide lives. diff --git a/lib/routing_filters.rb b/lib/routing_filters.rb new file mode 100644 index 000000000..cdb58e7c1 --- /dev/null +++ b/lib/routing_filters.rb @@ -0,0 +1,9 @@ +module RoutingFilter + class Conditionallyprependlocale < RoutingFilter::Locale + # Override core Locale filter not to prepend locale path segment + # when there's only one locale + def prepend_locale?(locale) + locale && I18n.available_locales.length > 1 && (self.class.include_default_locale? || !default_locale?(locale)) + end + end +end diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 6a48f142a..7807a5541 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -22,6 +22,29 @@ describe GeneralController, "when searching" do response.should redirect_to(:action => 'search', :combined => "mouse") # URL /search/:query end + describe "when using different locale settings" do + home_link_regex = /href=".*\/en"/ + it "should generate URLs with a locale prepended when there's more than one locale set" do + ActionController::Routing::Routes.add_filters(['conditionallyprependlocale']) + get :frontpage + response.should have_text(home_link_regex) + end + + it "should generate URLs without a locale prepended when there's only one locale set" do + ActionController::Routing::Routes.add_filters(['conditionallyprependlocale']) + old_available_locales = FastGettext.default_available_locales + available_locales = ['en'] + FastGettext.default_available_locales = available_locales + I18n.available_locales = available_locales + + get :frontpage + response.should_not have_text(home_link_regex) + + FastGettext.default_available_locales = old_available_locales + I18n.available_locales = old_available_locales + end + end + describe 'when using xapian search' do # rebuild xapian index after fixtures loaded diff --git a/spec/controllers/request_game_controller_spec.rb b/spec/controllers/request_game_controller_spec.rb index eb05045e9..ce507fad1 100644 --- a/spec/controllers/request_game_controller_spec.rb +++ b/spec/controllers/request_game_controller_spec.rb @@ -4,7 +4,7 @@ describe RequestGameController, "when playing the game" do fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages # all needed as integrating views - it "should show the game homepage with the correct urls" do + it "should show the game homepage" do get :play response.should render_template('play') end |