Permalink
Browse files

Merge pull request #2651 from luckydev/serialization-tests

More tests for only-include and except-include options in serialization
  • Loading branch information...
2 parents 14cf4b2 + 56e32ad commit 5536d901e54698e55d117c536d1cca89af6a5f8e @josevalim josevalim committed Aug 23, 2011
Showing with 14 additions and 1 deletion.
  1. +14 −1 activemodel/test/cases/serialization_test.rb
@@ -114,8 +114,21 @@ def test_nested_include
@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

0 comments on commit 5536d90

Please sign in to comment.