diff options
author | zhengjia <jiazheng@live.com> | 2011-10-11 11:09:43 -0500 |
---|---|---|
committer | zhengjia <jiazheng@live.com> | 2011-10-11 11:09:43 -0500 |
commit | 1adf5662b54adf2f1d63a3934629c0f3aadeacb9 (patch) | |
tree | 283efa0d08d130d85f8381355ef69d692c6b3c83 /activemodel | |
parent | 7b84e36cd6212fbbcddee1620f0ffd0e1f5a0024 (diff) | |
download | rails-1adf5662b54adf2f1d63a3934629c0f3aadeacb9.tar.gz rails-1adf5662b54adf2f1d63a3934629c0f3aadeacb9.tar.bz2 rails-1adf5662b54adf2f1d63a3934629c0f3aadeacb9.zip |
Fixed serialization issues with multiple includes with options
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/serialization.rb | 2 | ||||
-rw-r--r-- | activemodel/test/cases/serialization_test.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb index 7bc3f997b5..a4b58ab456 100644 --- a/activemodel/lib/active_model/serialization.rb +++ b/activemodel/lib/active_model/serialization.rb @@ -126,7 +126,7 @@ module ActiveModel 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| diff --git a/activemodel/test/cases/serialization_test.rb b/activemodel/test/cases/serialization_test.rb index 1ec915d245..b8dad9d51f 100644 --- a/activemodel/test/cases/serialization_test.rb +++ b/activemodel/test/cases/serialization_test.rb @@ -140,4 +140,12 @@ class SerializationTest < ActiveModel::TestCase 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 |