diff options
author | Rick Olson <technoweenie@gmail.com> | 2007-05-28 15:51:53 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2007-05-28 15:51:53 +0000 |
commit | 4472a30aadc35f8a9a67db8b0a2a7318c3a0dcfd (patch) | |
tree | 9a7582184fb23eb8e553e26ec97cf62a9b5ae564 /activerecord/test | |
parent | 6f6328787cb0ba61f7af1e733826b5ffcdd6a398 (diff) | |
download | rails-4472a30aadc35f8a9a67db8b0a2a7318c3a0dcfd.tar.gz rails-4472a30aadc35f8a9a67db8b0a2a7318c3a0dcfd.tar.bz2 rails-4472a30aadc35f8a9a67db8b0a2a7318c3a0dcfd.zip |
Allow nil serialized attributes with a set class constraint. #7293 [sandofsky]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6879 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/base_test.rb | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 50e7ba9da3..3171e75bac 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -1154,16 +1154,29 @@ class BasicsTest < Test::Unit::TestCase assert_equal(myobj, topic.content) end - def test_serialized_attribute_with_class_constraint + def test_nil_serialized_attribute_with_class_constraint myobj = MyObject.new('value1', 'value2') - topic = Topic.create("content" => myobj) - Topic.serialize(:content, Hash) + topic = Topic.new + assert_nil topic.content + end + def test_should_raise_exception_on_serialized_attribute_with_type_mismatch + myobj = MyObject.new('value1', 'value2') + topic = Topic.new(:content => myobj) + assert topic.save + Topic.serialize(:content, Hash) assert_raise(ActiveRecord::SerializationTypeMismatch) { Topic.find(topic.id).content } + ensure + Topic.serialize(:content) + end + def test_serialized_attribute_with_class_constraint settings = { "color" => "blue" } - Topic.find(topic.id).update_attribute("content", settings) + Topic.serialize(:content, Hash) + topic = Topic.new(:content => settings) + assert topic.save assert_equal(settings, Topic.find(topic.id).content) + ensure Topic.serialize(:content) end |