Skip to content

Commit

Permalink
Merge pull request #11655 from cibernox/fix_blockless_qp_only_links
Browse files Browse the repository at this point in the history
[BUGFIX release] Fix blockless link-to with only query params
  • Loading branch information
rwjblue committed Jul 6, 2015
2 parents 35f8a35 + 96e2abd commit 09d8f93
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/ember-routing-views/lib/views/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ var LinkComponent = EmberComponent.extend({
if (lastParam && lastParam.isQueryParams) {
params.pop();
}
let onlyQueryParamsSupplied = (params.length === 0);
let onlyQueryParamsSupplied = (this.attrs.hasBlock ? params.length === 0 : params.length === 1);
if (onlyQueryParamsSupplied) {
var appController = this.container.lookup('controller:application');
if (appController) {
Expand Down
36 changes: 35 additions & 1 deletion packages/ember/tests/helpers/link_to_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ QUnit.test('{{link-to}} populates href with fully supplied query param values',
equal(Ember.$('#the-link').attr('href'), '/?bar=NAW&foo=456', 'link has right href');
});

QUnit.test('{{link-to}} with only query-params updates when route changes', function() {
QUnit.test('{{link-to}} with only query-params and a block updates when route changes', function() {
Router.map(function() {
this.route('about');
});
Expand Down Expand Up @@ -1405,3 +1405,37 @@ QUnit.test('{{link-to}} with only query-params updates when route changes', func
});
equal(Ember.$('#the-link').attr('href'), '/about?bar=NAW&foo=456', 'link has right href');
});

QUnit.test('Block-less {{link-to}} with only query-params updates when route changes', function() {
Router.map(function() {
this.route('about');
});

if (isEnabled('ember-routing-route-configured-query-params')) {
App.ApplicationRoute = Ember.Route.extend({
queryParams: {
foo: {
defaultValue: '123'
},
bar: {
defaultValue: 'yes'
}
}
});
} else {
App.ApplicationController = Ember.Controller.extend({
queryParams: ['foo', 'bar'],
foo: '123',
bar: 'yes'
});
}

Ember.TEMPLATES.application = compile('{{link-to "Index" (query-params foo=\'456\' bar=\'NAW\') id=\'the-link\'}}');
bootApplication();
equal(Ember.$('#the-link').attr('href'), '/?bar=NAW&foo=456', 'link has right href');

Ember.run(function() {
router.handleURL('/about');
});
equal(Ember.$('#the-link').attr('href'), '/about?bar=NAW&foo=456', 'link has right href');
});

0 comments on commit 09d8f93

Please sign in to comment.