Add validation to subclass in tests to avoid polluting parent class

These two tests currently both define acceptance validators on the same
class, Topic. This means that in either one test or the other, there are
not one but *two* instances of the LazilyDefineAttributes module
builder in the class' ancestors, which can result in unpredictable
results.

Subclassing Topic in each test avoids conflicts.
上级 cc6bff3d
......@@ -145,15 +145,17 @@ def test_throw_away_typing
end
def test_validates_acceptance_of_with_undefined_attribute_methods
Topic.validates_acceptance_of(:approved)
topic = Topic.new(approved: true)
Topic.undefine_attribute_methods
klass = Class.new(Topic)
klass.validates_acceptance_of(:approved)
topic = klass.new(approved: true)
klass.undefine_attribute_methods
assert topic.approved
end
def test_validates_acceptance_of_as_database_column
Topic.validates_acceptance_of(:approved)
topic = Topic.create("approved" => true)
klass = Class.new(Topic)
klass.validates_acceptance_of(:approved)
topic = klass.create("approved" => true)
assert topic["approved"]
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册