Skip to content

Commit

Permalink
[BUGFIX release] MODEL_FACTORY_INJECTIONS is now always false.
Browse files Browse the repository at this point in the history
Double extend means this flag no longer means what it once did. To ensure ember-data functions correctly, we should now force it to always be false.

(cherry picked from commit 84ba295)
  • Loading branch information
stefanpenner authored and rwjblue committed May 17, 2017
1 parent c736afc commit 005cff8
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 36 deletions.
13 changes: 1 addition & 12 deletions packages/container/tests/container_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ import { factory } from 'internal-test-helpers';
import { isFeatureEnabled } from 'ember-debug';
import { LOOKUP_FACTORY, FACTORY_FOR } from 'container';

let originalModelInjections;

QUnit.module('Container', {
setup() {
originalModelInjections = ENV.MODEL_FACTORY_INJECTIONS;
},
teardown() {
ENV.MODEL_FACTORY_INJECTIONS = originalModelInjections;
}
});
QUnit.module('Container');

function lookupFactory(name, container, options) {
return container[LOOKUP_FACTORY](name, options);
Expand Down Expand Up @@ -244,8 +235,6 @@ QUnit.test('An invalid factory throws an error', function() {
});

QUnit.test('Injecting a failed lookup raises an error', function() {
ENV.MODEL_FACTORY_INJECTIONS = true;

let registry = new Registry();
let container = registry.container();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import { Object as EmberObject } from 'ember-runtime';
import DefaultResolver from '../../../system/resolver';
import { isFeatureEnabled } from 'ember-debug';

let originalLookup, App, originalModelInjections;
let originalLookup, App;

QUnit.module('Ember.Application Dependency Injection – toString', {
setup() {
originalModelInjections = ENV.MODEL_FACTORY_INJECTIONS;
ENV.MODEL_FACTORY_INJECTIONS = true;

originalLookup = context.lookup;

run(() => {
Expand All @@ -28,7 +25,6 @@ QUnit.module('Ember.Application Dependency Injection – toString', {
teardown() {
context.lookup = originalLookup;
run(App, 'destroy');
ENV.MODEL_FACTORY_INJECTIONS = originalModelInjections;
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import Application from '../../system/application';
let EmberApplication = Application;

let originalLookup = context.lookup;
let registry, locator, application, originalModelInjections;
let registry, locator, application;

QUnit.module('Ember.Application Dependency Injection', {
setup() {
originalModelInjections = ENV.MODEL_FACTORY_INJECTIONS;
ENV.MODEL_FACTORY_INJECTIONS = true;

application = run(EmberApplication, 'create');

application.Person = EmberObject.extend({});
Expand All @@ -36,7 +33,6 @@ QUnit.module('Ember.Application Dependency Injection', {
run(application, 'destroy');
application = locator = null;
context.lookup = originalLookup;
ENV.MODEL_FACTORY_INJECTIONS = originalModelInjections;
}
});

Expand Down
4 changes: 0 additions & 4 deletions packages/ember-environment/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* globals module */
import global from './global';
import { defaultFalse, defaultTrue, normalizeExtendPrototypes } from './utils';

/**
The hash of environment variables used to control various configuration
settings. To specify your own or override default settings, add the
Expand Down Expand Up @@ -66,9 +65,6 @@ ENV.LOG_STACKTRACE_ON_DEPRECATION = defaultTrue(ENV.LOG_STACKTRACE_ON_DEPRECATIO
*/
ENV.LOG_VERSION = defaultTrue(ENV.LOG_VERSION);

// default false
ENV.MODEL_FACTORY_INJECTIONS = defaultFalse(ENV.MODEL_FACTORY_INJECTIONS);

/**
Debug parameter you can turn on. This will log all bindings that fire to
the console. This should be disabled in production code. Note that you
Expand Down
1 change: 0 additions & 1 deletion packages/ember-extension-support/lib/data_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ export default EmberObject.extend({
if (!namespace.hasOwnProperty(key)) { continue; }
// Even though we will filter again in `getModelTypes`,
// we should not call `lookupFactory` on non-models
// (especially when `EmberENV.MODEL_FACTORY_INJECTIONS` is `true`)
if (!this.detect(namespace[key])) { continue; }
let name = StringUtils.dasherize(key);
if (!(namespace instanceof Application) && namespace.toString()) {
Expand Down
5 changes: 0 additions & 5 deletions packages/ember-runtime/lib/mixins/registry_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,6 @@ export default Mixin.create({
directly (via `create` or `new`) bypasses the dependency injection
system.
**Note:** Ember-Data instantiates its models in a unique manner, and consequently
injections onto models (or all models) will not work as expected. Injections
on models can be enabled by setting `EmberENV.MODEL_FACTORY_INJECTIONS`
to `true`.
@public
@method inject
@param factoryNameOrType {String}
Expand Down
20 changes: 16 additions & 4 deletions packages/ember/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,22 @@ Object.defineProperty(Ember, 'LOG_VERSION', {
enumerable: false
});

Object.defineProperty(Ember, 'MODEL_FACTORY_INJECTIONS', {
get() { return ENV.MODEL_FACTORY_INJECTIONS; },
set(value) { ENV.MODEL_FACTORY_INJECTIONS = !!value; },
enumerable: false
runInDebug(function() {
Object.defineProperty(Ember, 'MODEL_FACTORY_INJECTIONS', {
get() { return false; },
set(value) {
deprecate(
'Ember.MODEL_FACTORY_INJECTIONS is no longer required',
false,
{
id: 'ember-metal.model_factory_injections',
until: '2.17.0',
url: 'http://emberjs.com/deprecations/v2.x#toc_code-ember-model-factory-injections'
}
);
},
enumerable: false
});
});

Object.defineProperty(Ember, 'LOG_BINDINGS', {
Expand Down
17 changes: 17 additions & 0 deletions packages/ember/tests/reexports_test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* globals EmberDev */

import Ember from '../index';
import { confirmExport } from 'internal-test-helpers';
import { isFeatureEnabled } from 'ember-debug';
Expand Down Expand Up @@ -231,3 +233,18 @@ if (isFeatureEnabled('ember-metal-weakmap')) {
confirmExport(Ember, assert, 'WeakMap', 'ember-metal', 'WeakMap');
});
}

if (EmberDev && EmberDev.runningProdBuild) {
QUnit.test('Ember.MODEL_FACTORY_INJECTIONS', function(assert) {
let descriptor = Object.getOwnPropertyDescriptor(Ember, 'MODEL_FACTORY_INJECTIONS');
assert.equal(descriptor.enumerable, false, 'descriptor is not enumerable');
assert.equal(descriptor.configurable, false, 'descriptor is not configurable');

assert.equal(Ember.MODEL_FACTORY_INJECTIONS, false)

expectDeprecation(function() {
Ember.MODEL_FACTORY_INJECTIONS = true;
}, 'Ember.MODEL_FACTORY_INJECTIONS is no longer required')
assert.equal(Ember.MODEL_FACTORY_INJECTIONS, false, 'writing to the property has no affect')
});
}

0 comments on commit 005cff8

Please sign in to comment.