diff options
author | Louise Crow <louise.crow@gmail.com> | 2013-06-17 14:46:15 -0700 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2013-06-17 14:48:58 -0700 |
commit | 4a4169c606e0e26b905e11e1fc75c45268498112 (patch) | |
tree | 63ec3b6099638c0893c79c8320d259480e56f2d7 | |
parent | 64ae21945a69441ad6a58a1069417e7a56cc15f6 (diff) |
Explicitly set I18n.locale in set_gettext_locale in order to get Rails to expire the template cache and trigger a lookup.0.11.0.13hotfix/0.11.0.13
4 files changed, 31 insertions, 3 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a8ba52e4f..acf366bfb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -51,6 +51,9 @@ class ApplicationController < ActionController::Base anonymous_cache(24.hours) end + # This is an override of the method provided by gettext_i18n_rails - note the explicit + # setting of I18n.locale, required due to the I18nProxy used in Rails 3 to trigger the + # lookup_context and expire the template cache def set_gettext_locale if AlaveteliConfiguration::include_default_locale_in_urls == false params_locale = params[:locale] ? params[:locale] : I18n.default_locale @@ -63,7 +66,7 @@ class ApplicationController < ActionController::Base requested_locale = params_locale || session[:locale] || cookies[:locale] || I18n.default_locale end requested_locale = FastGettext.best_locale_in(requested_locale) - session[:locale] = FastGettext.set_locale(requested_locale) + session[:locale] = I18n.locale = FastGettext.set_locale(requested_locale) if !@user.nil? if @user.locale != requested_locale @user.locale = session[:locale] diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index 0f6f75eb9..c47e1abd3 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -1,8 +1,9 @@ +# -*- coding: utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe HelpController, "when using help" do render_views - + it "shows the about page" do get :about end @@ -12,7 +13,7 @@ describe HelpController, "when using help" do end it "sends a contact message" do - post :contact, { :contact => { + post :contact, { :contact => { :name => "Vinny Vanilli", :email => "vinny@localhost", :subject => "Why do I have such an ace name?", @@ -27,5 +28,27 @@ describe HelpController, "when using help" do deliveries.clear end + describe 'when requesting a page in a supported locale ' do + + before do + # Allow us to supply the locale manually + RoutingFilter.active = false + # Prepend our fixture templates + fixture_theme_path = File.join(Rails.root, 'spec', 'fixtures', 'theme_views', 'theme_one') + controller.prepend_view_path fixture_theme_path + end + + after do + RoutingFilter.active = true + end + + it 'should render the locale-specific template if available' do + get :contact, {:locale => 'es'} + response.body.should match('contáctenos theme one') + end + + end + + end diff --git a/spec/fixtures/theme_views/theme_one/help/contact.es.html.erb b/spec/fixtures/theme_views/theme_one/help/contact.es.html.erb new file mode 100644 index 000000000..a294c8aa1 --- /dev/null +++ b/spec/fixtures/theme_views/theme_one/help/contact.es.html.erb @@ -0,0 +1 @@ +contáctenos theme one diff --git a/spec/fixtures/theme_views/theme_one/help/contact.html.erb b/spec/fixtures/theme_views/theme_one/help/contact.html.erb new file mode 100644 index 000000000..428c7368d --- /dev/null +++ b/spec/fixtures/theme_views/theme_one/help/contact.html.erb @@ -0,0 +1 @@ +Contact us |