diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2010-08-03 10:26:24 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-08-31 17:45:03 +0200 |
commit | 8402488568cbc6ea2a90990faef65aa39bf1494d (patch) | |
tree | 3f9170ab717c042f24c4e776b03406bac52818e0 /activemodel | |
parent | 94b850c6611f202a09990f0a2066ce7aea13c6c5 (diff) | |
download | rails-8402488568cbc6ea2a90990faef65aa39bf1494d.tar.gz rails-8402488568cbc6ea2a90990faef65aa39bf1494d.tar.bz2 rails-8402488568cbc6ea2a90990faef65aa39bf1494d.zip |
adding new test for ActiveModel::Serialization
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/test/cases/serialization_test.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/activemodel/test/cases/serialization_test.rb b/activemodel/test/cases/serialization_test.rb new file mode 100644 index 0000000000..8cc1ccb1e7 --- /dev/null +++ b/activemodel/test/cases/serialization_test.rb @@ -0,0 +1,45 @@ +require "cases/helper" + +class SerializationTest < ActiveModel::TestCase + class User + include ActiveModel::Serialization + + attr_accessor :name, :email, :gender + + def attributes + @attributes ||= {'name' => 'nil', 'email' => 'nil', 'gender' => 'nil'} + end + + def foo + 'i_am_foo' + end + end + + setup do + @user = User.new + @user.name = 'David' + @user.email = 'david@example.com' + @user.gender = 'male' + end + + def test_method_serializable_hash_should_work + expected = {"name"=>"David", "gender"=>"male", "email"=>"david@example.com"} + assert_equal expected , @user.serializable_hash + end + + def test_method_serializable_hash_should_work_with_only_option + expected = {"name"=>"David"} + assert_equal expected , @user.serializable_hash(:only => [:name]) + end + + def test_method_serializable_hash_should_work_with_except_option + expected = {"gender"=>"male", "email"=>"david@example.com"} + assert_equal expected , @user.serializable_hash(:except => [:name]) + end + + def test_method_serializable_hash_should_work_with_methods_option + expected = {"name"=>"David", "gender"=>"male", :foo=>"i_am_foo", "email"=>"david@example.com"} + assert_equal expected , @user.serializable_hash(:methods => [:foo]) + end + +end |