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

Commit

Permalink
Add a delete alias (#84)
Browse files Browse the repository at this point in the history
* Add a `delete` alias

Since the other methods map to the HTTP type name (PATCH => `patch()`, POST => `post()`) it makes sense to do the same for `delete`. Does this sound like a good idea?

* Add test for `delete` (alias for `del`)

* Use splat to pass along arguments

* The same, only different
  • Loading branch information
sandstrom authored and alexlafroscia committed Apr 10, 2016
1 parent bd9e743 commit 952a20c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions addon/ajax-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ export default class AjaxRequest {
return this.request(url, this._addTypeToOptionsFor(options, 'DELETE'));
}

/**
* calls `request()` but forces `options.type` to `DELETE`
* alias for `del()`
* @public
*/
delete() {
return this.del(...arguments);
}

/**
* Wrap the `.get` method so that we issue a warning if
*
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/ajax-request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,21 @@ test('del() promise label is correct', function(assert) {
});
});

test('delete() promise label is correct', function(assert) {
const service = new AjaxRequest();
const url = '/posts/1';
const serverResponse = [200, { 'Content-Type': 'application/json' }, JSON.stringify({})];

server.delete(url, () => serverResponse);

const deletePromise = service.delete(url);
assert.equal(deletePromise._label, 'ember-ajax: DELETE /posts/1 response');

return deletePromise.then(function(response) {
assert.deepEqual(response, {});
});
});

test('request with method option makes the correct type of request', function(assert) {
assert.expect(1);

Expand Down

0 comments on commit 952a20c

Please sign in to comment.