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

[BUGFIX release] MODEL_FACTORY_INJECTIONS is now always false. #15204

Merged
merged 1 commit into from
May 15, 2017
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
13 changes: 1 addition & 12 deletions packages/container/tests/container_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@ import { get } from 'ember-metal';
import { Registry } from '..';
import { factory } from 'internal-test-helpers';

let originalModelInjections;

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

QUnit.test('A registered factory returns the same instance each time', function() {
let registry = new Registry();
Expand Down Expand Up @@ -166,8 +157,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 @@ -5,13 +5,10 @@ import Application from '../../../system/application';
import { Object as EmberObject } from 'ember-runtime';
import DefaultResolver from '../../../system/resolver';

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 @@ -27,7 +24,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 @@ -386,7 +386,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);
types.push(name);
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
23 changes: 18 additions & 5 deletions packages/ember/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import require, { has } from 'require';
import { DEBUG } from 'ember-env-flags';

// ****ember-environment****
import { ENV, context } from 'ember-environment';
Expand Down Expand Up @@ -174,11 +175,23 @@ 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
});
if (DEBUG) {
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', {
get() { return ENV.LOG_BINDINGS; },
Expand Down
16 changes: 16 additions & 0 deletions packages/ember/tests/reexports_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Ember from '../index';
import { confirmExport } from 'internal-test-helpers';
import { EMBER_METAL_WEAKMAP } from 'ember/features';
import { DEBUG } from 'ember-env-flags';

QUnit.module('ember reexports');

Expand Down Expand Up @@ -233,3 +234,18 @@ if (EMBER_METAL_WEAKMAP) {
confirmExport(Ember, assert, 'WeakMap', 'ember-metal', 'WeakMap');
});
}

if (DEBUG) {
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')
});
}