Revert non-model sync commits.

Revert "Allow non-model object as second argument, with test."
This reverts commit 32743e6b60.

Revert "trigger request event only if model extends Backbone.Events, and fix whitespace"
This reverts commit 6d72e1be35.

Revert "add if statement and add passing test"
This reverts commit 2caf748651.
This commit is contained in:
Brad Dunbar
2013-04-22 11:02:29 -04:00
parent 32743e6b60
commit dc5de0190e
2 changed files with 2 additions and 17 deletions

View File

@@ -1144,9 +1144,8 @@
// Ensure that we have the appropriate request data.
if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
var attrs = options.attrs || (_.isFunction(model.toJSON) ? model.toJSON(options) : model);
params.data = JSON.stringify(attrs);
params.contentType = 'application/json';
params.data = JSON.stringify(options.attrs || model.toJSON(options));
}
// For older servers, emulate JSON by encoding the request into an HTML-form.
@@ -1184,10 +1183,7 @@
// Make the request, allowing the user to override any Ajax options.
var xhr = options.xhr = Backbone.ajax(_.extend(params, options));
// Only trigger a "request" event if the second argument is a model or collection.
if (model && model.trigger === Events.trigger) model.trigger('request', model, xhr, options);
model.trigger('request', model, xhr, options);
return xhr;
};

View File

@@ -209,15 +209,4 @@ $(document).ready(function() {
strictEqual(this.ajaxSettings.beforeSend(xhr), false);
});
test("#2494 - Backbone.sync allows for non model/collection in second argument", 6, function() {
Backbone.sync('read', {}, {url : '/someurl'});
equal(this.ajaxSettings.url, '/someurl');
equal(this.ajaxSettings.type, 'GET');
equal(this.ajaxSettings.dataType, 'json');
Backbone.sync('create', {item: 'test'}, {url: '/test-url'});
equal(this.ajaxSettings.url, '/test-url');
equal(this.ajaxSettings.type, 'POST');
equal(this.ajaxSettings.data, '{"item":"test"}');
});
});