added more tests for only-include and except-include options in serialization

This commit is contained in:
Anand 2011-08-23 16:03:58 +05:30
parent 0b6da0c654
commit 56e32ad40f
1 changed files with 14 additions and 1 deletions

View File

@ -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