Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion addon/validators/confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ export default function validateConfirmation(options = {}) {
// Combine the changes on top of the content so that we evaluate against both default values
// and valid changes. `changes` only has valid changes that have been made and won't include
// default values
let model = Object.assign({}, content, changes);
let model;

if ('_internalModel' in content) {
const contentHash = content._internalModel.createSnapshot().attributes();
model = Object.assign({}, contentHash, changes);
} else {
model = Object.assign({}, content, changes);
}

let result = evValidateConfirmation(newValue, options, model, key);
return result === true ? true : buildMessage(key, result);
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/validators/confirmation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,27 @@ test('It looks for default values as well as "changes" values', function (assert
);
assert.true(validator(key, password, undefined, {}, content));
});

test('It handles ember data models when looking for default values as well as "changes" values', function (assert) {
assert.expect(2);

let password = '1234567';
let content = {
_internalModel: {
createSnapshot: () => ({
attributes: () => ({
password,
}),
}),
},
};
let key = 'passwordConfirmation';
let opts = { on: 'password' };
let validator = validateConfirmation(opts);

assert.strictEqual(
validator(key, 'foo', undefined, {}, content),
buildMessage(key, { type: 'confirmation', context: opts })
);
assert.true(validator(key, password, undefined, {}, content));
});