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] {{link-to}} before application boot #11639

Merged
merged 2 commits into from
Jul 3, 2015
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
2 changes: 2 additions & 0 deletions packages/ember-routing-views/lib/views/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ var LinkComponent = EmberComponent.extend({
*/
active: computed('attrs.params', '_routing.currentState', function computeLinkComponentActive() {
var currentState = get(this, '_routing.currentState');
if (!currentState) { return false; }

return computeActive(this, currentState);
}),

Expand Down
1 change: 1 addition & 0 deletions packages/ember-routing/lib/services/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var RoutingService = Service.extend({

generateURL(routeName, models, queryParams) {
var router = get(this, 'router');
if (!router.router) { return; }

var visibleQueryParams = {};
merge(visibleQueryParams, queryParams);
Expand Down
40 changes: 40 additions & 0 deletions packages/ember/tests/helpers/link_to_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "ember";
import ComponentLookup from "ember-views/component_lookup";

import { objectControllerDeprecation } from "ember-runtime/controllers/object_controller";
import EmberHandlebars from "ember-htmlbars/compat";
Expand Down Expand Up @@ -93,6 +94,45 @@ QUnit.module("The {{link-to}} helper", {
teardown: sharedTeardown
});

// These two tests are designed to simulate the context of an ember-qunit/ember-test-helpers component integration test,
// so the container is available but it does not boot the entire app
QUnit.test('Using {{link-to}} does not cause an exception if it is rendered before the router has started routing', function(assert) {
Router.map(function() {
this.route('about');
});

registry.register('component-lookup:main', ComponentLookup);

let component = Ember.Component.extend({
layout: compile('{{#link-to "about"}}Go to About{{/link-to}}'),
container: container
}).create();

let router = container.lookup('router:main');
router.setupRouter();

Ember.run(function() {
component.appendTo('#qunit-fixture');
});

assert.strictEqual(component.$('a').length, 1, 'the link is rendered');
});

QUnit.test('Using {{link-to}} does not cause an exception if it is rendered without a router.js instance', function(assert) {
registry.register('component-lookup:main', ComponentLookup);

let component = Ember.Component.extend({
layout: compile('{{#link-to "nonexistent"}}Does not work.{{/link-to}}'),
container: container
}).create();

Ember.run(function() {
component.appendTo('#qunit-fixture');
});

assert.strictEqual(component.$('a').length, 1, 'the link is rendered');
});

QUnit.test("The {{link-to}} helper moves into the named route", function() {
Router.map(function(match) {
this.route("about");
Expand Down