Fixed serialization issues with multiple includes with options

This commit is contained in:
zhengjia 2011-10-11 11:09:43 -05:00
parent 7b84e36cd6
commit 1adf5662b5
2 changed files with 9 additions and 1 deletions

@ -126,7 +126,7 @@ def serializable_add_includes(options = {}) #:nodoc:
return unless include = options[:include]
unless include.is_a?(Hash)
include = Hash[Array.wrap(include).map { |n| [n, {}] }]
include = Hash[Array.wrap(include).map { |n| n.is_a?(Hash) ? n.to_a.first : [n, {}] }]
end
include.each do |association, opts|

@ -140,4 +140,12 @@ def test_except_include
assert_equal expected , @user.serializable_hash(:except => :gender, :include => {:friends => {:except => :gender}})
end
def test_multiple_includes_with_options
expected = {"email"=>"david@example.com", "gender"=>"male", "name"=>"David",
:address=>{"street"=>"123 Lane"},
:friends=>[{"name"=>'Joe', "email"=>'joe@example.com', "gender"=>'male'},
{"name"=>'Sue', "email"=>'sue@example.com', "gender"=>'female'}]}
assert_equal expected , @user.serializable_hash(:include => [{:address => {:only => "street"}}, :friends])
end
end