Address warning: Passing only keyword arguments

This pull request addresses the following warnings enabled since ruby/ruby#4070

* Warnings without this fix 1

```
% ruby -v
ruby 3.1.0dev (2021-02-01T10:54:21Z master 1cdae49d39) [x86_64-darwin20]
% bin/test test/cases/arel/visitors/sqlite_test.rb:36
... snip ...
/Users/yahonda/src/github.com/rails/rails/activerecord/test/cases/arel/support/fake_record.rb:98: warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).
.

Finished in 0.003538s, 2261.1645 runs/s, 2543.8101 assertions/s.
8 runs, 9 assertions, 0 failures, 0 errors, 0 skips
%
```

* Warnings without this fix 2

```ruby
% ruby -v
ruby 3.1.0dev (2021-02-01T10:54:21Z master 1cdae49d39) [x86_64-darwin20]
% bin/test test/cases/type/adapter_specific_registry_test.rb
Using sqlite3
Run options: --seed 53175

......./Users/yahonda/src/github.com/rails/rails/activerecord/test/cases/type/adapter_specific_registry_test.rb:126: warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).
/Users/yahonda/src/github.com/rails/rails/activemodel/lib/active_model/type/registry.rb:18: warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).
/Users/yahonda/src/github.com/rails/rails/activerecord/test/cases/type/adapter_specific_registry_test.rb:130: warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).
/Users/yahonda/src/github.com/rails/rails/activemodel/lib/active_model/type/registry.rb:18: warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).
.../Users/yahonda/src/github.com/rails/rails/activerecord/test/cases/type/adapter_specific_registry_test.rb:85: warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).
/Users/yahonda/src/github.com/rails/rails/activemodel/lib/active_model/type/registry.rb:18: warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).
/Users/yahonda/src/github.com/rails/rails/activerecord/test/cases/type/adapter_specific_registry_test.rb:86: warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).
/Users/yahonda/src/github.com/rails/rails/activemodel/lib/active_model/type/registry.rb:18: warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).
.

Finished in 0.011424s, 962.8852 runs/s, 2450.9804 assertions/s.
11 runs, 28 assertions, 0 failures, 0 errors, 0 skips
%
```

* Warnings without this fix 3

```ruby
$ cd actionview
$ bin/test test/template/url_helper_test.rb
Run options: --seed 27105

........................../home/yahonda/src/github.com/rails/rails/actionview/test/template/url_helper_test.rb:88: warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).
.............................../home/yahonda/src/github.com/rails/rails/actionview/test/template/url_helper_test.rb:94: warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).
..................................................../home/yahonda/src/github.com/rails/rails/actionview/test/template/url_helper_test.rb:71: warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).
......................

Finished in 0.305066s, 429.4159 runs/s, 580.2032 assertions/s.
131 runs, 177 assertions, 0 failures, 0 errors, 0 skips
$
```

Refer:
ruby/ruby#4070
https://bugs.ruby-lang.org/issues/16806

Co-authored-by: Ryuta Kamizono <kamipo@gmail.com>
This commit is contained in:
Yasuo Honda 2021-02-02 21:25:43 +09:00
parent a70680bb07
commit 40db515e91
3 changed files with 16 additions and 6 deletions

@ -68,7 +68,7 @@ def test_url_for_does_not_include_empty_hashes
def test_url_for_with_back
referer = "http://www.example.com/referer"
@controller = Struct.new(:request).new(Struct.new(:env).new("HTTP_REFERER" => referer))
@controller = Struct.new(:request).new(Struct.new(:env).new({ "HTTP_REFERER" => referer }))
assert_equal "http://www.example.com/referer", url_for(:back)
end
@ -85,13 +85,13 @@ def test_url_for_with_back_and_no_controller
def test_url_for_with_back_and_javascript_referer
referer = "javascript:alert(document.cookie)"
@controller = Struct.new(:request).new(Struct.new(:env).new("HTTP_REFERER" => referer))
@controller = Struct.new(:request).new(Struct.new(:env).new({ "HTTP_REFERER" => referer }))
assert_equal "javascript:history.back()", url_for(:back)
end
def test_url_for_with_invalid_referer
referer = "THIS IS NOT A URL"
@controller = Struct.new(:request).new(Struct.new(:env).new("HTTP_REFERER" => referer))
@controller = Struct.new(:request).new(Struct.new(:env).new({ "HTTP_REFERER" => referer }))
assert_equal "javascript:history.back()", url_for(:back)
end

@ -89,7 +89,7 @@ def quote(thing)
end
class ConnectionPool
class Spec < Struct.new(:config)
class Spec < Struct.new(:adapter, keyword_init: true)
end
attr_reader :spec, :connection

@ -76,7 +76,6 @@ class AdapterSpecificRegistryTest < ActiveRecord::TestCase
end
test "construct args are passed to the type" do
type = Struct.new(:args)
registry = Type::AdapterSpecificRegistry.new
registry.register(:foo, type)
@ -117,7 +116,6 @@ class AdapterSpecificRegistryTest < ActiveRecord::TestCase
test "registering adapter specific modifiers" do
decoration = Struct.new(:value)
type = Struct.new(:args)
registry = Type::AdapterSpecificRegistry.new
registry.register(:foo, type)
registry.add_modifier({ array: true }, decoration, adapter: :postgresql)
@ -131,5 +129,17 @@ class AdapterSpecificRegistryTest < ActiveRecord::TestCase
registry.lookup(:foo, array: true, adapter: :sqlite3)
)
end
TYPE = Class.new do
attr_reader :args
def initialize(args = nil)
@args = args
end
def ==(other) self.args == other.args end
end
private def type; TYPE end
end
end