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

Revert assertion on content attribute and add test to prevent regression #7683

Merged
merged 1 commit into from
Aug 30, 2021
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
9 changes: 1 addition & 8 deletions packages/-ember-data/tests/unit/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,15 +757,8 @@ module('unit/model - Model', function (hooks) {
@attr('string')
name;
}
class NativePostWithContent extends Model {
@attr('string')
content;
@attr('string')
name;
}
const PROP_MAP = {
_internalModel: NativePostWithInternalModel,
content: NativePostWithContent,
currentState: NativePostWithCurrentState,
};

Expand Down Expand Up @@ -805,7 +798,7 @@ module('unit/model - Model', function (hooks) {
});
}

['_internalModel', 'content', 'currentState'].forEach(testReservedProperty);
['_internalModel', 'currentState'].forEach(testReservedProperty);

testInDebug('A subclass of Model throws an error when calling create() directly', async function (assert) {
class NativePerson extends Model {}
Expand Down
24 changes: 24 additions & 0 deletions packages/-ember-data/tests/unit/model/attr-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,28 @@ module('unit/model/attr | attr syntax', function (hooks) {

assert.strictEqual(userRecord.name, 'Chris', 'attr is correctly set: name');
});

test('attr can be used to define an attribute with name "content"', async function (assert) {
class Blog extends Model {
@attr content;
}

owner.register('model:blog', Blog);

let BlogModel = store.modelFor('blog');
let attrs = BlogModel.attributes;
assert.true(attrs.has('content'), 'We have the attr: name');

let userRecord = store.push({
data: {
type: 'blog',
id: '1',
attributes: {
content: 'The best blog post',
},
},
});

assert.strictEqual(userRecord.content, 'The best blog post', 'attr is correctly set: content');
});
});
4 changes: 2 additions & 2 deletions packages/model/addon/-private/attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function attr(type, options) {
return computed({
get(key) {
if (DEBUG) {
if (['_internalModel', 'content', 'currentState'].indexOf(key) !== -1) {
if (['_internalModel', 'currentState'].indexOf(key) !== -1) {
throw new Error(
`'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your attr on ${this.constructor.toString()}`
);
Expand All @@ -145,7 +145,7 @@ function attr(type, options) {
},
set(key, value) {
if (DEBUG) {
if (['_internalModel', 'content', 'currentState'].indexOf(key) !== -1) {
if (['_internalModel', 'currentState'].indexOf(key) !== -1) {
throw new Error(
`'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your attr on ${this.constructor.toString()}`
);
Expand Down
4 changes: 2 additions & 2 deletions packages/model/addon/-private/belongs-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function belongsTo(modelName, options) {
return computed({
get(key) {
if (DEBUG) {
if (['_internalModel', 'content', 'recordData', 'currentState'].indexOf(key) !== -1) {
if (['_internalModel', 'recordData', 'currentState'].indexOf(key) !== -1) {
throw new Error(
`'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`
);
Expand Down Expand Up @@ -173,7 +173,7 @@ function belongsTo(modelName, options) {
},
set(key, value) {
if (DEBUG) {
if (['_internalModel', 'content', 'recordData', 'currentState'].indexOf(key) !== -1) {
if (['_internalModel', 'recordData', 'currentState'].indexOf(key) !== -1) {
throw new Error(
`'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`
);
Expand Down
4 changes: 2 additions & 2 deletions packages/model/addon/-private/has-many.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function hasMany(type, options) {
return computed({
get(key) {
if (DEBUG) {
if (['_internalModel', 'content', 'recordData', 'currentState'].indexOf(key) !== -1) {
if (['_internalModel', 'recordData', 'currentState'].indexOf(key) !== -1) {
throw new Error(
`'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your hasMany on ${this.constructor.toString()}`
);
Expand All @@ -193,7 +193,7 @@ function hasMany(type, options) {
},
set(key, records) {
if (DEBUG) {
if (['_internalModel', 'content', 'recordData', 'currentState'].indexOf(key) !== -1) {
if (['_internalModel', 'recordData', 'currentState'].indexOf(key) !== -1) {
throw new Error(
`'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your hasMany on ${this.constructor.toString()}`
);
Expand Down
6 changes: 0 additions & 6 deletions packages/model/addon/-private/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2279,12 +2279,6 @@ if (DEBUG) {
);
}

if (!isDefaultEmptyDescriptor(this, 'content') || this.content !== undefined) {
throw new Error(
`'content' is a reserved property name on instances of classes extending Model. Please choose a different property name for ${this.constructor.toString()}`
);
}

let ourDescriptor = lookupDescriptor(Model.prototype, 'currentState');
let theirDescriptor = lookupDescriptor(this, 'currentState');
let realState = this.___recordState || this._internalModel.currentState;
Expand Down