| | 38 | |
|---|
| | 39 | # Bulk-test multiple values of an attribute (from |
|---|
| | 40 | # http://matthall.wordpress.com/2007/11/21/helper-for-testing-validation-in-unit-tests/) |
|---|
| | 41 | |
|---|
| | 42 | def validation_tester(test_object, attribute_name, valid_values, invalid_values) |
|---|
| | 43 | |
|---|
| | 44 | invalid_values.each do |val| |
|---|
| | 45 | test_object.[]=(attribute_name, val) |
|---|
| | 46 | assert !test_object.save, "Object should be valid with #{attribute_name} should be valid: #{test_object.[](attribute_name)}" |
|---|
| | 47 | assert !test_object.valid? |
|---|
| | 48 | assert test_object.errors.invalid?(attribute_name) |
|---|
| | 49 | end |
|---|
| | 50 | |
|---|
| | 51 | valid_values.each do |val| |
|---|
| | 52 | test_object.[]=(attribute_name, val) |
|---|
| | 53 | assert test_object.save, "Object should be valid with #{attribute_name} should be valid: #{test_object.[](attribute_name)}" |
|---|
| | 54 | assert test_object.valid? |
|---|
| | 55 | assert !test_object.errors.invalid?(attribute_name) |
|---|
| | 56 | end |
|---|
| | 57 | |
|---|
| | 58 | end |
|---|
| | 59 | |
|---|