Skip to content

Commit

Permalink
Fix warnings for attribute methods with kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
kamipo committed Jan 20, 2020
1 parent 72cd217 commit a070260
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions activemodel/lib/active_model/attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ def method_missing(method, *args, &block)
match ? attribute_missing(match, *args, &block) : super
end
end
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)

# +attribute_missing+ is like +method_missing+, but for attributes. When
# +method_missing+ is called we check to see if there is a matching
Expand Down
8 changes: 7 additions & 1 deletion activemodel/test/cases/attribute_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ModelWithAttributes2

attr_accessor :attributes

attribute_method_suffix "_test"
attribute_method_suffix "_test", "_kw"

private
def attribute(name)
Expand All @@ -37,6 +37,10 @@ def attribute_test(name, attrs = {})
attrs[name] = attribute(name)
end

def attribute_kw(name, kw: 1)
attribute(name)
end

def private_method
"<3 <3"
end
Expand Down Expand Up @@ -217,6 +221,7 @@ def foo
attrs = {}

assert_equal "bar", m.foo
assert_equal "bar", m.foo_kw(kw: 2)
assert_equal "bar", m.foo_test(attrs)
assert_equal "bar", attrs["foo"]
end
Expand All @@ -229,6 +234,7 @@ def foo
attrs = {}

assert_equal "bar", m.foo
assert_equal "bar", m.foo_kw(kw: 2)
assert_equal "bar", m.foo_test(attrs)
assert_equal "bar", attrs["foo"]
ensure
Expand Down

0 comments on commit a070260

Please sign in to comment.