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] Fix link-to with only qps linking to outdated route #12058

Merged
merged 1 commit into from
Aug 12, 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: 1 addition & 1 deletion packages/ember-routing-views/lib/views/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ var LinkComponent = EmberComponent.extend({
}

var routing = get(this, '_routing');
var targetRouteName = get(this, 'targetRouteName');
var targetRouteName = this._handleOnlyQueryParamsSupplied(get(this, 'targetRouteName'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me but in hindsight, but in hindsight we should probably find a better name for this method... it doesn't seem to "handle" anything but rather compute the target route name? @juggy, you're the original author, would you be ok with renaming this method or is there something I'm missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but in hindsight, but in hindsight

does this reduce to "in the future " :trollface:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahahahah

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it can be renamed to something more meaningful like computeWithOnlyQueryParamsSupplied.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juggy - Mind sending in a PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #12065

var models = get(this, 'models');
var queryParamValues = get(this, 'queryParams.values');
var shouldReplace = get(this, 'attrs.replace');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,56 @@ if (isEnabled('ember-routing-route-configured-query-params')) {
equal(Ember.$('#the-link').attr('href'), '/?bar=BORF&foo=lol');
});

QUnit.test('The {{link-to}} with only query params always transitions to the current route with the query params applied', function() {
// Test harness for bug #12033

Ember.TEMPLATES.cars = compile(
'{{#link-to \'cars.create\' id=\'create-link\'}}Create new car{{/link-to}} ' +
'{{#link-to (query-params page=\'2\') id=\'page2-link\'}}Page 2{{/link-to}}' +
'{{outlet}}'
);

Ember.TEMPLATES['cars/create'] = compile(
'{{#link-to \'cars\' id=\'close-link\'}}Close create form{{/link-to}}'
);

Router.map(function() {
this.route('cars', function() {
this.route('create');
});
});

App.CarsRoute = Ember.Route.extend({
queryParams: {
page: { defaultValue: 1 }
}
});

bootApplication();

Ember.run(function() {
router.handleURL('/cars/create');
});

Ember.run(function() {
equal(router.currentRouteName, 'cars.create');
Ember.$('#close-link').click();
});

Ember.run(function() {
equal(router.currentRouteName, 'cars.index');
equal(router.get('url'), '/cars');
equal(container.lookup('controller:cars').get('page'), 1, 'The page query-param is 1');
Ember.$('#page2-link').click();
});

Ember.run(function() {
equal(router.currentRouteName, 'cars.index', 'The active route is still cars');
equal(router.get('url'), '/cars?page=2', 'The url has been updated');
equal(container.lookup('controller:cars').get('page'), 2, 'The query params have been updated');
});
});

QUnit.test('The {{link-to}} applies activeClass when query params are not changed', function() {
Ember.TEMPLATES.index = compile(
'{{#link-to (query-params foo=\'cat\') id=\'cat-link\'}}Index{{/link-to}} ' +
Expand Down Expand Up @@ -578,6 +628,57 @@ if (isEnabled('ember-routing-route-configured-query-params')) {
equal(Ember.$('#the-link').attr('href'), '/?bar=BORF&foo=lol');
});

QUnit.test('The {{link-to}} with only query params always transitions to the current route with the query params applied', function() {
// Test harness for bug #12033

Ember.TEMPLATES.cars = compile(
'{{#link-to \'cars.create\' id=\'create-link\'}}Create new car{{/link-to}} ' +
'{{#link-to (query-params page=\'2\') id=\'page2-link\'}}Page 2{{/link-to}}' +
'{{outlet}}'
);

Ember.TEMPLATES['cars/create'] = compile(
'{{#link-to \'cars\' id=\'close-link\'}}Close create form{{/link-to}}'
);

Router.map(function() {
this.route('cars', function() {
this.route('create');
});
});

App.CarsController = Ember.Controller.extend({
queryParams: ['page'],
page: 1
});

bootApplication();

var carsController = container.lookup('controller:cars');

Ember.run(function() {
router.handleURL('/cars/create');
});

Ember.run(function() {
equal(router.currentRouteName, 'cars.create');
Ember.$('#close-link').click();
});

Ember.run(function() {
equal(router.currentRouteName, 'cars.index');
equal(router.get('url'), '/cars');
equal(carsController.get('page'), 1, 'The page query-param is 1');
Ember.$('#page2-link').click();
});

Ember.run(function() {
equal(router.currentRouteName, 'cars.index', 'The active route is still cars');
equal(router.get('url'), '/cars?page=2', 'The url has been updated');
equal(carsController.get('page'), 2, 'The query params have been updated');
});
});

QUnit.test('The {{link-to}} applies activeClass when query params are not changed', function() {
Ember.TEMPLATES.index = compile(
'{{#link-to (query-params foo=\'cat\') id=\'cat-link\'}}Index{{/link-to}} ' +
Expand Down