Merge pull request #195 from anatoliychakkaev/master

Test case for uniqueness validation
This commit is contained in:
Anatoliy Chakkaev 2013-01-21 09:48:52 -08:00
commit 71e1b5159e
1 changed files with 24 additions and 0 deletions

View File

@ -88,3 +88,27 @@ it 'should allow to skip validations', (test) ->
test.done() test.done()
it 'should validate uniqueness', (test) ->
Airport = schema.define 'Airport', code: String, city: String
Airport.validatesUniquenessOf 'code'
bkk = new Airport code: 'BKK', city: 'Bangkok'
bkk.isValid (valid) ->
test.ok valid
bkk.save ->
dmk = new Airport code: 'DMK', city: 'Bangkok'
dmk.isValid (valid) ->
test.ok valid
dmk.save ->
dmk.city = 'Bangkok, Don Muang'
dmk.isValid (valid) ->
test.ok valid
dmk.save ->
dmk.code = 'BKK'
dmk.isValid (valid) ->
test.ok !valid
dmk.code = 'DMK'
dmk.isValid (valid) ->
test.ok valid
test.done()