Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion addon/validators/date.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isEmpty } from '@ember/utils';

import buildMessage from 'ember-changeset-validations/utils/validation-errors';
import withDefaults from 'ember-changeset-validations/utils/with-defaults';
import toDate from 'ember-changeset-validations/utils/to-date';
Expand All @@ -19,7 +21,7 @@ export default function validateDate(options = {}) {
let { before, onOrBefore, after, onOrAfter, message } = options;
let type = 'date';

if (allowBlank && (typeof value === 'undefined' || value === null)) {
if (allowBlank && isEmpty(value)) {
return true;
}

Expand Down
4 changes: 0 additions & 4 deletions addon/validators/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import evValidateNumber from 'ember-validators/number';
export default function validateNumber(options = {}) {
options = withDefaults(options, { allowString: true, allowNone: false });

if (options.allowBlank) {
options.allowNone = true;
}
Comment on lines -8 to -10
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this one as it is not useful: isEmpty is basically isNone but with a larger scope, hence allowBlank has the same scope as allowNone but larger 🤷 (cf.)


return (key, value) => {
let result = evValidateNumber(value, options, null, key);
return result === true ? true : buildMessage(key, result);
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/validators/confirmation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ module('Unit | Validator | confirmation', function () {
let options = { allowBlank: true, on: 'foo' };
let validator = validateConfirmation(options);

assert.true(validator(key, ''), 'Empty string is accepted');
assert.true(validator(key, null), 'null is accepted');
assert.true(validator(key, undefined), 'undefined is accepted');
assert.true(validator(key, ''), 'empty string is accepted');
});
});

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/validators/date-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module('Unit | Validator | date', function () {

assert.true(validator(key, null), 'null is allowed');
assert.true(validator(key, undefined), 'undefined is allowed');
assert.true(validator(key, 123), 'number value is is allowed');
assert.true(validator(key, ''), 'empty string is allowed');
assert.true(validator(key, 123), 'number value is allowed');

assert.equal(
validator(key, '1992-03-30'),
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/validators/exclusion-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ module('Unit | Validator | exclusion', function () {
let options = { allowBlank: true };
let validator = validateExclusion(options);

assert.true(validator(key, ''), 'Empty string is accepted');
assert.true(validator(key, null), 'null is accepted');
assert.true(validator(key, undefined), 'undefined is accepted');
assert.true(validator(key, ''), 'empty string is accepted');
});
});
4 changes: 3 additions & 1 deletion tests/unit/validators/format-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ module('Unit | Validator | format', function () {
let options = { allowBlank: true };
let validator = validateFormat(options);

assert.true(validator(key, ''));
assert.true(validator(key, null), 'null is accepted');
assert.true(validator(key, undefined), 'undefined is accepted');
assert.true(validator(key, ''), 'empty string is accepted');
});

test('it accepts a `type` option', function (assert) {
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/validators/inclusion-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ module('Unit | Validator | inclusion', function () {
let options = { allowBlank: true };
let validator = validateInclusion(options);

assert.true(validator(key, ''), 'Empty string is accepted');
assert.true(validator(key, null), 'null is accepted');
assert.true(validator(key, undefined), 'undefined is accepted');
assert.true(validator(key, ''), 'empty string is accepted');
});
});