aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-02-01 10:39:03 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-02-01 10:39:03 -0800
commit6da8ec14c5e2ea0b60d4b3f4fa373d55a849aec9 (patch)
treeb893716e5fc3f4f181013254965b16afa9282e9b /activerecord/test/cases
parent78d5d6f8688bb7c45ba9a3ef893682231130da3f (diff)
parent39cb1bedb82814d7bf9de6834f88c31e4df27278 (diff)
downloadrails-6da8ec14c5e2ea0b60d4b3f4fa373d55a849aec9.tar.gz
rails-6da8ec14c5e2ea0b60d4b3f4fa373d55a849aec9.tar.bz2
rails-6da8ec14c5e2ea0b60d4b3f4fa373d55a849aec9.zip
Merge pull request #4806 from KL-7/do-not-serialize-nil
Do not serialize nil in serialized attribute.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/base_test.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 6c3e4fc6d0..d70525b57d 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -1301,11 +1301,24 @@ class BasicsTest < ActiveRecord::TestCase
assert_equal(myobj, topic.content)
end
- def test_nil_serialized_attribute_with_class_constraint
+ def test_nil_serialized_attribute_without_class_constraint
topic = Topic.new
assert_nil topic.content
end
+ def test_nil_not_serialized_without_class_constraint
+ assert Topic.new(:content => nil).save
+ assert_equal 1, Topic.where(:content => nil).count
+ end
+
+ def test_nil_not_serialized_with_class_constraint
+ Topic.serialize :content, Hash
+ assert Topic.new(:content => nil).save
+ assert_equal 1, Topic.where(:content => nil).count
+ ensure
+ Topic.serialize(:content)
+ end
+
def test_should_raise_exception_on_serialized_attribute_with_type_mismatch
myobj = MyObject.new('value1', 'value2')
topic = Topic.new(:content => myobj)