Permalink
Browse files

presence should not validate blank values

Fixes #304
  • Loading branch information...
1 parent cf0738a commit d5e719fdad0e4bfa9ac907efde7284ba7d580532 Kamil Tusznio committed Feb 10, 2012
Showing with 7 additions and 4 deletions.
  1. +1 −1 lib/batman.js
  2. +1 −1 src/batman.coffee
  3. +5 −2 tests/batman/model/validations_test.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -3276,7 +3276,7 @@ Validators = Batman.Validators = [
@options 'presence'
validateEach: (errors, record, key, callback) ->
value = record.get(key)
- if @options.presence and !value?
+ if @options.presence && (!value? || value is '')
errors.add key, @format(key, 'blank')
callback()
]
@@ -28,7 +28,7 @@ validationsTestSuite = ->
equal errors.length, 3
QUnit.start()
- asyncTest "presence", 2, ->
+ asyncTest "presence", 3, ->
class Product extends Batman.Model
@validate 'name', presence: yes
@@ -38,7 +38,10 @@ validationsTestSuite = ->
p.unset 'name'
p.validate (result, errors) ->
ok !result
- QUnit.start()
+ p.set 'name', ''
+ p.validate (result, errors) ->
+ ok !result
+ QUnit.start()
asyncTest "presence and length", 4, ->
class Product extends Batman.Model

0 comments on commit d5e719f

Please sign in to comment.