Skip to content

Commit

Permalink
Updated example for 'matches'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbuttery committed Mar 24, 2014
1 parent 668c806 commit ccb323a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ exports['in'] = function(values) {

/**
* Check if one field matches another
* @param {String} Value of field
* @param {String} field Field to match
* @param {Object} attributes All of the data
* @param attr {String} - name of field to validate - e.g "ConfirmNewPassword"
* @param val {String} input value of field to compare match - e.g data.NewPassword
* @param data {Object} the whole data object (model)
* @return {Boolean}
*/
exports.matches = function(attr) {
Expand Down
17 changes: 11 additions & 6 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,17 @@ describe('Validation Methods', function(){
});

it('should validate the if a value matches another value', function(){
var fn = methods.matches('foo');
fn('bar', { foo: 'bar' }).should.be.true;
fn('bar', { foo: 'foo' }).should.be.false;
fn(null, { foo: 'bar' }).should.be.false;
fn('', { foo: 'bar' }).should.be.false;
fn(undefined, { foo: 'bar' }).should.be.false;
// model
var data = {
NewPassword: 'eggplant' // < the value we're comparing to
};

var fn = methods.matches('NewPassword');
fn('eggplant', data).should.be.true;
fn('celery', data).should.be.false;
fn(null, data).should.be.false;
fn('', data).should.be.false;
fn(undefined, data).should.be.false;
});

it('should validate if a value is made up of only numbers or not', function(){
Expand Down

0 comments on commit ccb323a

Please sign in to comment.