Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8733

Show
Ignore:
Timestamp:
01/26/08 05:08:20 (9 months ago)
Author:
nzkoz
Message:

Add tests and documentation for allow_blank. Closes #10651 [blj]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/validations.rb

    r8664 r8733  
    685685      # Configuration options: 
    686686      # * <tt>message</tt> - A custom error message (default is: "is invalid") 
     687      # * <tt>allow_nil</tt> - If set to true, skips this validation if the attribute is null (default is: false) 
     688      # * <tt>allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is: false) 
    687689      # * <tt>with</tt> - The regular expression used to validate the format with (note: must be supplied!) 
    688690      # * <tt>on</tt> Specifies when this validation is active (default is :save, other options :create, :update) 
  • trunk/activerecord/test/cases/validations_test.rb

    r8681 r8733  
    488488 
    489489    assert_raise(ArgumentError) { Topic.validates_format_of(:title, :content) } 
     490  end 
     491 
     492  def test_validate_format_with_allow_blank 
     493    Topic.validates_format_of(:title, :with => /^Validation\smacros \w+!$/, :allow_blank=>true) 
     494    assert !Topic.create("title" => "Shouldn't be valid").valid? 
     495    assert Topic.create("title" => "").valid? 
     496    assert Topic.create("title" => nil).valid? 
     497    assert Topic.create("title" => "Validation macros rule!").valid? 
    490498  end 
    491499