aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--config/environment.rb1
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb12
-rw-r--r--spec/controllers/general_controller_spec.rb21
-rw-r--r--spec/controllers/public_body_controller_spec.rb4
5 files changed, 31 insertions, 9 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index ba1cf4900..2918f39c0 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -42,7 +42,7 @@ class ApplicationController < ActionController::Base
end
def set_gettext_locale
- requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE']
+ requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] || I18n.default_locale
session[:locale] = FastGettext.set_locale(requested_locale)
end
diff --git a/config/environment.rb b/config/environment.rb
index a40c2df4e..17a16efed 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -122,6 +122,7 @@ else
end
FastGettext.default_available_locales = available_locales
+I18n.locale = default_locale
I18n.available_locales = available_locales
I18n.default_locale = default_locale
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
index 6b88fe39d..357564211 100644
--- a/spec/controllers/admin_public_body_controller_spec.rb
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -110,27 +110,27 @@ describe AdminPublicBodyController, "when administering public bodies with i18n"
end
it "creates a new public body" do
- I18n.locale = :es
+ I18n.default_locale = :es
PublicBody.count.should == 2
post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } }
PublicBody.count.should == 3
- I18n.locale = :en
+ I18n.default_locale = :en
end
it "edits a public body" do
- I18n.locale = :es
+ I18n.default_locale = :es
get :edit, {:id => 3, :locale => :es}
response.body.should include('Baguette')
- I18n.locale = :en
+ I18n.default_locale = :en
end
it "saves edits to a public body" do
- I18n.locale = :es
+ I18n.default_locale = :es
pb = PublicBody.find(id=3)
pb.name.should == "El Department for Humpadinking"
post :update, { :id => 3, :public_body => { :name => "Renamed", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' }}
response.flash[:notice].should include('successful')
- I18n.locale = :en
+ I18n.default_locale = :en
pb = PublicBody.find(public_bodies(:humpadink_public_body).id)
PublicBody.with_locale(:es) do
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 619635eea..63ad6873c 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -17,6 +17,27 @@ describe GeneralController, "when searching" do
response.should be_success
end
+ it "should render the front page with default language" do
+ get :frontpage
+ response.should have_tag('html[lang="en"]')
+ end
+
+ it "should render the front page with default language" do
+ old_default_locale = I18n.default_locale
+ I18n.default_locale = "es"
+ get :frontpage
+ response.should have_tag('html[lang="es"]')
+ I18n.default_locale = old_default_locale
+ end
+
+ it "should render the front page with browser-selected language" do
+ accept_language = "es-ES,en-GB,en-US;q=0.8,en;q=0.6"
+ request.env['HTTP_ACCEPT_LANGUAGE'] = accept_language
+ get :frontpage
+ response.should have_tag('html[lang="es"]')
+ request.env['HTTP_ACCEPT_LANGUAGE'] = nil
+ end
+
it "doesn't raise an error when there's no user matching the one in the session" do
session[:user_id] = 999
get :frontpage
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index d15482e51..0050678d2 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -72,13 +72,13 @@ describe PublicBodyController, "when listing bodies" do
end
it "should list bodies in alphabetical order with different locale" do
- I18n.locale = :es
+ I18n.default_locale = :es
get :list
response.should render_template('list')
assigns[:public_bodies].should == [ public_bodies(:geraldine_public_body), public_bodies(:humpadink_public_body) ]
assigns[:tag].should == "all"
assigns[:description].should == "all"
- I18n.locale = :en
+ I18n.default_locale = :en
end
it "should list a tagged thing on the appropriate list page, and others on the other page, and all still on the all page" do