From 1ad994493da9e7b020c535cbfdf935a4d2f00bde Mon Sep 17 00:00:00 2001 From: Amiel Martin Date: Fri, 26 Oct 2018 14:21:44 -0700 Subject: [PATCH 1/2] Add a test to verify the query params hack for #19 This way, we have a test that verifies that #19 continues to be resolved even after future changes. --- tests/acceptance/basic-url-template-test.js | 20 ++++++++++++++++++++ tests/dummy/app/routes/post.js | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/acceptance/basic-url-template-test.js b/tests/acceptance/basic-url-template-test.js index 3ed749a..72079c6 100644 --- a/tests/acceptance/basic-url-template-test.js +++ b/tests/acceptance/basic-url-template-test.js @@ -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); + }); }); diff --git a/tests/dummy/app/routes/post.js b/tests/dummy/app/routes/post.js index 6f87381..b7d9854 100644 --- a/tests/dummy/app/routes/post.js +++ b/tests/dummy/app/routes/post.js @@ -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' }); } }); From 6ace782668688aa61c102d6c130a3c2618aeb58e Mon Sep 17 00:00:00 2001 From: Amiel Martin Date: Fri, 26 Oct 2018 14:23:15 -0700 Subject: [PATCH 2/2] Clarify TODO comment about sortQueryParams hack --- addon/mixins/url-templates.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addon/mixins/url-templates.js b/addon/mixins/url-templates.js index 8cc3fb4..6b153f1 100644 --- a/addon/mixins/url-templates.js +++ b/addon/mixins/url-templates.js @@ -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 {}; },