Avoid accidental locale changes in tests

This commit is contained in:
Tom Hughes 2021-06-22 19:05:55 +01:00
parent 63e4a89323
commit f6818bb2ed
2 changed files with 134 additions and 120 deletions

View file

@ -2,6 +2,7 @@ require "test_helper"
class PageLocaleTest < ActionDispatch::IntegrationTest
def test_defaulting
I18n.with_locale "en" do
user = create(:user, :languages => [])
get "/login"
@ -17,8 +18,10 @@ class PageLocaleTest < ActionDispatch::IntegrationTest
assert_equal %w[fr en], User.find(user.id).languages
assert_select "html[lang=?]", "fr"
end
end
def test_override
I18n.with_locale "en" do
user = create(:user, :languages => ["de"])
get "/diary"
@ -38,4 +41,5 @@ class PageLocaleTest < ActionDispatch::IntegrationTest
get "/diary", :params => { :locale => "fr" }
assert_select "html[lang=?]", "fr"
end
end
end

View file

@ -18,6 +18,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
end
def test_create_user_form
I18n.with_locale "en" do
I18n.available_locales.each do |locale|
reset!
get "/user/new", :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
@ -26,8 +27,10 @@ class UserCreationTest < ActionDispatch::IntegrationTest
assert_template "users/new"
end
end
end
def test_user_create_submit_duplicate_email
I18n.with_locale "en" do
Locale.available.each do |locale|
dup_email = create(:user).email
display_name = "#{locale}_new_tester"
@ -52,8 +55,10 @@ class UserCreationTest < ActionDispatch::IntegrationTest
assert_no_missing_translations
end
end
end
def test_user_create_submit_duplicate_username
I18n.with_locale "en" do
I18n.available_locales.each do |locale|
dup_display_name = create(:user).display_name
email = "#{locale}_new_tester"
@ -76,8 +81,10 @@ class UserCreationTest < ActionDispatch::IntegrationTest
assert_no_missing_translations
end
end
end
def test_user_create_success
I18n.with_locale "en" do
I18n.available_locales.each do |locale|
new_email = "#{locale}newtester@osm.org"
display_name = "#{locale}_new_tester"
@ -122,8 +129,10 @@ class UserCreationTest < ActionDispatch::IntegrationTest
ActionMailer::Base.deliveries.clear
end
end
end
def test_user_create_no_tou_failure
I18n.with_locale "en" do
I18n.available_locales.each do |locale|
new_email = "#{locale}newtester@osm.org"
display_name = "#{locale}_new_tester"
@ -152,6 +161,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
ActionMailer::Base.deliveries.clear
end
end
end
# Check that the user can successfully recover their password
def test_lost_password_recovery_success