Skip to content

Commit

Permalink
[BUGFIX release] Fix legacy addon deprecations
Browse files Browse the repository at this point in the history
The signature of `Ember.deprecate` is `message`, `test`, `options`,
where `test` is `If falsy, the deprecation will be displayed.` Here,
we did the opposite, causing the deprecation message to be shown only
when the addons are NOT installed.

This commit fixes the issue, and also moved the deprecation to first-
boot. This gives users (and our test harness) a chance to register
custom handlers before we issue the warning.

Also added tests.
  • Loading branch information
Godhuda committed Mar 1, 2016
1 parent 57d8c36 commit 59e9045
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 13 deletions.
31 changes: 30 additions & 1 deletion packages/ember-application/lib/system/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@submodule ember-application
*/
import Ember from 'ember-metal'; // Ember.libraries, LOG_VERSION, Namespace, BOOTED
import { assert, debug } from 'ember-metal/debug';
import { assert, debug, deprecate } from 'ember-metal/debug';
import isEnabled from 'ember-metal/features';
import { get } from 'ember-metal/property_get';
import { runLoadHooks } from 'ember-runtime/system/lazy_load';
Expand Down Expand Up @@ -39,6 +39,15 @@ import Engine from './engine';

var librariesRegistered = false;

let warnedAboutLegacyViewAddon = false;
let warnedAboutLegacyControllerAddon = false;

// For testing
export function _resetLegacyAddonWarnings() {
warnedAboutLegacyViewAddon = false;
warnedAboutLegacyControllerAddon = false;
}

/**
An instance of `Ember.Application` is the starting point for every Ember
application. It helps to instantiate, initialize and coordinate the many
Expand Down Expand Up @@ -594,6 +603,26 @@ const Application = Engine.extend({
_bootSync() {
if (this._booted) { return; }

if (Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT && !warnedAboutLegacyViewAddon) {
deprecate(
'Support for the `ember-legacy-views` addon will end soon, please remove it from your application.',
false,
{ id: 'ember-legacy-views', until: '2.6.0', url: 'http://emberjs.com/deprecations/v1.x/#toc_ember-view' }
);

warnedAboutLegacyViewAddon = true;
}

if (Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT && !warnedAboutLegacyControllerAddon) {
deprecate(
'Support for the `ember-legacy-controllers` addon will end soon, please remove it from your application.',
false,
{ id: 'ember-legacy-controllers', until: '2.6.0', url: 'http://emberjs.com/deprecations/v1.x/#toc_objectcontroller' }
);

warnedAboutLegacyControllerAddon = true;
}

// Even though this returns synchronously, we still need to make sure the
// boot promise exists for book-keeping purposes: if anything went wrong in
// the boot process, we need to store the error as a rejection on the boot
Expand Down
72 changes: 71 additions & 1 deletion packages/ember-application/tests/system/application_test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*globals EmberDev */

import Ember from 'ember-metal/core';
import assign from 'ember-metal/assign';
import run from 'ember-metal/run_loop';
import Application from 'ember-application/system/application';
import Application, { _resetLegacyAddonWarnings } from 'ember-application/system/application';
import DefaultResolver from 'ember-application/system/resolver';
import Router from 'ember-routing/system/router';
import View from 'ember-views/views/view';
Expand Down Expand Up @@ -354,3 +355,72 @@ QUnit.test('does not leak itself in onLoad._loaded', function() {
run(app, 'destroy');
equal(_loaded.application, undefined);
});

let originalEmberENV;

QUnit.module('Ember.Application - legacy addon deprecation warnings', {
setup() {
originalEmberENV = Ember.ENV;

Ember.ENV = assign({}, originalEmberENV, {
_ENABLE_LEGACY_VIEW_SUPPORT: false,
_ENABLE_LEGACY_CONTROLLER_SUPPORT: false
});

_resetLegacyAddonWarnings();
},

teardown() {
Ember.ENV = originalEmberENV;

if (app) {
run(app, 'destroy');
}
}
});

QUnit.test('it does not warn about the ember-legacy-views addon on first boot when not installed', function() {
expectNoDeprecation();

Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT = false;

app = run(Application, 'create');
});

QUnit.test('it warns about the ember-legacy-views addon on first boot when installed', function() {
Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT = true;

expectDeprecation(() => {
app = run(Application, 'create');
}, 'Support for the `ember-legacy-views` addon will end soon, please remove it from your application.');

run(app, 'destroy');

// It should not warn again on second boot
expectNoDeprecation(() => {
app = run(Application, 'create');
});
});

QUnit.test('it does not warn about the ember-legacy-controllers addon on first boot when not installed', function() {
expectNoDeprecation();

Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = false;

app = run(Application, 'create');
});

QUnit.test('it warns about the ember-legacy-controllers addon on first boot when installed', function() {
Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = true;

expectDeprecation(() => {
app = run(Application, 'create');
}, 'Support for the `ember-legacy-controllers` addon will end soon, please remove it from your application.');

run(app, 'destroy');

// It should not warn again on second boot
expectNoDeprecation(() => {
app = run(Application, 'create');
});
});
12 changes: 1 addition & 11 deletions packages/ember-metal/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// BEGIN IMPORTS
import require, { has } from 'require';
import Ember from 'ember-metal/core';
import { deprecate, deprecateFunc } from 'ember-metal/debug';
import { deprecateFunc } from 'ember-metal/debug';
import isEnabled, { FEATURES } from 'ember-metal/features';
import assign from 'ember-metal/assign';
import merge from 'ember-metal/merge';
Expand Down Expand Up @@ -367,16 +367,6 @@ if (has('ember-debug')) {
}
}

deprecate(
'Support for the `ember-legacy-views` addon will end soon, please remove it from your application.',
!!Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT,
{ id: 'ember-legacy-views', until: '2.6.0', url: 'http://emberjs.com/deprecations/v1.x/#toc_ember-view' });

deprecate(
'Support for the `ember-legacy-controllers` addon will end soon, please remove it from your application.',
!!Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT,
{ id: 'ember-legacy-controllers', until: '2.6.0', url: 'http://emberjs.com/deprecations/v1.x/#toc_objectcontroller' });

Ember.create = deprecateFunc('Ember.create is deprecated in favor of Object.create', { id: 'ember-metal.ember-create', until: '3.0.0' }, Object.create);
Ember.keys = deprecateFunc('Ember.keys is deprecated in favor of Object.keys', { id: 'ember-metal.ember.keys', until: '3.0.0' }, Object.keys);

Expand Down
10 changes: 10 additions & 0 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@
}
}

Ember.Debug.registerDeprecationHandler(function (message, options, next) {
var id = options && options.id;

if (id === 'ember-legacy-views' || id === 'ember-legacy-controllers') {
// Our test suite relies on the legacy semantics... to test the legacy semantics
} else {
next(message, options);
}
});

window.EmberDev = window.EmberDev || {};
EmberDev.runningProdBuild = !!QUnit.urlParams.prod;

Expand Down

0 comments on commit 59e9045

Please sign in to comment.