From: Andy Allan Date: Wed, 11 Nov 2020 15:51:44 +0000 (+0000) Subject: Prefer keyword arguments when method has optional boolean arguments X-Git-Tag: live~2378^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/1f242978af5400bbe53d61491d0f7e8ba563d9ae?ds=inline;hp=a2bb4388e41796edd7d5e117e44084d0b3b41253 Prefer keyword arguments when method has optional boolean arguments --- diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cfff8c43e..f6d11c58f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -185,9 +185,6 @@ Style/OptionalBooleanParameter: - 'app/models/trace.rb' - 'app/models/tracepoint.rb' - 'app/models/way.rb' - - 'test/models/diary_entry_test.rb' - - 'test/models/trace_test.rb' - - 'test/models/tracetag_test.rb' # Offense count: 28 # Cop supports --auto-correct. diff --git a/test/helpers/browse_helper_test.rb b/test/helpers/browse_helper_test.rb index bc597596f..076975b09 100644 --- a/test/helpers/browse_helper_test.rb +++ b/test/helpers/browse_helper_test.rb @@ -31,8 +31,8 @@ class BrowseHelperTest < ActionView::TestCase 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, true) - assert_dom_equal "#{node.id}, v1", printable_name(node_v1, true) + 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.locale = "pt" @@ -41,8 +41,8 @@ class BrowseHelperTest < ActionView::TestCase 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, true) - assert_dom_equal "#{node.id}, v1", printable_name(node_v1, true) + 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" @@ -51,8 +51,8 @@ class BrowseHelperTest < ActionView::TestCase 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, true) - assert_dom_equal "#{node.id}, v1", printable_name(node_v1, true) + 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 = "de" @@ -61,8 +61,8 @@ class BrowseHelperTest < ActionView::TestCase 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, true) - assert_dom_equal "#{node.id}, v1", printable_name(node_v1, true) + 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 diff --git a/test/models/diary_entry_test.rb b/test/models/diary_entry_test.rb index 76e8bbbe0..2b94d04dd 100644 --- a/test/models/diary_entry_test.rb +++ b/test/models/diary_entry_test.rb @@ -8,18 +8,18 @@ class DiaryEntryTest < ActiveSupport::TestCase def test_diary_entry_validations diary_entry_valid({}) - diary_entry_valid({ :title => "" }, false) + diary_entry_valid({ :title => "" }, :valid => false) diary_entry_valid(:title => "a" * 255) - diary_entry_valid({ :title => "a" * 256 }, false) - diary_entry_valid({ :body => "" }, false) + diary_entry_valid({ :title => "a" * 256 }, :valid => false) + diary_entry_valid({ :body => "" }, :valid => false) diary_entry_valid(:latitude => 90) - diary_entry_valid({ :latitude => 90.00001 }, false) + diary_entry_valid({ :latitude => 90.00001 }, :valid => false) diary_entry_valid(:latitude => -90) - diary_entry_valid({ :latitude => -90.00001 }, false) + diary_entry_valid({ :latitude => -90.00001 }, :valid => false) diary_entry_valid(:longitude => 180) - diary_entry_valid({ :longitude => 180.00001 }, false) + diary_entry_valid({ :longitude => 180.00001 }, :valid => false) diary_entry_valid(:longitude => -180) - diary_entry_valid({ :longitude => -180.00001 }, false) + diary_entry_valid({ :longitude => -180.00001 }, :valid => false) end def test_diary_entry_visible @@ -48,8 +48,8 @@ class DiaryEntryTest < ActiveSupport::TestCase private - def diary_entry_valid(attrs, result = true) + def diary_entry_valid(attrs, valid: true) entry = build(:diary_entry, attrs) - assert_equal result, entry.valid?, "Expected #{attrs.inspect} to be #{result}" + assert_equal valid, entry.valid?, "Expected #{attrs.inspect} to be #{valid}" end end diff --git a/test/models/trace_test.rb b/test/models/trace_test.rb index 8b38b7f0e..fc5064ad7 100644 --- a/test/models/trace_test.rb +++ b/test/models/trace_test.rb @@ -76,17 +76,17 @@ class TraceTest < ActiveSupport::TestCase def test_validations trace_valid({}) - trace_valid({ :user_id => nil }, false) + trace_valid({ :user_id => nil }, :valid => false) trace_valid(:name => "a" * 255) - trace_valid({ :name => "a" * 256 }, false) - trace_valid({ :description => nil }, false) + trace_valid({ :name => "a" * 256 }, :valid => false) + trace_valid({ :description => nil }, :valid => false) trace_valid(:description => "a" * 255) - trace_valid({ :description => "a" * 256 }, false) + trace_valid({ :description => "a" * 256 }, :valid => false) trace_valid(:visibility => "private") trace_valid(:visibility => "public") trace_valid(:visibility => "trackable") trace_valid(:visibility => "identifiable") - trace_valid({ :visibility => "foo" }, false) + trace_valid({ :visibility => "foo" }, :valid => false) end def test_tagstring @@ -319,9 +319,9 @@ class TraceTest < ActiveSupport::TestCase assert_equal md5sum, md5sum(create(:trace, :fixture => id).xml_file) end - def trace_valid(attrs, result = true) + def trace_valid(attrs, valid: true) entry = build(:trace, attrs) - assert_equal result, entry.valid?, "Expected #{attrs.inspect} to be #{result}" + assert_equal valid, entry.valid?, "Expected #{attrs.inspect} to be #{valid}" end def md5sum(io) diff --git a/test/models/tracetag_test.rb b/test/models/tracetag_test.rb index 04263dbb7..1aaa596d2 100644 --- a/test/models/tracetag_test.rb +++ b/test/models/tracetag_test.rb @@ -3,23 +3,23 @@ require "test_helper" class TracetagTest < ActiveSupport::TestCase def test_validations tracetag_valid({}) - tracetag_valid({ :tag => nil }, false) - tracetag_valid({ :tag => "" }, false) + tracetag_valid({ :tag => nil }, :valid => false) + tracetag_valid({ :tag => "" }, :valid => false) tracetag_valid(:tag => "a") tracetag_valid(:tag => "a" * 255) - tracetag_valid({ :tag => "a" * 256 }, false) - tracetag_valid({ :tag => "a/b" }, false) - tracetag_valid({ :tag => "a;b" }, false) - tracetag_valid({ :tag => "a.b" }, false) - tracetag_valid({ :tag => "a,b" }, false) - tracetag_valid({ :tag => "a?b" }, false) + tracetag_valid({ :tag => "a" * 256 }, :valid => false) + tracetag_valid({ :tag => "a/b" }, :valid => false) + tracetag_valid({ :tag => "a;b" }, :valid => false) + tracetag_valid({ :tag => "a.b" }, :valid => false) + tracetag_valid({ :tag => "a,b" }, :valid => false) + tracetag_valid({ :tag => "a?b" }, :valid => false) end private - def tracetag_valid(attrs, result = true) + def tracetag_valid(attrs, valid: true) entry = build(:tracetag) entry.assign_attributes(attrs) - assert_equal result, entry.valid?, "Expected #{attrs.inspect} to be #{result}" + assert_equal valid, entry.valid?, "Expected #{attrs.inspect} to be #{valid}" end end