Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #100 from scoutforpets/fix-query-param-issue
Browse files Browse the repository at this point in the history
ignores stringifying query params when content is jsonapi (fixes #99)
  • Loading branch information
taras committed Apr 29, 2016
2 parents ec23059 + 6fe71b3 commit c0028c5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addon/ajax-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class AjaxRequest {
url: hash.url
};

if (isJSONAPIContentType(hash.headers['Content-Type'])) {
if (isJSONAPIContentType(hash.headers['Content-Type']) && requestData.type !== 'GET') {
if (typeof hash.data === 'object') {
hash.data = JSON.stringify(hash.data);
}
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/ajax-request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,30 @@ test('it JSON encodes JSON:API request data automatically', function(assert) {
});
});

test('it does not JSON encode query parameters when JSON:API headers are present', function(assert) {
assert.expect(1);

server.get('/test', ({ queryParams }) => {
const { foo } = queryParams;
assert.equal(foo, 'bar', 'Correctly received query param');
return jsonResponse();
});

class RequestWithHeaders extends AjaxRequest {
get headers() {
return {
'Content-Type': 'application/vnd.api+json'
};
}
}
const service = new RequestWithHeaders();
return service.request('/test', {
data: {
foo: 'bar'
}
});
});

test('it JSON encodes JSON:API "extension" request data automatically', function(assert) {
assert.expect(1);

Expand Down

0 comments on commit c0028c5

Please sign in to comment.