Namespace
- CLASS SerializationTest::Address
- CLASS SerializationTest::FriendList
- CLASS SerializationTest::User
Methods
- S
- T
-
- test_except_include,
- test_find_records_by_serialized_attributes_through_join,
- test_include_option_with_ary,
- test_include_option_with_empty_association,
- test_include_option_with_plural_association,
- test_include_option_with_singular_association,
- test_include_root_in_json_allows_inheritance,
- test_include_root_in_json_is_false_by_default,
- 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_read_attribute_for_serialization_with_format_after_find,
- test_read_attribute_for_serialization_with_format_after_init,
- test_read_attribute_for_serialization_with_format_without_method_missing,
- test_serialize_should_allow_attribute_except_filtering,
- test_serialize_should_allow_attribute_only_filtering,
- test_serialize_should_be_reversible,
- 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 13 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, :id => nil } end
test_except_include()
Link
# File activemodel/test/cases/serialization_test.rb, line 154 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_find_records_by_serialized_attributes_through_join()
Link
# File activerecord/test/cases/serialization_test.rb, line 98 def test_find_records_by_serialized_attributes_through_join author = Author.create!(name: "David") author.serialized_posts.create!(title: "Hello") assert_equal 1, Author.joins(:serialized_posts).where(name: "David", serialized_posts: { title: "Hello" }).length end
test_include_option_with_ary()
Link
# File activemodel/test/cases/serialization_test.rb, line 118 def test_include_option_with_ary @user.friends = FriendList.new(@user.friends) 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_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_root_in_json_allows_inheritance()
Link
# File activerecord/test/cases/serialization_test.rb, line 58 def test_include_root_in_json_allows_inheritance original_root_in_json = ActiveRecord::Base.include_root_in_json ActiveRecord::Base.include_root_in_json = true klazz = Class.new(ActiveRecord::Base) klazz.table_name = 'topics' assert klazz.include_root_in_json klazz.include_root_in_json = false assert ActiveRecord::Base.include_root_in_json assert !klazz.include_root_in_json assert !klazz.new.include_root_in_json ensure ActiveRecord::Base.include_root_in_json = original_root_in_json end
test_include_root_in_json_is_false_by_default()
Link
test_include_with_options()
Link
# File activemodel/test/cases/serialization_test.rb, line 134 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
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 126 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 161 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 140 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
test_read_attribute_for_serialization_with_format_after_find()
Link
# File activerecord/test/cases/serialization_test.rb, line 90 def test_read_attribute_for_serialization_with_format_after_find klazz = Class.new(ActiveRecord::Base) klazz.table_name = 'books' book = klazz.find(books(:awdr).id) assert_equal 'paperback', book.read_attribute_for_serialization(:format) end
test_read_attribute_for_serialization_with_format_after_init()
Link
# File activerecord/test/cases/serialization_test.rb, line 82 def test_read_attribute_for_serialization_with_format_after_init klazz = Class.new(ActiveRecord::Base) klazz.table_name = 'books' book = klazz.new(format: 'paperback') assert_equal 'paperback', book.read_attribute_for_serialization(:format) end
test_read_attribute_for_serialization_with_format_without_method_missing()
Link
# File activerecord/test/cases/serialization_test.rb, line 74 def test_read_attribute_for_serialization_with_format_without_method_missing klazz = Class.new(ActiveRecord::Base) klazz.table_name = 'books' book = klazz.new assert_nil book.read_attribute_for_serialization(:format) end
test_serialize_should_allow_attribute_except_filtering()
Link
# File activerecord/test/cases/serialization_test.rb, line 48 def test_serialize_should_allow_attribute_except_filtering FORMATS.each do |format| @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 39 def test_serialize_should_allow_attribute_only_filtering FORMATS.each do |format| @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 30 def test_serialize_should_be_reversible FORMATS.each do |format| @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_should_not_call_methods_that_dont_respond()
Link
test_should_use_read_attribute_for_serialization()
Link