diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2011-08-08 13:02:03 +0100 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2011-08-08 14:57:01 +0100 |
commit | a3c00d25d1bf6dc9ef554a44809e732a96ec1533 (patch) | |
tree | 0b9f7dd0ad5cb48c458487e3fd28960146830a95 /spec/controllers | |
parent | 99548c87d201871a150e395c334e07149651996a (diff) |
Ensure we use sensible fallbacks for setting the default / initial locale for a user. (Partially) fixes #114
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/admin_public_body_controller_spec.rb | 12 | ||||
-rw-r--r-- | spec/controllers/general_controller_spec.rb | 21 | ||||
-rw-r--r-- | spec/controllers/public_body_controller_spec.rb | 4 |
3 files changed, 29 insertions, 8 deletions
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 |