Permalink
Browse files

Use teardown hook to return the initial state of the object

  • Loading branch information...
1 parent 21be180 commit 4f6120e0d58e73f410ba9834b52ecf0072423326 @rafaelfranca rafaelfranca committed Aug 26, 2012
Showing with 5 additions and 16 deletions.
  1. +5 −16 activerecord/test/cases/serialized_attribute_test.rb
View
21 activerecord/test/cases/serialized_attribute_test.rb
@@ -7,6 +7,11 @@ class SerializedAttributeTest < ActiveRecord::TestCase
MyObject = Struct.new :attribute1, :attribute2
+ def teardown
+ super
+ Topic.serialize("content")
+ end
+
def test_list_of_serialized_attributes
assert_equal %w(content), Topic.serialized_attributes.keys
end
@@ -29,7 +34,6 @@ def test_serialized_attribute
end
def test_serialized_attribute_init_with
- Topic.serialize("content")
topic = Topic.allocate
topic.init_with('attributes' => { 'content' => '--- foo' })
assert_equal 'foo', topic.content
@@ -106,8 +110,6 @@ 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
@@ -116,8 +118,6 @@ def test_should_raise_exception_on_serialized_attribute_with_type_mismatch
assert topic.save
Topic.serialize(:content, Hash)
assert_raise(ActiveRecord::SerializationTypeMismatch) { Topic.find(topic.id).reload.content }
- ensure
- Topic.serialize(:content)
end
def test_serialized_attribute_with_class_constraint
@@ -126,8 +126,6 @@ def test_serialized_attribute_with_class_constraint
topic = Topic.new(:content => settings)
assert topic.save
assert_equal(settings, Topic.find(topic.id).content)
- ensure
- Topic.serialize(:content)
end
def test_serialized_default_class
@@ -140,8 +138,6 @@ def test_serialized_default_class
topic.reload
assert_equal Hash, topic.content.class
assert_equal "MadridRb", topic.content["beer"]
- ensure
- Topic.serialize(:content)
end
def test_serialized_no_default_class_for_object
@@ -150,15 +146,13 @@ def test_serialized_no_default_class_for_object
end
def test_serialized_boolean_value_true
- Topic.serialize(:content)
topic = Topic.new(:content => true)
assert topic.save
topic = topic.reload
assert_equal topic.content, true
end
def test_serialized_boolean_value_false
- Topic.serialize(:content)
topic = Topic.new(:content => false)
assert topic.save
topic = topic.reload
@@ -184,8 +178,6 @@ def dump(thing)
assert topic.save
topic = topic.reload
assert_equal [s].pack('m'), topic.content
- ensure
- Topic.serialize(:content)
end
def test_serialize_with_bcrypt_coder
@@ -207,8 +199,5 @@ def dump(thing)
topic = topic.reload
assert_kind_of BCrypt::Password, topic.content
assert_equal(true, topic.content == password, 'password should equal')
- ensure
- Topic.serialize(:content)
end
-
end

0 comments on commit 4f6120e

Please sign in to comment.