Skip to content

Commit

Permalink
Merge pull request #51 from amiel/verify-query-params-hack
Browse files Browse the repository at this point in the history
Add a test to verify the query params hack for #19
  • Loading branch information
amiel authored Oct 26, 2018
2 parents b7fe6c9 + 6ace782 commit 2f3b145
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
5 changes: 3 additions & 2 deletions addon/mixins/url-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ export default Mixin.create({

// HACK: Prevent query/queryRecord from appending query params to urls, we
// can do that in the template.
// TODO: Use dataForRequest when ds-improved-ajax lands
// (https://github.com/emberjs/data/pull/3099)
// TODO: ember-data plans to implement better hooks for customizing the
// request. Hopefully in the future, this hack can be removed and another
// hook used instead.
sortQueryParams(/* params */) {
return {};
},
Expand Down
20 changes: 20 additions & 0 deletions tests/acceptance/basic-url-template-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,24 @@ module('Acceptance | basic url template', function(hooks) {
assert.equal(findAll('#post-2').length, 1);
assert.equal(findAll('#post-3').length, 0);
});

test('it prevents ember-data from adding query params', async function(assert) {
server.create('post', {
slug: 'my-first-post',
title: 'This is my first post',
});

let queryParams, params;

server.get('/my-posts/:slug', (schema, request) => {
queryParams = request.queryParams;
params = request.params;
return schema.posts.findBy({ slug: request.params.slug });
});

await visit('/posts/my-first-post');

assert.equal(params.slug, 'my-first-post');
assert.ok(!queryParams.foo);
});
});
3 changes: 2 additions & 1 deletion tests/dummy/app/routes/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Route from '@ember/routing/route';

export default Route.extend({
model({ slug }) {
return this.store.queryRecord('post', { slug });
// Add a random extra query param to see if it ends up in the url
return this.store.queryRecord('post', { slug, foo: 'bar' });
}
});

0 comments on commit 2f3b145

Please sign in to comment.