Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update tests to Backbone 1.5.2, fix an inconsistency in the comments

  • Loading branch information...
commit 92c8a4278d36b448003d5f4fb1867b0e395f21ed 1 parent 9603ede
@PaulUithol PaulUithol authored
Showing with 17 additions and 12 deletions.
  1. +2 −2 backbone-relational.js
  2. +15 −10 test/lib/backbone.js
View
4 backbone-relational.js
@@ -805,8 +805,8 @@
},
/**
- * Initialize Relations present in this.relations; determine the type (HasOne/HasMany), then create a new instance.
- * The regular constructor (which fills this.attributes, initialize, etc) hasn't run yet at this time!
+ * Initialize Relations present in this.relations; determine the type (HasOne/HasMany), then creates a new instance.
+ * Invoked in the first call so 'set' (which is made from the Backbone.Model constructor).
*/
initializeRelations: function() {
this.acquire(); // Setting up relations often also involve calls to 'set', and we only want to enter this function once
View
25 test/lib/backbone.js
@@ -1,4 +1,4 @@
-// Backbone.js 0.5.1
+// Backbone.js 0.5.2
// (c) 2010 Jeremy Ashkenas, DocumentCloud Inc.
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
@@ -25,7 +25,7 @@
}
// Current version of the library. Keep in sync with `package.json`.
- Backbone.VERSION = '0.5.1';
+ Backbone.VERSION = '0.5.2';
// Require Underscore, if we're on the server, and it's not already present.
var _ = root._;
@@ -68,10 +68,10 @@
// Bind an event, specified by a string name, `ev`, to a `callback` function.
// Passing `"all"` will bind the callback to all events fired.
- bind : function(ev, callback) {
+ bind : function(ev, callback, context) {
var calls = this._callbacks || (this._callbacks = {});
var list = calls[ev] || (calls[ev] = []);
- list.push(callback);
+ list.push([callback, context || this]);
return this;
},
@@ -89,7 +89,7 @@
var list = calls[ev];
if (!list) return this;
for (var i = 0, l = list.length; i < l; i++) {
- if (callback === list[i]) {
+ if (list[i] && callback === list[i][0]) {
list[i] = null;
break;
}
@@ -114,7 +114,7 @@
list.splice(i, 1); i--; l--;
} else {
args = both ? Array.prototype.slice.call(arguments, 1) : arguments;
- callback.apply(this, args);
+ callback[0].apply(callback[1], args);
}
}
}
@@ -133,7 +133,7 @@
var defaults;
attributes || (attributes = {});
if (defaults = this.defaults) {
- if (_.isFunction(defaults)) defaults = defaults();
+ if (_.isFunction(defaults)) defaults = defaults.call(this);
attributes = _.extend({}, defaults, attributes);
}
this.attributes = {};
@@ -806,6 +806,8 @@
if (this._wantsPushState && !this._hasPushState && !atRoot) {
this.fragment = this.getFragment(null, true);
window.location.replace(this.options.root + '#' + this.fragment);
+ // Return immediately as browser will do redirect to new url
+ return true;
} else if (this._wantsPushState && this._hasPushState && atRoot && loc.hash) {
this.fragment = loc.hash.replace(hashStrip, '');
window.history.replaceState({}, document.title, loc.protocol + '//' + loc.host + this.options.root + this.fragment);
@@ -1035,8 +1037,7 @@
// Default JSON-request options.
var params = _.extend({
type: type,
- dataType: 'json',
- processData: false
+ dataType: 'json'
}, options);
// Ensure that we have a URL.
@@ -1053,7 +1054,6 @@
// For older servers, emulate JSON by encoding the request into an HTML-form.
if (Backbone.emulateJSON) {
params.contentType = 'application/x-www-form-urlencoded';
- params.processData = true;
params.data = params.data ? {model : params.data} : {};
}
@@ -1069,6 +1069,11 @@
}
}
+ // Don't process data on a non-GET request.
+ if (params.type !== 'GET' && ! Backbone.emulateJSON) {
+ params.processData = false;
+ }
+
// Make the request.
return $.ajax(params);
};
Please sign in to comment.
Something went wrong with that request. Please try again.