Created
May 12, 2010 14:38
-
-
Save mallain/398660 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate generic tests for instance and unsaved objects | |
# object as String | |
# uniqueness_attr as Array | |
# model_generic_tests("account", %w(name)) | |
def model_generic_tests(object, uniqueness_attr=[]) | |
context "A #{object} instance" do | |
setup do | |
@object = Factory(object.to_sym) | |
end | |
should "return its name" do | |
assert @object.name | |
end | |
uniqueness_attr.each do |attr| | |
model_uniqueness_tests(@object, attr) | |
end | |
should "not save #{object} without name" do | |
@object.name = nil | |
assert [email protected] | |
end | |
end | |
context "A unsaved #{object} instance" do | |
setup do | |
@object = Factory.build(object.to_sym, :name => nil) | |
end | |
should "not save #{object} without name" do | |
assert [email protected] | |
end | |
end | |
end | |
# Generate uniqueness_tests | |
# object as String | |
# attribute as String | |
# model_uniqueness_tests("account", "name") | |
def model_uniqueness_tests(object, attribute) | |
should "have unique #{attribute}" do | |
object = Factory(object.to_sym, attribute.to_sym => "unique") | |
object_not_unique = Factory.build(object.to_sym, attribute.to_sym => "unique") | |
assert !object_not_unique.save | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment