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

Changeset 8832

Show
Ignore:
Timestamp:
02/10/08 01:05:54 (5 months ago)
Author:
nzkoz
Message:

2-0-stable: Add tests and documentation for allow_blank. References #10651 [blj]

Merging [8733]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2-0-stable/activerecord/lib/active_record/validations.rb

    r8379 r8832  
    708708      # Configuration options: 
    709709      # * <tt>message</tt> - A custom error message (default is: "is invalid") 
     710      # * <tt>allow_nil</tt> - If set to true, skips this validation if the attribute is null (default is: false) 
     711      # * <tt>allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is: false) 
    710712      # * <tt>with</tt> - The regular expression used to validate the format with (note: must be supplied!) 
    711713      # * <tt>on</tt> Specifies when this validation is active (default is :save, other options :create, :update) 
  • branches/2-0-stable/activerecord/test/validations_test.rb

    r8487 r8832  
    481481    assert_raise(ArgumentError) { Topic.validates_format_of(:title, :content) } 
    482482  end 
     483 
     484  def test_validate_format_with_allow_blank 
     485        Topic.validates_format_of(:title, :with => /^Validation\smacros \w+!$/, :allow_blank=>true) 
     486        assert !Topic.create("title" => "Shouldn't be valid").valid? 
     487        assert Topic.create("title" => "").valid? 
     488        assert Topic.create("title" => nil).valid? 
     489        assert Topic.create("title" => "Validation macros rule!").valid? 
     490        end 
    483491 
    484492  # testing ticket #3142