Skip to content

Commit

Permalink
Merge pull request #715 from kprasadpvv/updateValidatorsAndRequiredMo…
Browse files Browse the repository at this point in the history
…dule

Updated ember required and ember validators packages
  • Loading branch information
MelSumner committed Aug 17, 2022
2 parents d6c95d7 + e9468ef commit 1989855
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 44 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## v4.0.0

- [[Major]: Remove Moment and Node 10](https://github.com/offirgolan/ember-validators/pull/100);
- Remove Node 10 minimum requirement in favor of Node 12
- removed custom String 'now' argument.
- remove momentjs
- Remove `precision` argument. If you need to compare based on precision, you can use the Intl.DateTimeFormat [APIs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#using_options) to hone in on the comparison - `{ year: 'numeric' }`
- Added `locale` option. Defaults to en-us when creating date times using `Intl.DateTimeFormat` API.

## v4.0.0-beta.10

- [#668](https://github.com/adopted-ember-addons/ember-cp-validations/pull/668) Support Ember 3.13 [@jrjohnson](https://github.com/jrjohnson)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"ember-cli-babel": "^7.26.10",
"ember-require-module": "^0.4.0",
"ember-validators": "^3.0.1"
"ember-validators": "^4.1.1"
},
"devDependencies": {
"@ember/optional-features": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/models/user-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Validations = buildValidations(
validators: [
validator('presence', true),
validator('date', {
before: 'now',
before: new Date(),
after: computed(function () {
return moment().subtract(120, 'years').format('M/D/YYYY');
}).volatile(),
Expand Down
72 changes: 44 additions & 28 deletions tests/unit/validators/date-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module('Unit | Validator | date', function (hooks) {

options = {
allowBlank: true,
before: '1/1/2015',
before: new Date('1/1/2015'),
};

builtOptions = validator.buildOptions(options);
Expand All @@ -33,7 +33,7 @@ module('Unit | Validator | date', function (hooks) {
assert.true(message);

message = validator.validate('1/1/2016', builtOptions.toObject());
assert.equal(message, 'This field must be before Jan 1st, 2015');
assert.equal(message, 'This field must be before January 1, 2015');
});

test('valid date', function (assert) {
Expand All @@ -54,15 +54,18 @@ module('Unit | Validator | date', function (hooks) {
assert.expect(2);

options = {
format: 'DD/M/YYYY',
format: { year: 'numeric', month: 'numeric', day: '2-digit' },
};

builtOptions = validator.buildOptions(options);

message = validator.validate('27/3/15', builtOptions.toObject());
assert.equal(message, 'This field must be in the format of DD/M/YYYY');
assert.equal(message, 'This field must be a valid date');

message = validator.validate('27/3/2015', builtOptions.toObject());
message = validator.validate(
new Date('3/27/2015'),
builtOptions.toObject()
);
assert.true(message);
});

Expand Down Expand Up @@ -90,17 +93,21 @@ module('Unit | Validator | date', function (hooks) {
builtOptions = validator.buildOptions(options);

message = validator.validate('1/1/2016', builtOptions.toObject());
assert.equal(message, 'This field must be before Jan 1st, 2015');
assert.equal(message, 'This field must be before January 1, 2015');

message = validator.validate('1/1/2014', builtOptions.toObject());
assert.true(message);
});

test('before now', function (assert) {
assert.expect(2);
let now = moment().format('MMM Do, YYYY');
let now = new Intl.DateTimeFormat('en', { dateStyle: 'long' }).format(
new Date('1/1/3015')
);
options = {
before: 'now',
before: new Intl.DateTimeFormat('en', { dateStyle: 'long' }).format(
new Date('1/1/3015')
),
};

builtOptions = validator.buildOptions(options);
Expand All @@ -122,7 +129,7 @@ module('Unit | Validator | date', function (hooks) {
builtOptions = validator.buildOptions(options);

message = validator.validate('1/1/2016', builtOptions.toObject());
assert.equal(message, 'This field must be on or before Jan 1st, 2015');
assert.equal(message, 'This field must be on or before January 1, 2015');

message = validator.validate('1/1/2014', builtOptions.toObject());
assert.true(message);
Expand All @@ -133,20 +140,25 @@ module('Unit | Validator | date', function (hooks) {

test('before now or on', function (assert) {
assert.expect(3);
let now = moment().format('MMM Do, YYYY');
let now = new Date();
options = {
onOrBefore: 'now',
onOrBefore: new Date(),
};

builtOptions = validator.buildOptions(options);

message = validator.validate('1/1/3015', builtOptions.toObject());
assert.equal(message, `This field must be on or before ${now}`);
message = validator.validate(new Date('1/1/3015'), builtOptions.toObject());
assert.equal(
message,
`This field must be on or before ${new Intl.DateTimeFormat('en', {
dateStyle: 'long',
}).format(now)}`
);

message = validator.validate('1/1/2014', builtOptions.toObject());
message = validator.validate(new Date('1/1/2014'), builtOptions.toObject());
assert.true(message);

message = validator.validate('now', builtOptions.toObject());
message = validator.validate(now, builtOptions.toObject());
assert.true(message);
});

Expand All @@ -162,9 +174,11 @@ module('Unit | Validator | date', function (hooks) {
];

assert.expect(precisions.length * 3 - 1);
let now = moment(new Date('2013-02-08T09:30:26'));
let now = new Date('2013-02-08T09:30:26');
let dateString = now.toString();
let nowMessage = now.format('MMM Do, YYYY');
let nowMessage = new Intl.DateTimeFormat('en', {
dateStyle: 'long',
}).format(now);

for (let i = 0; i < precisions.length; i++) {
let precision = precisions[i];
Expand Down Expand Up @@ -199,23 +213,23 @@ module('Unit | Validator | date', function (hooks) {
assert.expect(2);

options = {
after: '1/1/2015',
after: new Date('1/1/2015'),
};

builtOptions = validator.buildOptions(options);

message = validator.validate('1/1/2014', builtOptions.toObject());
assert.equal(message, 'This field must be after Jan 1st, 2015');
assert.equal(message, 'This field must be after January 1, 2015');

message = validator.validate('1/1/2016', builtOptions.toObject());
assert.true(message);
});

test('after now', function (assert) {
assert.expect(2);
let now = moment().format('MMM Do, YYYY');
let now = new Intl.DateTimeFormat('en', { dateStyle: 'long' }).format();
options = {
after: 'now',
after: new Date(),
};

builtOptions = validator.buildOptions(options);
Expand All @@ -231,13 +245,13 @@ module('Unit | Validator | date', function (hooks) {
assert.expect(3);

options = {
onOrAfter: '1/1/2015',
onOrAfter: new Date('1/1/2015'),
};

builtOptions = validator.buildOptions(options);

message = validator.validate('1/1/2014', builtOptions.toObject());
assert.equal(message, 'This field must be on or after Jan 1st, 2015');
assert.equal(message, 'This field must be on or after January 1, 2015');

message = validator.validate('1/1/2016', builtOptions.toObject());
assert.true(message);
Expand All @@ -248,9 +262,9 @@ module('Unit | Validator | date', function (hooks) {

test('after now or on', function (assert) {
assert.expect(3);
let now = moment().format('MMM Do, YYYY');
let now = new Intl.DateTimeFormat('en', { dateStyle: 'long' }).format();
options = {
onOrAfter: 'now',
onOrAfter: new Intl.DateTimeFormat('en', { dateStyle: 'long' }).format(),
precision: 'second',
};

Expand All @@ -262,7 +276,7 @@ module('Unit | Validator | date', function (hooks) {
message = validator.validate('1/1/3015', builtOptions.toObject());
assert.true(message);

message = validator.validate('now', builtOptions.toObject());
message = validator.validate(now, builtOptions.toObject());
assert.true(message);
});

Expand All @@ -278,9 +292,11 @@ module('Unit | Validator | date', function (hooks) {
];

assert.expect(precisions.length * 3 - 1);
let now = moment(new Date('2013-02-08T09:30:26'));
let now = new Date('2013-02-08T09:30:26');
let dateString = now.toString();
let nowMessage = now.format('MMM Do, YYYY');
let nowMessage = new Intl.DateTimeFormat('en', {
dateStyle: 'long',
}).format(now);

for (let i = 0; i < precisions.length; i++) {
let precision = precisions[i];
Expand Down
21 changes: 7 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6071,7 +6071,7 @@ ember-cli-babel-plugin-helpers@^1.0.0, ember-cli-babel-plugin-helpers@^1.1.1:
resolved "https://registry.yarnpkg.com/ember-cli-babel-plugin-helpers/-/ember-cli-babel-plugin-helpers-1.1.1.tgz#5016b80cdef37036c4282eef2d863e1d73576879"
integrity sha512-sKvOiPNHr5F/60NLd7SFzMpYPte/nnGkq/tMIfXejfKHIhaiIkYFqX8Z9UFTKWLLn+V7NOaby6niNPZUdvKCRw==

ember-cli-babel@^6.6.0, ember-cli-babel@^6.9.2:
ember-cli-babel@^6.6.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/ember-cli-babel/-/ember-cli-babel-6.18.0.tgz#3f6435fd275172edeff2b634ee7b29ce74318957"
integrity sha512-7ceC8joNYxY2wES16iIBlbPSxwKDBhYwC8drU3ZEvuPDMwVv1KzxCNu1fvxyFEBWhwaRNTUxSCsEVoTd9nosGA==
Expand Down Expand Up @@ -6663,13 +6663,6 @@ ember-qunit@^5.1.5:
silent-error "^1.1.1"
validate-peer-dependencies "^1.2.0"

ember-require-module@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/ember-require-module/-/ember-require-module-0.3.0.tgz#65aff7908b5b846467e4526594d33cfe0c23456b"
integrity sha512-rYN4YoWbR9VlJISSmx0ZcYZOgMcXZLGR7kdvp3zDerjIvYmHm/3p+K56fEAYmJILA6W4F+cBe41Tq2HuQAZizA==
dependencies:
ember-cli-babel "^6.9.2"

ember-require-module@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/ember-require-module/-/ember-require-module-0.4.0.tgz#2f86bae244f70c3d4cb8b9ef8abbd617e7a95218"
Expand Down Expand Up @@ -6825,13 +6818,13 @@ ember-try@^1.4.0:
rsvp "^4.7.0"
walk-sync "^1.1.3"

ember-validators@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/ember-validators/-/ember-validators-3.0.1.tgz#9e0f7ed4ce6817aa05f7d46e95a0267c03f1f043"
integrity sha512-GbvvECDG9N7U+4LXxPWNgiSnGbOzgvGBIxtS4kw2uyEIy7kymtgszhpSnm8lGMKYnhCKBqFingh8qnVKlCi0lg==
ember-validators@^4.1.1:
version "4.1.2"
resolved "https://registry.yarnpkg.com/ember-validators/-/ember-validators-4.1.2.tgz#e70c0ac80f6b66c8288ffe5860c96e81bf621691"
integrity sha512-aNyJW52eWvWhdcRfnb0pGYSDuQU4i4XjA682aDG1ocmz7eUEDw7bXXvKEYGtVsPTtPLtUPvTtaH9mXKpMG+1xA==
dependencies:
ember-cli-babel "^6.9.2"
ember-require-module "^0.3.0"
"@embroider/macros" "^1.0.0"
ember-cli-babel "^7.26.11"

emit-function@0.0.2:
version "0.0.2"
Expand Down

0 comments on commit 1989855

Please sign in to comment.