Skip to content

Commit

Permalink
Merge pull request #78 from lotus/ignore-blank-values-for-format-vali…
Browse files Browse the repository at this point in the history
…dation

Ignore blank values for format validation
  • Loading branch information
jodosha committed Oct 29, 2015
2 parents a893bbb + ef3bb91 commit f0b9020
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/lotus/validations/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def acceptance
# @since 0.2.0
# @api private
def format
_validate(__method__) {|matcher| @value.to_s.match(matcher) }
_validate(__method__) {|matcher| @value.to_s.match(matcher) } unless blank_value?
end

# Validates inclusion of the value in the defined collection.
Expand Down
8 changes: 8 additions & 0 deletions test/format_validation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
validator.errors.must_be_empty
end

# Bug https://github.com/lotus/validations/issues/77
it "is valid if has blank value" do
validator = FormatValidatorTest.new({name: ''})

validator.valid?.must_equal true
validator.errors.must_be_empty
end

it "is valid if it respects given formats" do
validator = FormatValidatorTest.new({name: 'Luca', age: '32'})

Expand Down

0 comments on commit f0b9020

Please sign in to comment.