diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-02-13 11:22:59 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-02-13 11:22:59 -0200 |
commit | ad9f968c4a4639bdc5e0a6e71189a1756c959ca3 (patch) | |
tree | 7b708c88bda8fc5dc9e4a9714cd43b6f4224da4f | |
parent | 5bcb4e3c18670977b543bef79fbbbe5d9732f094 (diff) | |
download | rails-ad9f968c4a4639bdc5e0a6e71189a1756c959ca3.tar.gz rails-ad9f968c4a4639bdc5e0a6e71189a1756c959ca3.tar.bz2 rails-ad9f968c4a4639bdc5e0a6e71189a1756c959ca3.zip |
Make sure serializable hash with :methods option returns always string keys
-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 |