diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js index 831ad6106dd..394ec74d45e 100644 --- a/tests/dummy/app/app.js +++ b/tests/dummy/app/app.js @@ -2,10 +2,13 @@ import Ember from 'ember'; import Resolver from './resolver'; import loadInitializers from 'ember-load-initializers'; import config from './config/environment'; +import { + setup as setupModelFactoryInjections +} from 'dummy/tests/helpers/model-factory-injection'; let App; -Ember.MODEL_FACTORY_INJECTIONS = true; +setupModelFactoryInjections(); App = Ember.Application.extend({ modulePrefix: config.modulePrefix, diff --git a/tests/helpers/model-factory-injection.js b/tests/helpers/model-factory-injection.js new file mode 100644 index 00000000000..aad65f95ade --- /dev/null +++ b/tests/helpers/model-factory-injection.js @@ -0,0 +1,14 @@ +import Ember from 'ember'; +import hasEmberVersion from 'ember-test-helpers/has-ember-version'; + +let ORIGINAL_MODEL_FACTORY_INJECTIONS = Ember.MODEL_FACTORY_INJECTIONS; + +export function setup(value = true) { + if (!hasEmberVersion(2, 14)) { + Ember.MODEL_FACTORY_INJECTIONS = value; + } +} + +export function reset() { + setup(ORIGINAL_MODEL_FACTORY_INJECTIONS); +} diff --git a/tests/integration/injection-test.js b/tests/integration/injection-test.js index c24c4bdacbe..dfbc603ff05 100644 --- a/tests/integration/injection-test.js +++ b/tests/integration/injection-test.js @@ -1,10 +1,13 @@ +import { + setup as setupModelFactoryInjections, + reset as resetModelFactoryInjections +} from 'dummy/tests/helpers/model-factory-injection'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; import DS from 'ember-data'; import { module, test } from 'qunit'; let env, hasFactoryFor, originalLookupFactory, originalOwnerLookupFactory, originalFactoryFor; -let originalMODEL_FACTORY_INJECTIONS = Ember.MODEL_FACTORY_INJECTIONS; const { run } = Ember; const model = { @@ -79,7 +82,7 @@ test('modelFor', function(assert) { module('integration/injection eager injections', { setup() { - Ember.MODEL_FACTORY_INJECTIONS = true; + setupModelFactoryInjections(); env = setupStore(); env.registry.injection('model:foo', 'apple', 'service:apple'); @@ -90,7 +93,7 @@ module('integration/injection eager injections', { teardown() { // can be removed once we no longer support ember versions without lookupFactory - Ember.MODEL_FACTORY_INJECTIONS = originalMODEL_FACTORY_INJECTIONS; + resetModelFactoryInjections(); run(env.store, 'destroy'); } diff --git a/tests/integration/relationships/belongs-to-test.js b/tests/integration/relationships/belongs-to-test.js index 88fa6b08f0e..1836ace5c9d 100644 --- a/tests/integration/relationships/belongs-to-test.js +++ b/tests/integration/relationships/belongs-to-test.js @@ -1,3 +1,7 @@ +import { + setup as setupModelFactoryInjections, + reset as resetModelFactoryInjections +} from 'dummy/tests/helpers/model-factory-injection'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; @@ -11,10 +15,11 @@ const { attr, hasMany, belongsTo } = DS; const { hash } = RSVP; let env, store, User, Message, Post, Comment, Book, Chapter, Author, NewMessage; -const injectionValue = Ember.MODEL_FACTORY_INJECTIONS; module("integration/relationship/belongs_to Belongs-To Relationships", { beforeEach() { + setupModelFactoryInjections(); + User = DS.Model.extend({ name: attr('string'), messages: hasMany('message', { polymorphic: true, async: false }), @@ -83,7 +88,7 @@ module("integration/relationship/belongs_to Belongs-To Relationships", { }, afterEach() { - Ember.MODEL_FACTORY_INJECTIONS = injectionValue; + resetModelFactoryInjections(); run(env.container, 'destroy'); } }); diff --git a/tests/integration/relationships/has-many-test.js b/tests/integration/relationships/has-many-test.js index e359df81d27..0db8908dd08 100644 --- a/tests/integration/relationships/has-many-test.js +++ b/tests/integration/relationships/has-many-test.js @@ -1,5 +1,9 @@ /*eslint no-unused-vars: ["error", { "args": "none", "varsIgnorePattern": "(page)" }]*/ +import { + setup as setupModelFactoryInjections, + reset as resetModelFactoryInjections +} from 'dummy/tests/helpers/model-factory-injection'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; @@ -1338,8 +1342,7 @@ test("When a polymorphic hasMany relationship is accessed, the store can call mu test("polymorphic hasMany type-checks check the superclass when MODEL_FACTORY_INJECTIONS is enabled", function(assert) { assert.expect(1); - let injectionValue = Ember.MODEL_FACTORY_INJECTIONS; - Ember.MODEL_FACTORY_INJECTIONS = true; + setupModelFactoryInjections(); try { run(function () { @@ -1351,7 +1354,7 @@ test("polymorphic hasMany type-checks check the superclass when MODEL_FACTORY_IN assert.equal(igor.get('messages.firstObject.body'), "Well I thought the title was fine"); }); } finally { - Ember.MODEL_FACTORY_INJECTIONS = injectionValue; + resetModelFactoryInjections(); } }); diff --git a/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js b/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js index 9439b60d168..f62f41e22d1 100644 --- a/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js +++ b/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js @@ -1,3 +1,8 @@ +import { + setup as setupModelFactoryInjections, + reset as resetModelFactoryInjections +} from 'dummy/tests/helpers/model-factory-injection'; + import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; @@ -155,8 +160,7 @@ testInDebug("Setting the polymorphic belongsTo with an object that does not impl test("Setting the polymorphic belongsTo gets propagated to the inverse side - model injections true", function(assert) { assert.expect(2); - var injectionValue = Ember.MODEL_FACTORY_INJECTIONS; - Ember.MODEL_FACTORY_INJECTIONS = true; + setupModelFactoryInjections(); try { var user, video; @@ -190,13 +194,12 @@ test("Setting the polymorphic belongsTo gets propagated to the inverse side - mo }); }); } finally { - Ember.MODEL_FACTORY_INJECTIONS = injectionValue; + resetModelFactoryInjections(); } }); testInDebug("Setting the polymorphic belongsTo with an object that does not implement the mixin errors out - model injections true", function(assert) { - var injectionValue = Ember.MODEL_FACTORY_INJECTIONS; - Ember.MODEL_FACTORY_INJECTIONS = true; + setupModelFactoryInjections(); try { var user, video; @@ -226,6 +229,6 @@ testInDebug("Setting the polymorphic belongsTo with an object that does not impl }, /You cannot add a record of modelClass 'not-message' to the 'user.bestMessage' relationship \(only 'message' allowed\)/); }); } finally { - Ember.MODEL_FACTORY_INJECTIONS = injectionValue; + resetModelFactoryInjections(); } }); diff --git a/tests/integration/relationships/polymorphic-mixins-has-many-test.js b/tests/integration/relationships/polymorphic-mixins-has-many-test.js index 9141b088522..8993ad3f8c4 100644 --- a/tests/integration/relationships/polymorphic-mixins-has-many-test.js +++ b/tests/integration/relationships/polymorphic-mixins-has-many-test.js @@ -1,3 +1,8 @@ +import { + setup as setupModelFactoryInjections, + reset as resetModelFactoryInjections +} from 'dummy/tests/helpers/model-factory-injection'; + import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; @@ -170,8 +175,7 @@ testInDebug("Pushing a an object that does not implement the mixin to the mixin }); test("Pushing to the hasMany reflects the change on the belongsTo side - model injections true", function(assert) { - var injectionValue = Ember.MODEL_FACTORY_INJECTIONS; - Ember.MODEL_FACTORY_INJECTIONS = true; + setupModelFactoryInjections(); try { var user, video; @@ -209,7 +213,7 @@ test("Pushing to the hasMany reflects the change on the belongsTo side - model i }); }); } finally { - Ember.MODEL_FACTORY_INJECTIONS = injectionValue; + resetModelFactoryInjections(); } }); @@ -217,8 +221,7 @@ test("Pushing to the hasMany reflects the change on the belongsTo side - model i Local edits */ testInDebug("Pushing a an object that does not implement the mixin to the mixin accepting array errors out - model injections true", function(assert) { - var injectionValue = Ember.MODEL_FACTORY_INJECTIONS; - Ember.MODEL_FACTORY_INJECTIONS = true; + setupModelFactoryInjections(); try { var user,notMessage; @@ -255,7 +258,6 @@ testInDebug("Pushing a an object that does not implement the mixin to the mixin }); }); } finally { - Ember.MODEL_FACTORY_INJECTIONS = injectionValue; + resetModelFactoryInjections(); } }); -