Permalink
Browse files

Fixed serialization issues with multiple includes with options

  • Loading branch information...
zhengjia committed Oct 11, 2011
1 parent 7b84e36 commit 1adf5662b54adf2f1d63a3934629c0f3aadeacb9
Showing with 9 additions and 1 deletion.
  1. +1 −1 activemodel/lib/active_model/serialization.rb
  2. +8 −0 activemodel/test/cases/serialization_test.rb
@@ -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

0 comments on commit 1adf566

Please sign in to comment.