Commit e092862f8d5f052e476056d93fcb2f01eda52145
1 parent
9ec91997
Exists in
master
and in
28 other branches
ActionItem135: adding assert_mandatory to test validates_presence_of
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1100 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
1 changed file
with
9 additions
and
0 deletions
Show diff stats
test/test_helper.rb
... | ... | @@ -89,6 +89,15 @@ class Test::Unit::TestCase |
89 | 89 | assert(!array.include?(element), "<#{array.inspect}> expected to NOT include <#{element.inspect}>") |
90 | 90 | end |
91 | 91 | |
92 | + def assert_mandatory(object, attribute, test_value = 'some random string') | |
93 | + object.send("#{attribute}=", nil) | |
94 | + object.valid? | |
95 | + assert object.errors.invalid?(attribute), "Attribute \"#{attribute.to_s}\" expected to be mandatory." | |
96 | + object.send("#{attribute}=", test_value) | |
97 | + object.valid? | |
98 | + assert !object.errors.invalid?(attribute), "Attribute \"#{attribute.to_s}\" expected to accept value #{test_value.inspect}" | |
99 | + end | |
100 | + | |
92 | 101 | private |
93 | 102 | |
94 | 103 | def uses_host(name) | ... | ... |