Skip to content

Commit

Permalink
Add a test to verify the query params hack for #19
Browse files Browse the repository at this point in the history
This way, we have a test that verifies that #19 continues to be resolved even after future changes.
  • Loading branch information
amiel committed Oct 26, 2018
1 parent b7fe6c9 commit 1ad9944
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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 1ad9944

Please sign in to comment.