-
Notifications
You must be signed in to change notification settings - Fork 9
isPlainObject/isArray validation, falsy values for presence validation, node 0.10.x support when running tests #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nettofarah
merged 4 commits into
nettofarah:master
from
bjrmatos:isPlainObject-isArray-validation
Mar 10, 2016
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4037d11
node 0.10.x support when running tests
bjrmatos 8e431b5
add isPlainObject/isArray validation resolves #9
bjrmatos efb89dc
take into account falsy values in presence validation resolves #12
bjrmatos b09cd5d
add isPlainObject/isArray to docs
bjrmatos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,7 @@ describe('Assertions', function() { | |
|
|
||
| var expectedError = { | ||
| field: 'email_address', | ||
| message: `"email_address" should look like an email address` | ||
| message: '"email_address" should look like an email address' | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great catch |
||
| } | ||
|
|
||
| assert.equal(1, validationError.errors.length); | ||
|
|
@@ -61,7 +61,7 @@ describe('Assertions', function() { | |
| email('email_address') | ||
| ]); | ||
| } catch(validationError) { | ||
| var message = `"email_address" should look like an email address`; | ||
| var message = '"email_address" should look like an email address'; | ||
|
|
||
| assert.deepEqual([message], validationError.messages); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,47 @@ describe('Validation', function() { | |
| }); | ||
| }); | ||
|
|
||
| describe('presence validation', function() { | ||
| var params; | ||
| var presence = validator.presence; | ||
|
|
||
| before(function() { | ||
| params = {} | ||
| }); | ||
|
|
||
| it('allows falsy values that are not null or undefined', function() { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. amazing! |
||
| params = { | ||
| foo: 0, | ||
| bar: false, | ||
| baz: '' | ||
| }; | ||
|
|
||
| var validation = validate(params, [ | ||
| presence('foo'), | ||
| presence('bar'), | ||
| presence('baz') | ||
| ]); | ||
|
|
||
| assert(validation.valid); | ||
| assert(validation.errors.length == 0); | ||
| }); | ||
|
|
||
| it('fails when fields are null or undefined', function() { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. <3 |
||
| params = { | ||
| foo: null, | ||
| bar: undefined | ||
| }; | ||
|
|
||
| var validation = validate(params, [ | ||
| presence('foo'), | ||
| presence('bar') | ||
| ]); | ||
|
|
||
| assert(!validation.valid); | ||
| assert(validation.errors.length == 2); | ||
| }); | ||
| }); | ||
|
|
||
| describe('optional validation', function() { | ||
| var params; | ||
| var optional = validator.optional; | ||
|
|
@@ -252,6 +293,13 @@ describe('Validation Helpers', function() { | |
| f(v.isAlphanumeric('i')({ i: '#@' })); | ||
| }); | ||
|
|
||
| it('isArray', function() { | ||
| t(v.isArray('i')({ i: [1, 2, 3] })); | ||
| f(v.isArray('i')({ i: 'bla' })); | ||
|
|
||
| m(v.isArray('i')({ i: 'test' }), '"i" should be an array'); | ||
| }); | ||
|
|
||
| it('isCreditCard', function() { | ||
| t(v.isCreditCard('i')({ i: '375556917985515' })); | ||
| f(v.isCreditCard('i')({ i: '123123' })); | ||
|
|
@@ -283,4 +331,10 @@ describe('Validation Helpers', function() { | |
| f(v.uuid('i')({ i: 'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3' })); | ||
| f(v.uuid('i')({ i: 'bla' })); | ||
| }); | ||
|
|
||
| it('isPlainObject', function() { | ||
| t(v.isPlainObject('i')({ i: { foo: true } })); | ||
| f(v.isPlainObject('i')({ i: 'bla' })); | ||
| m(v.isPlainObject('i')({ i: 'test' }), '"i" should be a plain object'); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great catch!