Permalink
Browse files

Make sure serializable hash with :methods option returns always strin…

…g keys
  • Loading branch information...
carlosantoniodasilva committed Feb 13, 2012
1 parent 5bcb4e3 commit ad9f968c4a4639bdc5e0a6e71189a1756c959ca3
Showing with 4 additions and 4 deletions.
  1. +1 −1 activemodel/lib/active_model/serialization.rb
  2. +3 −3 activemodel/test/cases/serialization_test.rb
@@ -82,7 +82,7 @@ def serializable_hash(options = nil)
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)
@@ -58,17 +58,17 @@ def test_method_serializable_hash_should_work_with_except_option
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

0 comments on commit ad9f968

Please sign in to comment.