1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Use teardown hook to return the initial state of the object

This commit is contained in:
Rafael Mendonça França 2012-08-26 02:58:12 -03:00
parent 21be1808a0
commit 4f6120e0d5

View file

@ -7,6 +7,11 @@ class SerializedAttributeTest < ActiveRecord::TestCase
MyObject = Struct.new :attribute1, :attribute2 MyObject = Struct.new :attribute1, :attribute2
def teardown
super
Topic.serialize("content")
end
def test_list_of_serialized_attributes def test_list_of_serialized_attributes
assert_equal %w(content), Topic.serialized_attributes.keys assert_equal %w(content), Topic.serialized_attributes.keys
end end
@ -29,7 +34,6 @@ class SerializedAttributeTest < ActiveRecord::TestCase
end end
def test_serialized_attribute_init_with def test_serialized_attribute_init_with
Topic.serialize("content")
topic = Topic.allocate topic = Topic.allocate
topic.init_with('attributes' => { 'content' => '--- foo' }) topic.init_with('attributes' => { 'content' => '--- foo' })
assert_equal 'foo', topic.content assert_equal 'foo', topic.content
@ -106,8 +110,6 @@ class SerializedAttributeTest < ActiveRecord::TestCase
Topic.serialize :content, Hash Topic.serialize :content, Hash
assert Topic.new(:content => nil).save assert Topic.new(:content => nil).save
assert_equal 1, Topic.where(:content => nil).count assert_equal 1, Topic.where(:content => nil).count
ensure
Topic.serialize(:content)
end end
def test_should_raise_exception_on_serialized_attribute_with_type_mismatch def test_should_raise_exception_on_serialized_attribute_with_type_mismatch
@ -116,8 +118,6 @@ class SerializedAttributeTest < ActiveRecord::TestCase
assert topic.save assert topic.save
Topic.serialize(:content, Hash) Topic.serialize(:content, Hash)
assert_raise(ActiveRecord::SerializationTypeMismatch) { Topic.find(topic.id).reload.content } assert_raise(ActiveRecord::SerializationTypeMismatch) { Topic.find(topic.id).reload.content }
ensure
Topic.serialize(:content)
end end
def test_serialized_attribute_with_class_constraint def test_serialized_attribute_with_class_constraint
@ -126,8 +126,6 @@ class SerializedAttributeTest < ActiveRecord::TestCase
topic = Topic.new(:content => settings) topic = Topic.new(:content => settings)
assert topic.save assert topic.save
assert_equal(settings, Topic.find(topic.id).content) assert_equal(settings, Topic.find(topic.id).content)
ensure
Topic.serialize(:content)
end end
def test_serialized_default_class def test_serialized_default_class
@ -140,8 +138,6 @@ class SerializedAttributeTest < ActiveRecord::TestCase
topic.reload topic.reload
assert_equal Hash, topic.content.class assert_equal Hash, topic.content.class
assert_equal "MadridRb", topic.content["beer"] assert_equal "MadridRb", topic.content["beer"]
ensure
Topic.serialize(:content)
end end
def test_serialized_no_default_class_for_object def test_serialized_no_default_class_for_object
@ -150,7 +146,6 @@ class SerializedAttributeTest < ActiveRecord::TestCase
end end
def test_serialized_boolean_value_true def test_serialized_boolean_value_true
Topic.serialize(:content)
topic = Topic.new(:content => true) topic = Topic.new(:content => true)
assert topic.save assert topic.save
topic = topic.reload topic = topic.reload
@ -158,7 +153,6 @@ class SerializedAttributeTest < ActiveRecord::TestCase
end end
def test_serialized_boolean_value_false def test_serialized_boolean_value_false
Topic.serialize(:content)
topic = Topic.new(:content => false) topic = Topic.new(:content => false)
assert topic.save assert topic.save
topic = topic.reload topic = topic.reload
@ -184,8 +178,6 @@ class SerializedAttributeTest < ActiveRecord::TestCase
assert topic.save assert topic.save
topic = topic.reload topic = topic.reload
assert_equal [s].pack('m'), topic.content assert_equal [s].pack('m'), topic.content
ensure
Topic.serialize(:content)
end end
def test_serialize_with_bcrypt_coder def test_serialize_with_bcrypt_coder
@ -207,8 +199,5 @@ class SerializedAttributeTest < ActiveRecord::TestCase
topic = topic.reload topic = topic.reload
assert_kind_of BCrypt::Password, topic.content assert_kind_of BCrypt::Password, topic.content
assert_equal(true, topic.content == password, 'password should equal') assert_equal(true, topic.content == password, 'password should equal')
ensure
Topic.serialize(:content)
end end
end end