X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/970e1a99d7dce64f0631e88c5b9f060fb48d75fe..295f5d6111ed5e1762283487d8bc4d0b01bf4a77:/test/integration/page_locale_test.rb?ds=sidebyside diff --git a/test/integration/page_locale_test.rb b/test/integration/page_locale_test.rb index c95af86ab..6f6d7779f 100644 --- a/test/integration/page_locale_test.rb +++ b/test/integration/page_locale_test.rb @@ -1,46 +1,45 @@ require "test_helper" class PageLocaleTest < ActionDispatch::IntegrationTest - fixtures :users - - def setup - I18n.locale = "en" - stub_hostip_requests - end - - def teardown - I18n.locale = "en" - end - def test_defaulting - user = users(:second_public_user) - - post_via_redirect "/login", :username => user.email, :password => "test" - - get "/diary/new", {} - assert_equal [], User.find(user.id).languages - assert_select "html[lang=?]", "en" - - get "/diary/new", {}, { "HTTP_ACCEPT_LANGUAGE" => "fr, en" } - assert_equal %w(fr en), User.find(user.id).languages - assert_select "html[lang=?]", "fr" + I18n.with_locale "en" do + user = create(:user, :languages => []) + + get "/login" + follow_redirect! + post "/login", :params => { :username => user.email, :password => "test" } + follow_redirect! + + get "/diary/new" + assert_empty User.find(user.id).languages + assert_select "html[lang=?]", "en" + + get "/diary/new", :headers => { "HTTP_ACCEPT_LANGUAGE" => "fr, en" } + assert_equal %w[fr en], User.find(user.id).languages + assert_select "html[lang=?]", "fr" + end end def test_override - user = users(:german_user) + I18n.with_locale "en" do + user = create(:user, :languages => ["de"]) - get "/diary" - assert_select "html[lang=?]", "en" + get "/diary" + assert_select "html[lang=?]", "en" - get "/diary", :locale => "es" - assert_select "html[lang=?]", "es" + get "/diary", :params => { :locale => "es" } + assert_select "html[lang=?]", "es" - post_via_redirect "/login", :username => user.email, :password => "test" + get "/login" + follow_redirect! + post "/login", :params => { :username => user.email, :password => "test" } + follow_redirect! - get "/diary" - assert_select "html[lang=?]", "de" + get "/diary" + assert_select "html[lang=?]", "de" - get "/diary", :locale => "fr" - assert_select "html[lang=?]", "fr" + get "/diary", :params => { :locale => "fr" } + assert_select "html[lang=?]", "fr" + end end end