Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Don't expose the value of a model's attribute in assertions #7370

Merged
merged 3 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 33 additions & 3 deletions packages/-ember-data/tests/unit/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,13 @@ module('unit/model - Model', function(hooks) {
'the deleted person is not removed from store (no unload called)'
);

assert.expectAssertion(() => {
set(record, 'isArchived', true);
}, /Attempted to set 'isArchived' to 'true' on the deleted record <person:1>/);
assert.expectAssertion(
() => {
set(record, 'isArchived', true);
},
/Attempted to set 'isArchived' on the deleted record <person:1>/,
"Assertion does not leak the 'value'"
);

currentState = record._internalModel.currentState;

Expand All @@ -151,6 +155,32 @@ module('unit/model - Model', function(hooks) {
assert.ok(get(record, 'isArchived') === false, 'The record reflects canonical state');
});

testInDebug('Assertion for dirtying in root.deleted.saved', async function(assert) {
adapter.deleteRecord = () => {
return resolve({ data: null });
};

let record = store.push({
data: {
type: 'person',
id: '1',
attributes: {
isDrugAddict: false,
},
},
});

await record.destroyRecord();

assert.expectAssertion(
() => {
set(record, 'isDrugAddict', true);
},
/Attempted to set 'isDrugAddict' to 'true' on the deleted record <person:1>/,
'Assertion includes more context when in DEBUG'
);
});

test('currentState is accessible when the record is created', async function(assert) {
let record = store.push({
data: {
Expand Down
6 changes: 5 additions & 1 deletion packages/store/addon/-private/system/model/internal-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,11 @@ export default class InternalModel {

setDirtyAttribute(key, value) {
if (this.isDeleted()) {
throw new EmberError(`Attempted to set '${key}' to '${value}' on the deleted record ${this}`);
if (DEBUG) {
throw new EmberError(`Attempted to set '${key}' to '${value}' on the deleted record ${this}`);
} else {
throw new EmberError(`Attempted to set '${key}' on the deleted record ${this}`);
}
}

let currentValue = this.getAttributeValue(key);
Expand Down