From 63e4a89323f4b0dba5e64b227f3e8508c94373b6 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 22 Jun 2021 18:34:15 +0100 Subject: [PATCH] Fix new ruboop warnings --- test/helpers/application_helper_test.rb | 20 ++---- test/helpers/browse_helper_test.rb | 62 ++++++++---------- test/helpers/browse_tags_helper_test.rb | 84 +++++++++++-------------- test/integration/page_locale_test.rb | 8 --- test/integration/user_creation_test.rb | 4 -- 5 files changed, 71 insertions(+), 107 deletions(-) diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 90fbaebc2..43e27c529 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -3,14 +3,6 @@ require "test_helper" class ApplicationHelperTest < ActionView::TestCase attr_accessor :current_user - def setup - I18n.locale = "en" - end - - def teardown - I18n.locale = "en" - end - def test_linkify %w[http://example.com/test ftp://example.com/test https://example.com/test].each do |link| text = "Test #{link} is made into a link" @@ -54,13 +46,13 @@ class ApplicationHelperTest < ActionView::TestCase assert_equal "rtl", dir params.delete(:dir) - I18n.locale = "he" + I18n.with_locale "he" do + assert_equal "rtl", dir - assert_equal "rtl", dir - - params[:dir] = "ltr" - assert_equal "ltr", dir - params.delete(:dir) + params[:dir] = "ltr" + assert_equal "ltr", dir + params.delete(:dir) + end end def test_friendly_date diff --git a/test/helpers/browse_helper_test.rb b/test/helpers/browse_helper_test.rb index 076975b09..a20e1703d 100644 --- a/test/helpers/browse_helper_test.rb +++ b/test/helpers/browse_helper_test.rb @@ -4,14 +4,6 @@ class BrowseHelperTest < ActionView::TestCase include ERB::Util include ApplicationHelper - def setup - I18n.locale = "en" - end - - def teardown - I18n.locale = "en" - end - def test_printable_name node = create(:node, :with_history, :version => 2) node_v1 = node.old_nodes.find_by(:version => 1) @@ -35,35 +27,35 @@ class BrowseHelperTest < ActionView::TestCase assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true) assert_dom_equal "3.1415926 (#{node_with_ref_without_name.id})", printable_name(node_with_ref_without_name) - I18n.locale = "pt" - - assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node) - assert_dom_equal "Nó teste (#{node.id})", printable_name(node) - assert_dom_equal "Nó teste (#{node.id})", printable_name(node_v2) - assert_dom_equal node.id.to_s, printable_name(node_v1) - assert_dom_equal "Nó teste (#{node.id}, v2)", printable_name(node_v2, :version => true) - assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true) - assert_dom_equal "3.1415926 (#{node_with_ref_without_name.id})", printable_name(node_with_ref_without_name) - - I18n.locale = "pt-BR" - - assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node) - assert_dom_equal "Nó teste (#{node.id})", printable_name(node) - assert_dom_equal "Nó teste (#{node.id})", printable_name(node_v2) - assert_dom_equal node.id.to_s, printable_name(node_v1) - assert_dom_equal "Nó teste (#{node.id}, v2)", printable_name(node_v2, :version => true) - assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true) - assert_dom_equal "3.1415926 (#{node_with_ref_without_name.id})", printable_name(node_with_ref_without_name) + I18n.with_locale "pt" do + assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node) + assert_dom_equal "Nó teste (#{node.id})", printable_name(node) + assert_dom_equal "Nó teste (#{node.id})", printable_name(node_v2) + assert_dom_equal node.id.to_s, printable_name(node_v1) + assert_dom_equal "Nó teste (#{node.id}, v2)", printable_name(node_v2, :version => true) + assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true) + assert_dom_equal "3.1415926 (#{node_with_ref_without_name.id})", printable_name(node_with_ref_without_name) + end - I18n.locale = "de" + I18n.with_locale "pt-BR" do + assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node) + assert_dom_equal "Nó teste (#{node.id})", printable_name(node) + assert_dom_equal "Nó teste (#{node.id})", printable_name(node_v2) + assert_dom_equal node.id.to_s, printable_name(node_v1) + assert_dom_equal "Nó teste (#{node.id}, v2)", printable_name(node_v2, :version => true) + assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true) + assert_dom_equal "3.1415926 (#{node_with_ref_without_name.id})", printable_name(node_with_ref_without_name) + end - assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node) - assert_dom_equal "Test Node (#{node.id})", printable_name(node) - assert_dom_equal "Test Node (#{node.id})", printable_name(node_v2) - assert_dom_equal node.id.to_s, printable_name(node_v1) - assert_dom_equal "Test Node (#{node.id}, v2)", printable_name(node_v2, :version => true) - assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true) - assert_dom_equal "3.1415926 (#{node_with_ref_without_name.id})", printable_name(node_with_ref_without_name) + I18n.with_locale "de" do + assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node) + assert_dom_equal "Test Node (#{node.id})", printable_name(node) + assert_dom_equal "Test Node (#{node.id})", printable_name(node_v2) + assert_dom_equal node.id.to_s, printable_name(node_v1) + assert_dom_equal "Test Node (#{node.id}, v2)", printable_name(node_v2, :version => true) + assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true) + assert_dom_equal "3.1415926 (#{node_with_ref_without_name.id})", printable_name(node_with_ref_without_name) + end end def test_link_class diff --git a/test/helpers/browse_tags_helper_test.rb b/test/helpers/browse_tags_helper_test.rb index 5574513c2..3aa851ef9 100644 --- a/test/helpers/browse_tags_helper_test.rb +++ b/test/helpers/browse_tags_helper_test.rb @@ -4,14 +4,6 @@ class BrowseTagsHelperTest < ActionView::TestCase include ERB::Util include ApplicationHelper - def setup - I18n.locale = "en" - end - - def teardown - I18n.locale = "en" - end - def test_format_key html = format_key("highway") assert_dom_equal "highway", html @@ -63,21 +55,21 @@ class BrowseTagsHelperTest < ActionView::TestCase link = wiki_link("tag", "highway=primary") assert_equal "https://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=en", link - I18n.locale = "de" + I18n.with_locale "de" do + link = wiki_link("key", "highway") + assert_equal "https://wiki.openstreetmap.org/wiki/DE:Key:highway?uselang=de", link - link = wiki_link("key", "highway") - assert_equal "https://wiki.openstreetmap.org/wiki/DE:Key:highway?uselang=de", link - - link = wiki_link("tag", "highway=primary") - assert_equal "https://wiki.openstreetmap.org/wiki/DE:Tag:highway=primary?uselang=de", link + link = wiki_link("tag", "highway=primary") + assert_equal "https://wiki.openstreetmap.org/wiki/DE:Tag:highway=primary?uselang=de", link + end - I18n.locale = "tr" + I18n.with_locale "tr" do + link = wiki_link("key", "highway") + assert_equal "https://wiki.openstreetmap.org/wiki/Tr:Key:highway?uselang=tr", link - link = wiki_link("key", "highway") - assert_equal "https://wiki.openstreetmap.org/wiki/Tr:Key:highway?uselang=tr", link - - link = wiki_link("tag", "highway=primary") - assert_equal "https://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=tr", link + link = wiki_link("tag", "highway=primary") + assert_equal "https://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=tr", link + end end def test_wikidata_links @@ -110,12 +102,12 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_equal "Q42", links[0][:title] # the language of the wikidata-page should match the current locale - I18n.locale = "zh-CN" - links = wikidata_links("wikidata", "Q1234") - assert_equal 1, links.length - assert_equal "//www.wikidata.org/entity/Q1234?uselang=zh-CN", links[0][:url] - assert_equal "Q1234", links[0][:title] - I18n.locale = "en" + I18n.with_locale "zh-CN" do + links = wikidata_links("wikidata", "Q1234") + assert_equal 1, links.length + assert_equal "//www.wikidata.org/entity/Q1234?uselang=zh-CN", links[0][:url] + assert_equal "Q1234", links[0][:title] + end ### Prefixed wikidata-tags @@ -129,16 +121,16 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_equal "Q24", links[0][:title] # Another allowed key, this time with multiple values and I18n - I18n.locale = "dsb" - links = wikidata_links("brand:wikidata", "Q936;Q2013;Q1568346") - assert_equal 3, links.length - assert_equal "//www.wikidata.org/entity/Q936?uselang=dsb", links[0][:url] - assert_equal "Q936", links[0][:title] - assert_equal "//www.wikidata.org/entity/Q2013?uselang=dsb", links[1][:url] - assert_equal "Q2013", links[1][:title] - assert_equal "//www.wikidata.org/entity/Q1568346?uselang=dsb", links[2][:url] - assert_equal "Q1568346", links[2][:title] - I18n.locale = "en" + I18n.with_locale "dsb" do + links = wikidata_links("brand:wikidata", "Q936;Q2013;Q1568346") + assert_equal 3, links.length + assert_equal "//www.wikidata.org/entity/Q936?uselang=dsb", links[0][:url] + assert_equal "Q936", links[0][:title] + assert_equal "//www.wikidata.org/entity/Q2013?uselang=dsb", links[1][:url] + assert_equal "Q2013", links[1][:title] + assert_equal "//www.wikidata.org/entity/Q1568346?uselang=dsb", links[2][:url] + assert_equal "Q1568346", links[2][:title] + end # and now with whitespaces... links = wikidata_links("subject:wikidata", "Q6542248 ;\tQ180\n ;\rQ364\t\n\r ;\nQ4006") @@ -184,11 +176,11 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_equal "https://de.wikipedia.org/wiki/de:Liste der Baudenkmäler in Eichstätt?uselang=en#Br.C3.BCckenstra.C3.9Fe_1.2C_Ehemaliges_Bauernhaus", link[:url] assert_equal "de:Liste der Baudenkmäler in Eichstätt#Brückenstraße 1, Ehemaliges Bauernhaus", link[:title] - I18n.locale = "pt-BR" - - link = wikipedia_link("wikipedia", "zh-classical:Test#Section") - assert_equal "https://zh-classical.wikipedia.org/wiki/zh-classical:Test?uselang=pt-BR#Section", link[:url] - assert_equal "zh-classical:Test#Section", link[:title] + I18n.with_locale "pt-BR" do + link = wikipedia_link("wikipedia", "zh-classical:Test#Section") + assert_equal "https://zh-classical.wikipedia.org/wiki/zh-classical:Test?uselang=pt-BR#Section", link[:url] + assert_equal "zh-classical:Test#Section", link[:title] + end link = wikipedia_link("foo", "Test") assert_nil link @@ -212,11 +204,11 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_equal "//commons.wikimedia.org/wiki/Category:Test_Category?uselang=en", link[:url] assert_equal "Category:Test_Category", link[:title] - I18n.locale = "pt-BR" - - link = wikimedia_commons_link("wikimedia_commons", "File:Test.jpg") - assert_equal "//commons.wikimedia.org/wiki/File:Test.jpg?uselang=pt-BR", link[:url] - assert_equal "File:Test.jpg", link[:title] + I18n.with_locale "pt-BR" do + link = wikimedia_commons_link("wikimedia_commons", "File:Test.jpg") + assert_equal "//commons.wikimedia.org/wiki/File:Test.jpg?uselang=pt-BR", link[:url] + assert_equal "File:Test.jpg", link[:title] + end link = wikimedia_commons_link("foo", "Test") assert_nil link diff --git a/test/integration/page_locale_test.rb b/test/integration/page_locale_test.rb index b42865ae4..c8e5026d4 100644 --- a/test/integration/page_locale_test.rb +++ b/test/integration/page_locale_test.rb @@ -1,14 +1,6 @@ require "test_helper" class PageLocaleTest < ActionDispatch::IntegrationTest - def setup - I18n.locale = "en" - end - - def teardown - I18n.locale = "en" - end - def test_defaulting user = create(:user, :languages => []) diff --git a/test/integration/user_creation_test.rb b/test/integration/user_creation_test.rb index a39e423c0..82a17fdff 100644 --- a/test/integration/user_creation_test.rb +++ b/test/integration/user_creation_test.rb @@ -2,16 +2,12 @@ require "test_helper" class UserCreationTest < ActionDispatch::IntegrationTest def setup - I18n.locale = "en" - OmniAuth.config.test_mode = true stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404) end def teardown - I18n.locale = "en" - OmniAuth.config.mock_auth[:openid] = nil OmniAuth.config.mock_auth[:google] = nil OmniAuth.config.mock_auth[:facebook] = nil -- 2.39.5