We have a model with 2 variables. Neither may be nil or non-nil at the
same time. They must pass this truth table:
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
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
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?
“Test Driven Ajax (on Rails)”