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 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
21 changes: 18 additions & 3 deletions packages/-ember-data/tests/unit/model-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { computed, get, observer, set } from '@ember/object';
import { guidFor } from '@ember/object/internals';
import { settled } from '@ember/test-helpers';
import { DEBUG } from '@glimmer/env';

import { module, test } from 'qunit';
import { reject, resolve } from 'rsvp';
Expand Down Expand Up @@ -141,9 +142,23 @@ 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>/);
if (DEBUG) {
assert.throws(
() => {
set(record, 'isArchived', true);
},
/Attempted to set 'isArchived' to 'true' on the deleted record <person:1>/,
'Assertion includes more context when in DEBUG'
);
} else {
assert.throws(
() => {
set(record, 'isArchived', true);
},
/Attempted to set 'isArchived' on the deleted record <person:1>/,
"Assertion does not leak the 'value'"
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure how strict we are with dbl vs single quotes.

);
}

currentState = record._internalModel.currentState;

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 @@ -934,7 +934,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