diff --git a/addon/ajax-request.js b/addon/ajax-request.js index c89aa23a..9f641a1e 100644 --- a/addon/ajax-request.js +++ b/addon/ajax-request.js @@ -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 * diff --git a/tests/unit/ajax-request-test.js b/tests/unit/ajax-request-test.js index a1978be3..90cb7bfc 100644 --- a/tests/unit/ajax-request-test.js +++ b/tests/unit/ajax-request-test.js @@ -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);