Namespace
- CLASS SerializationTest::Address
- CLASS SerializationTest::User
Methods
- S
- T
-
- test_except_include,
- test_include_option_with_empty_association,
- test_include_option_with_plural_association,
- test_include_option_with_singular_association,
- test_include_with_options,
- test_method_serializable_hash_should_work,
- test_method_serializable_hash_should_work_with_except_and_methods,
- test_method_serializable_hash_should_work_with_except_option,
- test_method_serializable_hash_should_work_with_methods_option,
- test_method_serializable_hash_should_work_with_only_and_methods,
- test_method_serializable_hash_should_work_with_only_option,
- test_multiple_includes,
- test_multiple_includes_with_options,
- test_nested_include,
- test_only_include,
- test_serialize_should_allow_attribute_except_filtering,
- test_serialize_should_allow_attribute_only_filtering,
- test_serialize_should_be_reversible,
- test_serialized_init_with,
- test_should_not_call_methods_that_dont_respond,
- test_should_use_read_attribute_for_serialization
Constants
| FORMATS | = | [ :xml, :json ] |
Instance Public methods
setup()
Link
# File activerecord/test/cases/serialization_test.rb, line 8 def setup @contact_attributes = { :name => 'aaron stack', :age => 25, :avatar => 'binarydata', :created_at => Time.utc(2006, 8, 1), :awesome => false, :preferences => { :gem => '<strong>ruby</strong>' }, :alternative_id => nil } end
test_except_include()
Link
# File activemodel/test/cases/serialization_test.rb, line 136 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
test_include_option_with_empty_association()
Link
# File activemodel/test/cases/serialization_test.rb, line 102 def test_include_option_with_empty_association @user.friends = [] expected = {"email"=>"david@example.com", "gender"=>"male", "name"=>"David", :friends=>[]} assert_equal expected , @user.serializable_hash(:include => :friends) end
test_include_option_with_plural_association()
Link
# File activemodel/test/cases/serialization_test.rb, line 95 def test_include_option_with_plural_association expected = {"email"=>"david@example.com", "gender"=>"male", "name"=>"David", :friends=>[{"name"=>'Joe', "email"=>'joe@example.com', "gender"=>'male'}, {"name"=>'Sue', "email"=>'sue@example.com', "gender"=>'female'}]} assert_equal expected , @user.serializable_hash(:include => :friends) end
test_include_option_with_singular_association()
Link
# File activemodel/test/cases/serialization_test.rb, line 89 def test_include_option_with_singular_association expected = {"name"=>"David", "gender"=>"male", "email"=>"david@example.com", :address=>{"street"=>"123 Lane", "city"=>"Springfield", "state"=>"CA", "zip"=>11111}} assert_equal expected , @user.serializable_hash(:include => :address) end
test_include_with_options()
Link
# File activemodel/test/cases/serialization_test.rb, line 116 def test_include_with_options expected = {"email"=>"david@example.com", "gender"=>"male", "name"=>"David", :address=>{"street"=>"123 Lane"}} assert_equal expected , @user.serializable_hash(:include => {:address => {:only => "street"}}) end
test_method_serializable_hash_should_work()
Link
test_method_serializable_hash_should_work_with_except_and_methods()
Link
# File activemodel/test/cases/serialization_test.rb, line 70 def test_method_serializable_hash_should_work_with_except_and_methods expected = {"gender"=>"male", :foo=>"i_am_foo"} assert_equal expected , @user.serializable_hash(:except => [:name, :email], :methods => [:foo]) end
test_method_serializable_hash_should_work_with_except_option()
Link
test_method_serializable_hash_should_work_with_methods_option()
Link
# File activemodel/test/cases/serialization_test.rb, line 60 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
test_method_serializable_hash_should_work_with_only_and_methods()
Link
test_method_serializable_hash_should_work_with_only_option()
Link
test_multiple_includes()
Link
# File activemodel/test/cases/serialization_test.rb, line 108 def test_multiple_includes expected = {"email"=>"david@example.com", "gender"=>"male", "name"=>"David", :address=>{"street"=>"123 Lane", "city"=>"Springfield", "state"=>"CA", "zip"=>11111}, :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, :friends]) end
test_multiple_includes_with_options()
Link
# File activemodel/test/cases/serialization_test.rb, line 143 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
test_nested_include()
Link
# File activemodel/test/cases/serialization_test.rb, line 122 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"}]}, {"name"=>'Sue', "email"=>'sue@example.com', "gender"=>'female', :friends => []}]} assert_equal expected , @user.serializable_hash(:include => {:friends => {:include => :friends}}) end
test_only_include()
Link
# File activemodel/test/cases/serialization_test.rb, line 131 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
test_serialize_should_allow_attribute_except_filtering()
Link
# File activerecord/test/cases/serialization_test.rb, line 44 def test_serialize_should_allow_attribute_except_filtering for format in FORMATS @serialized = Contact.new(@contact_attributes).send("to_#{format}", :except => [ :age, :name ]) contact = Contact.new.send("from_#{format}", @serialized) assert_nil contact.name, "For #{format}" assert_nil contact.age, "For #{format}" assert_equal @contact_attributes[:awesome], contact.awesome, "For #{format}" end end
test_serialize_should_allow_attribute_only_filtering()
Link
# File activerecord/test/cases/serialization_test.rb, line 35 def test_serialize_should_allow_attribute_only_filtering for format in FORMATS @serialized = Contact.new(@contact_attributes).send("to_#{format}", :only => [ :age, :name ]) contact = Contact.new.send("from_#{format}", @serialized) assert_equal @contact_attributes[:name], contact.name, "For #{format}" assert_nil contact.avatar, "For #{format}" end end
test_serialize_should_be_reversible()
Link
# File activerecord/test/cases/serialization_test.rb, line 26 def test_serialize_should_be_reversible for format in FORMATS @serialized = Contact.new.send("to_#{format}") contact = Contact.new.send("from_#{format}", @serialized) assert_equal @contact_attributes.keys.collect(&:to_s).sort, contact.attributes.keys.collect(&:to_s).sort, "For #{format}" end end
test_serialized_init_with()
Link
test_should_not_call_methods_that_dont_respond()
Link
test_should_use_read_attribute_for_serialization()
Link