Skip to content

Commit

Permalink
fix: Make the extended rules accessible to the validator (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
relekang committed May 21, 2016
1 parent 93fa869 commit f0118db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/__tests__/extend_tests.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import 'babel-core/register';
import test from 'ava';
import { constant } from 'lodash';

import extend from '../extend';
const newRule = () => {};
const newRule = constant(null);

test('Validator.extend should extend rules suite', t => {
t.plan(2);
const Validator = extend({ newRule });
t.truthy(Validator.rules.newRule);
t.is(Validator.rules.newRule, newRule);
});

test('Validator.extend should include default rules', t => {
t.plan(1);
const Validator = extend({ newRule });
t.truthy(Validator.rules.required);
});

test('Validator.extend should overwrite if the rule has same name', t => {
t.plan(1);
const Validator = extend({ required: newRule });
t.is(Validator.rules.required, newRule);
});

test('Validator.extend should create validator that is able to use the new rules', t => {
const Validator = extend({ newRule });
const result = new Validator({ a: { newRule: true } }).validate(['a'], {});
t.deepEqual(result, {});
});
2 changes: 1 addition & 1 deletion src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class Validator {
}

validateRule(ruleName, field, value, options) {
return rules[ruleName](field, value, options);
return Validator.rules[ruleName](field, value, options);
}
}

Expand Down

0 comments on commit f0118db

Please sign in to comment.