#6 √ resolved
Luke Francl

PATCH: should_require_acceptance_of

Reported by Luke Francl | December 7th, 2007 @ 02:13 PM

I created a macro to test validates_acceptance_of which I've called should_require_acceptance_of.

Here is the code:

def should_require_acceptance_of(*attributes)
  message = get_options!(attributes, :message)
  message ||= /accepted/
  klass = model_class
    
  attributes.each do |attribute|
    should "require #{attribute} to be accepted" do
      object = klass.new
      assert !object.valid?, "#{klass.name} does not require acceptance of #{attribute}."

      assert object.errors.on(attribute), "#{klass.name} does not require acceptance of #{attribute}."
      assert_contains(object.errors.on(attribute), message)
    end
  end
end

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket