Skip to content

Commit

Permalink
Merge pull request #28092 from sikachu/fix-define_attribute_method-wi…
Browse files Browse the repository at this point in the history
…th-symbol-in-ar

Fix `define_attribute_method` with Symbol in AR
  • Loading branch information
guilleiguaran committed Feb 21, 2017
2 parents ba22c5e + 0b157f8 commit 5716c4d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/attribute_methods.rb
Expand Up @@ -289,7 +289,7 @@ def define_attribute_method(attr_name)
generate_method = "define_method_#{matcher.method_missing_target}"

if respond_to?(generate_method, true)
send(generate_method, attr_name)
send(generate_method, attr_name.to_s)
else
define_proxy_call true, generated_attribute_methods, method_name, matcher.method_missing_target, attr_name.to_s
end
Expand Down
7 changes: 7 additions & 0 deletions activerecord/test/cases/attribute_methods_test.rb
Expand Up @@ -866,6 +866,13 @@ def name
assert subklass.method_defined?(:id), "subklass is missing id method"
end

test "define_attribute_method works with both symbol and string" do
klass = Class.new(ActiveRecord::Base)

assert_nothing_raised { klass.define_attribute_method(:foo) }
assert_nothing_raised { klass.define_attribute_method("bar") }
end

test "read_attribute with nil should not asplode" do
assert_nil Topic.new.read_attribute(nil)
end
Expand Down

0 comments on commit 5716c4d

Please sign in to comment.