From 68fab3d1a356b16b0ab0e47f18df921295316724 Mon Sep 17 00:00:00 2001 From: Manuel Wiedenmann Date: Sun, 4 Sep 2022 23:02:55 +0200 Subject: [PATCH] Always overwrite serializeBelongsTo and serializeHasMany --- .eslintrc.js | 1 - addon/serializers/serializer.js | 30 +++++------------------------- tests/unit/models/post-test.js | 8 ++------ 3 files changed, 7 insertions(+), 32 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 4d5aa1a..4867cf1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -26,7 +26,6 @@ module.exports = { 'ember/no-mixins': 'off', 'ember/no-new-mixins': 'off', 'ember/no-string-prototype-extensions': 'off', - // 'ember/use-ember-data-rfc-395-imports': 'off', }, overrides: [ // node files diff --git a/addon/serializers/serializer.js b/addon/serializers/serializer.js index cda28a0..df865ff 100644 --- a/addon/serializers/serializer.js +++ b/addon/serializers/serializer.js @@ -1,36 +1,16 @@ import JSONAPISerializer from '@ember-data/serializer/json-api'; -import DS from 'ember-data'; // eslint-disable-line ember/use-ember-data-rfc-395-imports - -// Should be removed -// https://github.com/emberjs/data/pull/5317 -// https://github.com/emberjs/data/pull/5324 -const emberDataVersionOlderThan3Point1 = DS.VERSION.match(/^[0-2]\.|^3\.0/); export default JSONAPISerializer.extend({ - // Serialization behavior - // Can be removed (_shouldSerializeHasMany) removed in ember data 3.0.0 - // https://github.com/emberjs/data/pull/5290 - _shouldSerializeHasMany: function () { - return true; - }, - shouldSerializeHasMany: function () { + shouldSerializeHasMany() { return true; }, - serializeBelongsTo(snapshot, json, relationship) { - if (emberDataVersionOlderThan3Point1) { - this._super.apply(this, arguments); - } else { - this._fixSerializeBelongsTo(snapshot, json, relationship); - } + serializeBelongsTo() { + this._fixSerializeBelongsTo(...arguments); }, - serializeHasMany(snapshot, json, relationship) { - if (emberDataVersionOlderThan3Point1) { - this._super.apply(this, arguments); - } else { - this._fixSerializeHasMany(snapshot, json, relationship); - } + serializeHasMany() { + this._fixSerializeHasMany(...arguments); }, _fixSerializeBelongsTo(snapshot, json, relationship) { diff --git a/tests/unit/models/post-test.js b/tests/unit/models/post-test.js index e2c1665..c7f814b 100644 --- a/tests/unit/models/post-test.js +++ b/tests/unit/models/post-test.js @@ -3,7 +3,6 @@ import { setupTest } from 'ember-qunit'; import { get } from '@ember/object'; import { run } from '@ember/runloop'; -import DS from 'ember-data'; // eslint-disable-line ember/use-ember-data-rfc-395-imports import { registerConfigEnvironment, @@ -196,11 +195,7 @@ module('Unit | Model | post', function (hooks) { store .queryRecord('post', { filter: { name: 'Super Name' } }) .then(function (post) { - if (DS.VERSION.match(/^1\.13\./) || DS.VERSION.match(/^2\.[0|1]\./)) { - assert.deepEqual(post, []); - } else { - assert.equal(post, null); - } + assert.equal(post, null); done(); }) @@ -209,6 +204,7 @@ module('Unit | Model | post', function (hooks) { false, 'queryRecord on empty store throws error: ' + error.message ); + done(); }); });