Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Assertions for ActiveRecord validations (See related posts)

These two methods will allow you to assert that an ActiveRecord model should or should not have an validation error.

Put them at the bottom of test/test_helper.rb

  def assert_error_on(field, model)
  	assert !model.errors[field.to_sym].nil?, "No validation error on the #{field.to_s} field."
  end
  
  def assert_no_error_on(field, model)
  	assert model.errors[field.to_sym].nil?, "Validation error on #{field.to_s}."
  end

You need to create an account or log in to post comments to this site.


Click here to browse all 5141 code snippets

Related Posts