Forum: Ruby on Rails Can't see why my asseet fails in unit test

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jim A. (Guest)
on 2007-03-07 09:34
(Received via mailing list)
I have the following model

class Advertisement < ActiveRecord::Base
  # presence validation code
  validates_presence_of :job_title,

  #length validation code
  validates_length_of :job_title, :maximum => 80
  validates_length_of :short_description, :maximum => 150
  validates_length_of :internal_ref, :allow_nil => true, :maximum =>
  validates_length_of :contact_email, :maximum => 80
  validates_length_of :contact_details, :allow_nil => true, :maximum
=> 200

  # numerical validation code
  validates_numericality_of :min_salary, :only_integer => false
  validates_numericality_of :max_salary, :allow_nil =>
true, :only_integer => false

  # validate the format of data
  validates_format_of :contact_email,
                     :with => /\A[\w\._%-]+@[\w\.-]+\.[a-zA-Z]
                     :message => "is an invalid email address"


When I execute the following test case the  second assert fails.

  def test_invalid_ad_with_no_attrs
    ad =
    assert !ad.valid?
    assert ad.errors.invalid?(:min_salary)

Can anyone shed some light on this?

This topic is locked and can not be replied to.