Update vendor/backbone.

This commit is contained in:
John-David Dalton
2016-03-25 14:14:52 -07:00
parent 71c0861675
commit 97193b9680
4 changed files with 68 additions and 40 deletions

View File

@@ -101,11 +101,6 @@
assert.equal(collection2.get(model.clone()), collection2.first());
});
QUnit.test('get with "undefined" id', function(assert) {
var collection = new Backbone.Collection([{id: 1}, {id: 'undefined'}]);
assert.equal(collection.get(1).id, 1);
});
QUnit.test('has', function(assert) {
assert.expect(15);
assert.ok(col.has(a));
@@ -1583,7 +1578,7 @@
});
QUnit.test('_addReference binds all collection events & adds to the lookup hashes', function(assert) {
assert.expect(9);
assert.expect(8);
var calls = {add: 0, remove: 0};
@@ -1603,7 +1598,6 @@
assert.equal(this._byId[model.id], void 0);
assert.equal(this._byId[model.cid], void 0);
assert.equal(model.collection, void 0);
assert.equal(model._events, void 0);
}
});
@@ -1739,13 +1733,14 @@
assert.equal(c2.modelId(m.attributes), void 0);
});
QUnit.test('#3039: adding at index fires with correct at', function(assert) {
assert.expect(3);
var collection = new Backbone.Collection([{at: 0}, {at: 4}]);
QUnit.test('#3039 #3951: adding at index fires with correct at', function(assert) {
assert.expect(4);
var collection = new Backbone.Collection([{val: 0}, {val: 4}]);
collection.on('add', function(model, coll, options) {
assert.equal(model.get('at'), options.index);
assert.equal(model.get('val'), options.index);
});
collection.add([{at: 1}, {at: 2}, {at: 3}], {at: 1});
collection.add([{val: 1}, {val: 2}, {val: 3}], {at: 1});
collection.add({val: 5}, {at: 10});
});
QUnit.test('#3039: index is not sent when at is not specified', function(assert) {

View File

@@ -417,6 +417,18 @@
assert.equal(obj.counterB, 1, 'counterB should have only been incremented once.');
});
QUnit.test('bind a callback with a default context when none supplied', function(assert) {
assert.expect(1);
var obj = _.extend({
assertTrue: function() {
assert.equal(this, obj, '`this` was bound to the callback');
}
}, Backbone.Events);
obj.once('event', obj.assertTrue);
obj.trigger('event');
});
QUnit.test('bind a callback with a supplied context', function(assert) {
assert.expect(1);
var TestClass = function() {
@@ -587,6 +599,19 @@
assert.equal(obj.counter, 3);
});
QUnit.test('bind a callback with a supplied context using once with object notation', function(assert) {
assert.expect(1);
var obj = {counter: 0};
var context = {};
_.extend(obj, Backbone.Events);
obj.once({
a: function() {
assert.strictEqual(this, context, 'defaults `context` to `callback` param');
}
}, context).trigger('a');
});
QUnit.test('once with off only by context', function(assert) {
assert.expect(0);
var context = {};

View File

@@ -34,6 +34,12 @@
assert.equal(model.collection, collection);
});
QUnit.test('Object.prototype properties are overridden by attributes', function(assert) {
assert.expect(1);
var model = new Backbone.Model({hasOwnProperty: true});
assert.equal(model.get('hasOwnProperty'), true);
});
QUnit.test('initialize with attributes and options', function(assert) {
assert.expect(1);
var Model = Backbone.Model.extend({
@@ -57,19 +63,6 @@
assert.equal(model.get('value'), 2);
});
QUnit.test('initialize with defaults', function(assert) {
assert.expect(2);
var Model = Backbone.Model.extend({
defaults: {
firstName: 'Unknown',
lastName: 'Unknown'
}
});
var model = new Model({'firstName': 'John'});
assert.equal(model.get('firstName'), 'John');
assert.equal(model.get('lastName'), 'Unknown');
});
QUnit.test('parse can return null', function(assert) {
assert.expect(1);
var Model = Backbone.Model.extend({
@@ -428,7 +421,7 @@
});
QUnit.test('defaults', function(assert) {
assert.expect(4);
assert.expect(9);
var Defaulted = Backbone.Model.extend({
defaults: {
one: 1,
@@ -438,6 +431,9 @@
var model = new Defaulted({two: undefined});
assert.equal(model.get('one'), 1);
assert.equal(model.get('two'), 2);
model = new Defaulted({two: 3});
assert.equal(model.get('one'), 1);
assert.equal(model.get('two'), 3);
Defaulted = Backbone.Model.extend({
defaults: function() {
return {
@@ -449,6 +445,15 @@
model = new Defaulted({two: undefined});
assert.equal(model.get('one'), 3);
assert.equal(model.get('two'), 4);
Defaulted = Backbone.Model.extend({
defaults: {hasOwnProperty: true}
});
model = new Defaulted();
assert.equal(model.get('hasOwnProperty'), true);
model = new Defaulted({hasOwnProperty: undefined});
assert.equal(model.get('hasOwnProperty'), true);
model = new Defaulted({hasOwnProperty: false});
assert.equal(model.get('hasOwnProperty'), false);
});
QUnit.test('change, hasChanged, changedAttributes, previous, previousAttributes', function(assert) {
@@ -989,8 +994,8 @@
QUnit.test('`previous` for falsey keys', function(assert) {
assert.expect(2);
var model = new Backbone.Model({0: true, '': true});
model.set({0: false, '': false}, {silent: true});
var model = new Backbone.Model({'0': true, '': true});
model.set({'0': false, '': false}, {silent: true});
assert.equal(model.previous(0), true);
assert.equal(model.previous(''), true);
});