Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
2-0-stable: Add tests and documentation for allow_blank. References #…
…10651 [blj]

Merging [8733]


git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/2-0-stable@8832 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
NZKoz committed Feb 10, 2008
1 parent 75aef09 commit 0f225c0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activerecord/lib/active_record/validations.rb
Expand Up @@ -707,6 +707,8 @@ def validates_uniqueness_of(*attr_names)
#
# Configuration options:
# * <tt>message</tt> - A custom error message (default is: "is invalid")
# * <tt>allow_nil</tt> - If set to true, skips this validation if the attribute is null (default is: false)
# * <tt>allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is: false)
# * <tt>with</tt> - The regular expression used to validate the format with (note: must be supplied!)
# * <tt>on</tt> Specifies when this validation is active (default is :save, other options :create, :update)
# * <tt>if</tt> - Specifies a method, proc or string to call to determine if the validation should
Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/validations_test.rb
Expand Up @@ -481,6 +481,14 @@ def test_validate_format
assert_raise(ArgumentError) { Topic.validates_format_of(:title, :content) }
end

def test_validate_format_with_allow_blank
Topic.validates_format_of(:title, :with => /^Validation\smacros \w+!$/, :allow_blank=>true)
assert !Topic.create("title" => "Shouldn't be valid").valid?
assert Topic.create("title" => "").valid?
assert Topic.create("title" => nil).valid?
assert Topic.create("title" => "Validation macros rule!").valid?
end

# testing ticket #3142
def test_validate_format_numeric
Topic.validates_format_of(:title, :content, :with => /^[1-9][0-9]*$/, :message => "is bad data")
Expand Down

0 comments on commit 0f225c0

Please sign in to comment.