Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] The adapter should call ajax instead of the new metho… #4448

Merged
merged 1 commit into from
Jun 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions addon/adapters/json-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Ember from 'ember';
import RESTAdapter from "ember-data/adapters/rest";
import isEnabled from 'ember-data/-private/features';
import { deprecate } from 'ember-data/-private/debug';

/**
@class JSONAPIAdapter
Expand Down Expand Up @@ -99,7 +100,7 @@ var JSONAPIAdapter = RESTAdapter.extend({
@return {Promise} promise
*/
findMany(store, type, ids, snapshots) {
if (isEnabled('ds-improved-ajax')) {
if (isEnabled('ds-improved-ajax') && !this._hasCustomizedAjax()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works if we support ember-cli/babel-plugin-feature-flags#4. Are the necessary dependencies in ember-data updated so this is satisfied? I'm just asking; haven't had time to follow recent developments in ember-data too closely...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be allowed, as that was released as 0.2.1 and we are depending on ^0.2.0 (see here).

Copy link
Member

@pangratz pangratz Jun 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, awesome. Sorry for making you check this, I realize I could have easily done this myself 😔

return this._super(...arguments);
} else {
var url = this.buildURL(type.modelName, ids, snapshots, 'findMany');
Expand All @@ -126,7 +127,7 @@ var JSONAPIAdapter = RESTAdapter.extend({
@return {Promise} promise
*/
updateRecord(store, type, snapshot) {
if (isEnabled('ds-improved-ajax')) {
if (isEnabled('ds-improved-ajax') && !this._hasCustomizedAjax()) {
return this._super(...arguments);
} else {
var data = {};
Expand All @@ -139,6 +140,26 @@ var JSONAPIAdapter = RESTAdapter.extend({

return this.ajax(url, 'PATCH', { data: data });
}
},

_hasCustomizedAjax() {
if (this.ajax !== JSONAPIAdapter.prototype.ajax) {
deprecate('JSONAPIAdapter#ajax has been deprecated please use. `methodForRequest`, `urlForRequest`, `headersForRequest` or `dataForRequest` instead.', false, {
id: 'ds.json-api-adapter.ajax',
until: '3.0.0'
});
return true;
}

if (this.ajaxOptions !== JSONAPIAdapter.prototype.ajaxOptions) {
deprecate('JSONAPIAdapterr#ajaxOptions has been deprecated please use. `methodForRequest`, `urlForRequest`, `headersForRequest` or `dataForRequest` instead.', false, {
id: 'ds.json-api-adapter.ajax-options',
until: '3.0.0'
});
return true;
}

return false;
}
});

Expand Down
42 changes: 31 additions & 11 deletions addon/adapters/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from 'ember-data/adapters/errors';
import BuildURLMixin from "ember-data/-private/adapters/build-url-mixin";
import isEnabled from 'ember-data/-private/features';
import { runInDebug, warn } from 'ember-data/-private/debug';
import { runInDebug, warn, deprecate } from 'ember-data/-private/debug';
import parseResponseHeaders from 'ember-data/-private/utils/parse-response-headers';

const {
Expand Down Expand Up @@ -417,7 +417,7 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
@return {Promise} promise
*/
findRecord(store, type, id, snapshot) {
if (isEnabled('ds-improved-ajax')) {
if (isEnabled('ds-improved-ajax') && !this._hasCustomizedAjax()) {
const request = this._requestFor({
store, type, id, snapshot,
requestType: 'findRecord'
Expand Down Expand Up @@ -449,7 +449,7 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
findAll(store, type, sinceToken, snapshotRecordArray) {
const query = this.buildQuery(snapshotRecordArray);

if (isEnabled('ds-improved-ajax')) {
if (isEnabled('ds-improved-ajax') && !this._hasCustomizedAjax()) {
const request = this._requestFor({
store, type, sinceToken, query,
snapshots: snapshotRecordArray,
Expand Down Expand Up @@ -486,7 +486,7 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
@return {Promise} promise
*/
query(store, type, query) {
if (isEnabled('ds-improved-ajax')) {
if (isEnabled('ds-improved-ajax') && !this._hasCustomizedAjax()) {
const request = this._requestFor({
store, type, query,
requestType: 'query'
Expand Down Expand Up @@ -522,7 +522,7 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
@return {Promise} promise
*/
queryRecord(store, type, query) {
if (isEnabled('ds-improved-ajax')) {
if (isEnabled('ds-improved-ajax') && !this._hasCustomizedAjax()) {
const request = this._requestFor({
store, type, query,
requestType: 'queryRecord'
Expand Down Expand Up @@ -574,7 +574,7 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
@return {Promise} promise
*/
findMany(store, type, ids, snapshots) {
if (isEnabled('ds-improved-ajax')) {
if (isEnabled('ds-improved-ajax') && !this._hasCustomizedAjax()) {
const request = this._requestFor({
store, type, ids, snapshots,
requestType: 'findMany'
Expand Down Expand Up @@ -623,7 +623,7 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
@return {Promise} promise
*/
findHasMany(store, snapshot, url, relationship) {
if (isEnabled('ds-improved-ajax')) {
if (isEnabled('ds-improved-ajax') && !this._hasCustomizedAjax()) {
const request = this._requestFor({
store, snapshot, url, relationship,
requestType: 'findHasMany'
Expand Down Expand Up @@ -676,7 +676,7 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
@return {Promise} promise
*/
findBelongsTo(store, snapshot, url, relationship) {
if (isEnabled('ds-improved-ajax')) {
if (isEnabled('ds-improved-ajax') && !this._hasCustomizedAjax()) {
const request = this._requestFor({
store, snapshot, url, relationship,
requestType: 'findBelongsTo'
Expand Down Expand Up @@ -709,7 +709,7 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
@return {Promise} promise
*/
createRecord(store, type, snapshot) {
if (isEnabled('ds-improved-ajax')) {
if (isEnabled('ds-improved-ajax') && !this._hasCustomizedAjax()) {
const request = this._requestFor({
store, type, snapshot,
requestType: 'createRecord'
Expand Down Expand Up @@ -744,7 +744,7 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
@return {Promise} promise
*/
updateRecord(store, type, snapshot) {
if (isEnabled('ds-improved-ajax')) {
if (isEnabled('ds-improved-ajax') && !this._hasCustomizedAjax()) {
const request = this._requestFor({
store, type, snapshot,
requestType: 'updateRecord'
Expand Down Expand Up @@ -776,7 +776,7 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
@return {Promise} promise
*/
deleteRecord(store, type, snapshot) {
if (isEnabled('ds-improved-ajax')) {
if (isEnabled('ds-improved-ajax') && !this._hasCustomizedAjax()) {
const request = this._requestFor({
store, type, snapshot,
requestType: 'deleteRecord'
Expand Down Expand Up @@ -1169,6 +1169,26 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
}

return query;
},

_hasCustomizedAjax() {
if (this.ajax !== RESTAdapter.prototype.ajax) {
deprecate('RESTAdapter#ajax has been deprecated please use. `methodForRequest`, `urlForRequest`, `headersForRequest` or `dataForRequest` instead.', false, {
id: 'ds.rest-adapter.ajax',
until: '3.0.0'
});
return true;
}

if (this.ajaxOptions !== RESTAdapter.prototype.ajaxOptions) {
deprecate('RESTAdapter#ajaxOptions has been deprecated please use. `methodForRequest`, `urlForRequest`, `headersForRequest` or `dataForRequest` instead.', false, {
id: 'ds.rest-adapter.ajax-options',
until: '3.0.0'
});
return true;
}

return false;
}
});

Expand Down
6 changes: 3 additions & 3 deletions config/features.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"ds-boolean-transform-allow-null": null,
"ds-improved-ajax": null,
"ds-boolean-transform-allow-null": true,
"ds-improved-ajax": true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the updates in this file intended? What this basically does is aligning master with what we already have in beta, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

"ds-pushpayload-return": null,
"ds-serialize-ids-and-types": true,
"ds-extended-errors": null,
"ds-links-in-record-array": null,
"ds-links-in-record-array": true,
"ds-overhaul-references": null,
"ds-payload-type-hooks": null,
"ds-check-should-serialize-relationships": null,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"license": "MIT",
"dependencies": {
"amd-name-resolver": "0.0.5",
"babel-plugin-feature-flags": "^0.2.0",
"babel-plugin-feature-flags": "^0.2.1",
"babel-plugin-filter-imports": "^0.2.0",
"broccoli-babel-transpiler": "^5.5.0",
"broccoli-file-creator": "^1.0.0",
Expand Down
43 changes: 43 additions & 0 deletions tests/integration/adapter/rest-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2593,3 +2593,46 @@ testInDebug("warns when an empty response is returned, though a valid stringifie

assert.expectWarning("The server returned an empty string for POST /posts, which cannot be parsed into a valid JSON. Return either null or {}.");
});


if (isEnabled('ds-improved-ajax')) {
testInDebug("The RESTAdapter should use `ajax` with a deprecation message when it is overridden by the user.", function(assert) {
assert.expect(2)

adapter.ajax = function(url, verb, hash) {
assert.ok(true, 'The ajax method should be called when it is overridden');
return { posts: { id: 1, name: "Rails is omakase" } };
};

assert.expectDeprecation(function() {
run(function() {
store.findRecord('post', 1);
});
}, /RESTAdapter#ajax has been deprecated/)
});


testInDebug("The RESTAdapter should use `ajaxOptions` with a deprecation message when it is overridden by the user.", function(assert) {
assert.expect(2)

adapter._ajaxRequest = function(hash) {
var jqXHR = {
status: 200,
getAllResponseHeaders() { return ''; }
};
hash.success({ posts: { id: 1, name: "Rails is omakase" } }, 'OK', jqXHR);
}

var oldAjaxOptions = adapter.ajaxOptions;
adapter.ajaxOptions = function() {
assert.ok(true, 'The ajaxOptions method should be called when it is overridden');
return oldAjaxOptions.apply(this, arguments);
};

assert.expectDeprecation(function() {
run(function() {
store.findRecord('post', 1);
});
}, /RESTAdapter#ajaxOptions has been deprecated/)
});
}