Railsters:
We have a model with 2 variables. Neither may be nil or non-nil at the
same time. They must pass this truth table:
def test_mutually_exclude
assert_equal false, Model.new.save
assert_equal false, Model.new(:thing1 => 2, :thing2 => 1).save
assert_equal true, Model.new(:thing1 => 2).save
assert_equal true, Model.new(:thing2 => 1).save
end
thing1 and thing2 default to nil. We need only one Thing at a time,
and having them both together causes trouble.
What’s the minimum set of validates_presence_of or similar validators
required to enforce this? Note the error message itself is not
important.
We have it down to 4 lines, which seems absurdly excessive for Rails,
so what are we missing?
Even better, could someone write validates_mutual_exclusivity, in the
usual 2 lines of code or less?
–
Phlip
http://www.oreilly.com/catalog/9780596510657/
“Test Driven Ajax (on Rails)”
assert_xpath, assert_javascript, & assert_ajax