From 67824e01a9ab063a85e95aeb4c2d01c9b1a5ac62 Mon Sep 17 00:00:00 2001 From: Andrey Fel Date: Mon, 22 Nov 2021 14:40:32 +0300 Subject: [PATCH] Add failing test case which illustrates the createRecord bug createRecord crashes when a setter which sets an attribute is involved in the createRecord. --- .../tests/integration/store-test.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/-ember-data/tests/integration/store-test.js b/packages/-ember-data/tests/integration/store-test.js index ded98f542e4..eac8ba921c4 100644 --- a/packages/-ember-data/tests/integration/store-test.js +++ b/packages/-ember-data/tests/integration/store-test.js @@ -13,6 +13,8 @@ import JSONAPISerializer from '@ember-data/serializer/json-api'; import RESTSerializer from '@ember-data/serializer/rest'; import deepCopy from '@ember-data/unpublished-test-infra/test-support/deep-copy'; import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in-debug'; +import Model, { attr } from '@ember-data/model'; +import { set } from '@ember/object'; const Person = DS.Model.extend({ name: DS.attr('string'), @@ -1289,3 +1291,26 @@ module('integration/store - queryRecord', function (hooks) { } }); }); + +module('integration/store - createRecord', function (hooks) { + setupTest(hooks); + + test("createRecord doesn't crash when setter is involved", async function (assert) { + class User extends Model { + @attr() email; + + get name() { + return this.email ? this.email.substring(0, this.email.indexOf('@')) :''; + } + + set name(value) { + set(this, 'email', `${value.toLowerCase()}@ember.js`); + } + } + this.owner.register(`model:user`, User); + const store = this.owner.lookup('service:store'); + + const user = store.createRecord('user', { name: 'Robert' }); + assert.strictEqual(user.email, 'robert@ember.js'); + }); +});