diff options
-rw-r--r-- | activemodel/lib/active_model/serialization.rb | 2 | ||||
-rw-r--r-- | activemodel/test/cases/serialization_test.rb | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb index ba9721cc70..f7b1880ed9 100644 --- a/activemodel/lib/active_model/serialization.rb +++ b/activemodel/lib/active_model/serialization.rb @@ -82,7 +82,7 @@ module ActiveModel attribute_names.each { |n| hash[n] = read_attribute_for_serialization(n) } method_names = Array(options[:methods]).select { |n| respond_to?(n) } - method_names.each { |n| hash[n] = send(n) } + method_names.each { |n| hash[n.to_s] = send(n) } serializable_add_includes(options) do |association, records, opts| hash[association] = if records.is_a?(Enumerable) diff --git a/activemodel/test/cases/serialization_test.rb b/activemodel/test/cases/serialization_test.rb index 208fcb23ad..3b201a70f5 100644 --- a/activemodel/test/cases/serialization_test.rb +++ b/activemodel/test/cases/serialization_test.rb @@ -58,17 +58,17 @@ class SerializationTest < ActiveModel::TestCase end def test_method_serializable_hash_should_work_with_methods_option - expected = {"name"=>"David", "gender"=>"male", :foo=>"i_am_foo", "email"=>"david@example.com"} + expected = {"name"=>"David", "gender"=>"male", "foo"=>"i_am_foo", "email"=>"david@example.com"} assert_equal expected, @user.serializable_hash(:methods => [:foo]) end def test_method_serializable_hash_should_work_with_only_and_methods - expected = {:foo=>"i_am_foo"} + expected = {"foo"=>"i_am_foo"} assert_equal expected, @user.serializable_hash(:only => [], :methods => [:foo]) end def test_method_serializable_hash_should_work_with_except_and_methods - expected = {"gender"=>"male", :foo=>"i_am_foo"} + expected = {"gender"=>"male", "foo"=>"i_am_foo"} assert_equal expected, @user.serializable_hash(:except => [:name, :email], :methods => [:foo]) end |