aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorAnand <lucky.developer@gmail.com>2011-08-23 16:03:58 +0530
committerAnand <lucky.developer@gmail.com>2011-08-23 16:03:58 +0530
commit56e32ad40f8a1658c507ab0565767b82018369af (patch)
tree635ab8e71b24f5c505b4232da72a1807fce0de99 /activemodel
parent0b6da0c65497df4ee9d2f9313ccb9909bdc842e9 (diff)
downloadrails-56e32ad40f8a1658c507ab0565767b82018369af.tar.gz
rails-56e32ad40f8a1658c507ab0565767b82018369af.tar.bz2
rails-56e32ad40f8a1658c507ab0565767b82018369af.zip
added more tests for only-include and except-include options in serialization
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/test/cases/serialization_test.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/activemodel/test/cases/serialization_test.rb b/activemodel/test/cases/serialization_test.rb
index 5122f08eec..071cb9ff4e 100644
--- a/activemodel/test/cases/serialization_test.rb
+++ b/activemodel/test/cases/serialization_test.rb
@@ -114,8 +114,21 @@ class SerializationTest < ActiveModel::TestCase
@user.friends.first.friends = [@user]
expected = {"email"=>"david@example.com", "gender"=>"male", "name"=>"David",
:friends=>[{"name"=>'Joe', "email"=>'joe@example.com', "gender"=>'male',
- :friends => ["email"=>"david@example.com", "gender"=>"male", "name"=>"David"]},
+ :friends => [{"email"=>"david@example.com", "gender"=>"male", "name"=>"David"}]},
{"name"=>'Sue', "email"=>'sue@example.com', "gender"=>'female', :friends => []}]}
assert_equal expected , @user.serializable_hash(:include => {:friends => {:include => :friends}})
end
+
+ def test_only_include
+ expected = {"name"=>"David", :friends => [{"name" => "Joe"}, {"name" => "Sue"}]}
+ assert_equal expected , @user.serializable_hash(:only => :name, :include => {:friends => {:only => :name}})
+ end
+
+ def test_except_include
+ expected = {"name"=>"David", "email"=>"david@example.com",
+ :friends => [{"name" => 'Joe', "email" => 'joe@example.com'},
+ {"name" => "Sue", "email" => 'sue@example.com'}]}
+ assert_equal expected , @user.serializable_hash(:except => :gender, :include => {:friends => {:except => :gender}})
+ end
+
end