Update vendors.

Former-commit-id: b1b94d80548df89b3ce0ddd71b1e938f31666052
This commit is contained in:
John-David Dalton
2013-03-23 23:23:57 -07:00
parent 850c253e08
commit 2705a488ad
12 changed files with 904 additions and 581 deletions

View File

@@ -26,7 +26,7 @@
var closureId = 'a95a8007892aa824ce90c6aa3d3abb0489bf0fff'; var closureId = 'a95a8007892aa824ce90c6aa3d3abb0489bf0fff';
/** The Git object ID of `uglifyjs.tar.gz` */ /** The Git object ID of `uglifyjs.tar.gz` */
var uglifyId = '548bf495606eb4046c4573b1107f0225e274e1e1'; var uglifyId = '41308bd569db41a32d4f08af115875d0342e8bfb';
/** The path of the directory that is the base of the repository */ /** The path of the directory that is the base of the repository */
var basePath = fs.realpathSync(path.join(__dirname, '..')); var basePath = fs.realpathSync(path.join(__dirname, '..'));
@@ -455,6 +455,7 @@
toplevel.figure_out_scope(); toplevel.figure_out_scope();
toplevel = toplevel.transform(uglifyJS.Compressor({ toplevel = toplevel.transform(uglifyJS.Compressor({
'comparisons': false, 'comparisons': false,
'unsafe': true,
'unsafe_comps': true, 'unsafe_comps': true,
'warnings': false 'warnings': false
})); }));

View File

@@ -1,4 +1,4 @@
Copyright (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Copyright (c) 2010-2013 Jeremy Ashkenas, DocumentCloud
Permission is hereby granted, free of charge, to any person Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation obtaining a copy of this software and associated documentation

File diff suppressed because it is too large Load Diff

View File

@@ -62,30 +62,29 @@ $(document).ready(function() {
strictEqual(collection.last().get('a'), 4); strictEqual(collection.last().get('a'), 4);
}); });
test("get", 5, function() { test("get", 6, function() {
equal(col.get(0), d); equal(col.get(0), d);
equal(col.get(d.clone()), d);
equal(col.get(2), b); equal(col.get(2), b);
equal(col.get({id: 1}), c); equal(col.get({id: 1}), c);
equal(col.get(c.clone()), c); equal(col.get(c.clone()), c);
equal(col.get(col.first().cid), col.first()); equal(col.get(col.first().cid), col.first());
}); });
test("get with non-default ids", 4, function() { test("get with non-default ids", 5, function() {
var col = new Backbone.Collection(); var col = new Backbone.Collection();
var MongoModel = Backbone.Model.extend({ var MongoModel = Backbone.Model.extend({idAttribute: '_id'});
idAttribute: '_id'
});
var model = new MongoModel({_id: 100}); var model = new MongoModel({_id: 100});
col.push(model); col.add(model);
equal(col.get(100), model); equal(col.get(100), model);
model.set({_id: 101}); equal(col.get(model.cid), model);
equal(col.get(101), model); equal(col.get(model), model);
equal(col.get(101), void 0);
var Col2 = Backbone.Collection.extend({ model: MongoModel }); var col2 = new Backbone.Collection();
var col2 = new Col2(); col2.model = MongoModel;
col2.push(model); col2.add(model.attributes);
equal(col2.get({_id: 101}), model); equal(col2.get(model.clone()), col2.first());
equal(col2.get(model.clone()), model);
}); });
test("update index when id changes", 3, function() { test("update index when id changes", 3, function() {
@@ -226,6 +225,19 @@ $(document).ready(function() {
equal(col.at(0).get('value'), 2); equal(col.at(0).get('value'), 2);
}); });
test("add with parse and merge", function() {
var Model = Backbone.Model.extend({
parse: function (data) {
return data.model;
}
});
var collection = new Backbone.Collection();
collection.model = Model;
collection.add({id: 1});
collection.add({model: {id: 1, name: 'Alf'}}, {parse: true, merge: true});
equal(collection.first().get('name'), 'Alf');
});
test("add model to collection with sort()-style comparator", 3, function() { test("add model to collection with sort()-style comparator", 3, function() {
var col = new Backbone.Collection; var col = new Backbone.Collection;
col.comparator = function(a, b) { col.comparator = function(a, b) {
@@ -362,9 +374,7 @@ $(document).ready(function() {
test("model destroy removes from all collections", 3, function() { test("model destroy removes from all collections", 3, function() {
var e = new Backbone.Model({id: 5, title: 'Othello'}); var e = new Backbone.Model({id: 5, title: 'Othello'});
e.sync = function(method, model, options) { e.sync = function(method, model, options) { options.success(); };
options.success(model, [], options);
};
var colE = new Backbone.Collection([e]); var colE = new Backbone.Collection([e]);
var colF = new Backbone.Collection([e]); var colF = new Backbone.Collection([e]);
e.destroy(); e.destroy();
@@ -396,6 +406,15 @@ $(document).ready(function() {
equal(this.syncArgs.options.parse, false); equal(this.syncArgs.options.parse, false);
}); });
test("fetch with an error response triggers an error event", 1, function () {
var collection = new Backbone.Collection();
collection.on('error', function () {
ok(true);
});
collection.sync = function (method, model, options) { options.error(); };
collection.fetch();
});
test("ensure fetch only parses once", 1, function() { test("ensure fetch only parses once", 1, function() {
var collection = new Backbone.Collection; var collection = new Backbone.Collection;
var counter = 0; var counter = 0;
@@ -405,7 +424,7 @@ $(document).ready(function() {
}; };
collection.url = '/test'; collection.url = '/test';
collection.fetch(); collection.fetch();
this.syncArgs.options.success([]); this.syncArgs.options.success();
equal(counter, 1); equal(counter, 1);
}); });
@@ -419,7 +438,7 @@ $(document).ready(function() {
equal(model.collection, collection); equal(model.collection, collection);
}); });
test("create with validate:true enforces validation", 1, function() { test("create with validate:true enforces validation", 2, function() {
var ValidatingModel = Backbone.Model.extend({ var ValidatingModel = Backbone.Model.extend({
validate: function(attrs) { validate: function(attrs) {
return "fail"; return "fail";
@@ -429,6 +448,9 @@ $(document).ready(function() {
model: ValidatingModel model: ValidatingModel
}); });
var col = new ValidatingCollection(); var col = new ValidatingCollection();
col.on('invalid', function (collection, attrs, options) {
equal(options.validationError, 'fail');
});
equal(col.create({"foo":"bar"}, {validate:true}), false); equal(col.create({"foo":"bar"}, {validate:true}), false);
}); });
@@ -461,9 +483,10 @@ $(document).ready(function() {
equal(JSON.stringify(col), '[{"id":3,"label":"a"},{"id":2,"label":"b"},{"id":1,"label":"c"},{"id":0,"label":"d"}]'); equal(JSON.stringify(col), '[{"id":3,"label":"a"},{"id":2,"label":"b"},{"id":1,"label":"c"},{"id":0,"label":"d"}]');
}); });
test("where", 6, function() { test("where and findWhere", 8, function() {
var model = new Backbone.Model({a: 1});
var coll = new Backbone.Collection([ var coll = new Backbone.Collection([
{a: 1}, model,
{a: 1}, {a: 1},
{a: 1, b: 2}, {a: 1, b: 2},
{a: 2, b: 2}, {a: 2, b: 2},
@@ -475,6 +498,8 @@ $(document).ready(function() {
equal(coll.where({b: 1}).length, 0); equal(coll.where({b: 1}).length, 0);
equal(coll.where({b: 2}).length, 2); equal(coll.where({b: 2}).length, 2);
equal(coll.where({a: 1, b: 2}).length, 1); equal(coll.where({a: 1, b: 2}).length, 1);
equal(coll.findWhere({a: 1}), model);
equal(coll.findWhere({a: 4}), void 0);
}); });
test("Underscore methods", 13, function() { test("Underscore methods", 13, function() {
@@ -484,10 +509,10 @@ $(document).ready(function() {
equal(col.indexOf(b), 1); equal(col.indexOf(b), 1);
equal(col.size(), 4); equal(col.size(), 4);
equal(col.rest().length, 3); equal(col.rest().length, 3);
ok(!_.include(col.rest()), a); ok(!_.include(col.rest(), a));
ok(!_.include(col.rest()), d); ok(_.include(col.rest(), d));
ok(!col.isEmpty()); ok(!col.isEmpty());
ok(!_.include(col.without(d)), d); ok(!_.include(col.without(d), d));
equal(col.max(function(model){ return model.id; }).id, 3); equal(col.max(function(model){ return model.id; }).id, 3);
equal(col.min(function(model){ return model.id; }).id, 0); equal(col.min(function(model){ return model.id; }).id, 0);
deepEqual(col.chain() deepEqual(col.chain()
@@ -509,9 +534,9 @@ $(document).ready(function() {
}), 1); }), 1);
}); });
test("reset", 10, function() { test("reset", 12, function() {
var resetCount = 0; var resetCount = 0;
var models = col.models.slice(); var models = col.models;
col.on('reset', function() { resetCount += 1; }); col.on('reset', function() { resetCount += 1; });
col.reset([]); col.reset([]);
equal(resetCount, 1); equal(resetCount, 1);
@@ -526,6 +551,22 @@ $(document).ready(function() {
equal(col.length, 4); equal(col.length, 4);
ok(col.last() !== d); ok(col.last() !== d);
ok(_.isEqual(col.last().attributes, d.attributes)); ok(_.isEqual(col.last().attributes, d.attributes));
col.reset();
equal(col.length, 0);
equal(resetCount, 4);
});
test ("reset with different values", function(){
var col = new Backbone.Collection({id: 1});
col.reset({id: 1, a: 1});
equal(col.get(1).get('a'), 1);
});
test("same references in reset", function() {
var model = new Backbone.Model({id: 1});
var collection = new Backbone.Collection({id: 1});
collection.reset(model);
equal(collection.get(1), model);
}); });
test("reset passes caller options", 3, function() { test("reset passes caller options", 3, function() {
@@ -702,9 +743,7 @@ $(document).ready(function() {
test("#1447 - create with wait adds model.", 1, function() { test("#1447 - create with wait adds model.", 1, function() {
var collection = new Backbone.Collection; var collection = new Backbone.Collection;
var model = new Backbone.Model; var model = new Backbone.Model;
model.sync = function(method, model, options){ model.sync = function(method, model, options){ options.success(); };
options.success(model, [], options);
};
collection.on('add', function(){ ok(true); }); collection.on('add', function(){ ok(true); });
collection.create(model, {wait: true}); collection.create(model, {wait: true});
}); });
@@ -834,7 +873,7 @@ $(document).ready(function() {
collection.reset([]); collection.reset([]);
}); });
test("update", function() { test("set", function() {
var m1 = new Backbone.Model(); var m1 = new Backbone.Model();
var m2 = new Backbone.Model({id: 2}); var m2 = new Backbone.Model({id: 2});
var m3 = new Backbone.Model(); var m3 = new Backbone.Model();
@@ -852,24 +891,24 @@ $(document).ready(function() {
}); });
// remove: false doesn't remove any models // remove: false doesn't remove any models
c.update([], {remove: false}); c.set([], {remove: false});
strictEqual(c.length, 2); strictEqual(c.length, 2);
// add: false doesn't add any models // add: false doesn't add any models
c.update([m1, m2, m3], {add: false}); c.set([m1, m2, m3], {add: false});
strictEqual(c.length, 2); strictEqual(c.length, 2);
// merge: false doesn't change any models // merge: false doesn't change any models
c.update([m1, {id: 2, a: 1}], {merge: false}); c.set([m1, {id: 2, a: 1}], {merge: false});
strictEqual(m2.get('a'), void 0); strictEqual(m2.get('a'), void 0);
// add: false, remove: false only merges existing models // add: false, remove: false only merges existing models
c.update([m1, {id: 2, a: 0}, m3, {id: 4}], {add: false, remove: false}); c.set([m1, {id: 2, a: 0}, m3, {id: 4}], {add: false, remove: false});
strictEqual(c.length, 2); strictEqual(c.length, 2);
strictEqual(m2.get('a'), 0); strictEqual(m2.get('a'), 0);
// default options add/remove/merge as appropriate // default options add/remove/merge as appropriate
c.update([{id: 2, a: 1}, m3]); c.set([{id: 2, a: 1}, m3]);
strictEqual(c.length, 2); strictEqual(c.length, 2);
strictEqual(m2.get('a'), 1); strictEqual(m2.get('a'), 1);
@@ -877,23 +916,23 @@ $(document).ready(function() {
c.off('remove').on('remove', function(model) { c.off('remove').on('remove', function(model) {
ok(model === m2 || model === m3); ok(model === m2 || model === m3);
}); });
c.update([]); c.set([]);
strictEqual(c.length, 0); strictEqual(c.length, 0);
}); });
test("update with only cids", 3, function() { test("set with only cids", 3, function() {
var m1 = new Backbone.Model; var m1 = new Backbone.Model;
var m2 = new Backbone.Model; var m2 = new Backbone.Model;
var c = new Backbone.Collection; var c = new Backbone.Collection;
c.update([m1, m2]); c.set([m1, m2]);
equal(c.length, 2); equal(c.length, 2);
c.update([m1]); c.set([m1]);
equal(c.length, 1); equal(c.length, 1);
c.update([m1, m1, m1, m2, m2], {remove: false}); c.set([m1, m1, m1, m2, m2], {remove: false});
equal(c.length, 2); equal(c.length, 2);
}); });
test("update with only idAttribute", 3, function() { test("set with only idAttribute", 3, function() {
var m1 = { _id: 1 }; var m1 = { _id: 1 };
var m2 = { _id: 2 }; var m2 = { _id: 2 };
var col = Backbone.Collection.extend({ var col = Backbone.Collection.extend({
@@ -902,15 +941,15 @@ $(document).ready(function() {
}) })
}); });
var c = new col; var c = new col;
c.update([m1, m2]); c.set([m1, m2]);
equal(c.length, 2); equal(c.length, 2);
c.update([m1]); c.set([m1]);
equal(c.length, 1); equal(c.length, 1);
c.update([m1, m1, m1, m2, m2], {remove: false}); c.set([m1, m1, m1, m2, m2], {remove: false});
equal(c.length, 2); equal(c.length, 2);
}); });
test("update + merge with default values defined", function() { test("set + merge with default values defined", function() {
var Model = Backbone.Model.extend({ var Model = Backbone.Model.extend({
defaults: { defaults: {
key: 'value' key: 'value'
@@ -920,14 +959,43 @@ $(document).ready(function() {
var col = new Backbone.Collection([m], {model: Model}); var col = new Backbone.Collection([m], {model: Model});
equal(col.first().get('key'), 'value'); equal(col.first().get('key'), 'value');
col.update({id: 1, key: 'other'}); col.set({id: 1, key: 'other'});
equal(col.first().get('key'), 'other'); equal(col.first().get('key'), 'other');
col.update({id: 1, other: 'value'}); col.set({id: 1, other: 'value'});
equal(col.first().get('key'), 'other'); equal(col.first().get('key'), 'value');
equal(col.length, 1); equal(col.length, 1);
}); });
test("`set` and model level `parse`", function() {
var Model = Backbone.Model.extend({
parse: function (res) { return res.model; }
});
var Collection = Backbone.Collection.extend({
model: Model,
parse: function (res) { return res.models; }
});
var model = new Model({id: 1});
var collection = new Collection(model);
collection.set({models: [
{model: {id: 1}},
{model: {id: 2}}
]}, {parse: true});
equal(collection.first(), model);
});
test("`set` data is only parsed once", function() {
var collection = new Backbone.Collection();
collection.model = Backbone.Model.extend({
parse: function (data) {
equal(data.parsed, void 0);
data.parsed = true;
return data;
}
});
collection.set({}, {parse: true});
});
test("#1894 - Push should not trigger a sort", 0, function() { test("#1894 - Push should not trigger a sort", 0, function() {
var Collection = Backbone.Collection.extend({ var Collection = Backbone.Collection.extend({
comparator: 'id', comparator: 'id',
@@ -938,12 +1006,12 @@ $(document).ready(function() {
new Collection().push({id: 1}); new Collection().push({id: 1});
}); });
test("`update` with non-normal id", function() { test("`set` with non-normal id", function() {
var Collection = Backbone.Collection.extend({ var Collection = Backbone.Collection.extend({
model: Backbone.Model.extend({idAttribute: '_id'}) model: Backbone.Model.extend({idAttribute: '_id'})
}); });
var collection = new Collection({_id: 1}); var collection = new Collection({_id: 1});
collection.update([{_id: 1, a: 1}], {add: false}); collection.set([{_id: 1, a: 1}], {add: false});
equal(collection.first().get('a'), 1); equal(collection.first().get('a'), 1);
}); });
@@ -955,7 +1023,7 @@ $(document).ready(function() {
new Collection().add({id: 1}, {sort: false}); new Collection().add({id: 1}, {sort: false});
}); });
test("#1915 - `parse` data in the right order in `update`", function() { test("#1915 - `parse` data in the right order in `set`", function() {
var collection = new (Backbone.Collection.extend({ var collection = new (Backbone.Collection.extend({
parse: function (data) { parse: function (data) {
strictEqual(data.status, 'ok'); strictEqual(data.status, 'ok');
@@ -963,7 +1031,7 @@ $(document).ready(function() {
} }
})); }));
var res = {status: 'ok', data:[{id: 1}]}; var res = {status: 'ok', data:[{id: 1}]};
collection.update(res, {parse: true}); collection.set(res, {parse: true});
}); });
asyncTest("#1939 - `parse` is passed `options`", 1, function () { asyncTest("#1939 - `parse` is passed `options`", 1, function () {
@@ -1001,7 +1069,7 @@ $(document).ready(function() {
test("`add` only `sort`s when necessary with comparator function", 3, function () { test("`add` only `sort`s when necessary with comparator function", 3, function () {
var collection = new (Backbone.Collection.extend({ var collection = new (Backbone.Collection.extend({
comparator: function(a, b) { comparator: function(a, b) {
a.get('a') > b.get('a') ? 1 : (a.get('a') < b.get('a') ? -1 : 0); return a.get('a') > b.get('a') ? 1 : (a.get('a') < b.get('a') ? -1 : 0);
} }
}))([{id: 1}, {id: 2}, {id: 3}]); }))([{id: 1}, {id: 2}, {id: 3}]);
collection.on('sort', function () { ok(true); }); collection.on('sort', function () { ok(true); });
@@ -1013,4 +1081,20 @@ $(document).ready(function() {
collection.add(collection.models, {merge: true}); // don't sort collection.add(collection.models, {merge: true}); // don't sort
}); });
test("Attach options to collection.", 3, function() {
var url = '/somewhere';
var model = new Backbone.Model;
var comparator = function(){};
var collection = new Backbone.Collection([], {
url: url,
model: model,
comparator: comparator
});
strictEqual(collection.url, url);
ok(collection.model === model);
ok(collection.comparator === comparator);
});
}); });

View File

@@ -99,6 +99,43 @@ $(document).ready(function() {
a.listenTo(b, 'event2', cb); a.listenTo(b, 'event2', cb);
a.stopListening(null, {event: cb}); a.stopListening(null, {event: cb});
b.trigger('event event2'); b.trigger('event event2');
b.off();
a.listenTo(b, 'event event2', cb);
a.stopListening(null, 'event');
a.stopListening();
b.trigger('event2');
});
test("listenToOnce and stopListening", 1, function() {
var a = _.extend({}, Backbone.Events);
var b = _.extend({}, Backbone.Events);
a.listenToOnce(b, 'all', function() { ok(true); });
b.trigger('anything');
b.trigger('anything');
a.listenToOnce(b, 'all', function() { ok(false); });
a.stopListening();
b.trigger('anything');
});
test("listenTo, listenToOnce and stopListening", 1, function() {
var a = _.extend({}, Backbone.Events);
var b = _.extend({}, Backbone.Events);
a.listenToOnce(b, 'all', function() { ok(true); });
b.trigger('anything');
b.trigger('anything');
a.listenTo(b, 'all', function() { ok(false); });
a.stopListening();
b.trigger('anything');
});
test("listenTo and stopListening with event maps", 1, function() {
var a = _.extend({}, Backbone.Events);
var b = _.extend({}, Backbone.Events);
a.listenTo(b, {change: function(){ ok(true); }});
b.trigger('change');
a.listenTo(b, {change: function(){ ok(false); }});
a.stopListening();
b.trigger('change');
}); });
test("listenTo yourself", 1, function(){ test("listenTo yourself", 1, function(){
@@ -241,6 +278,13 @@ $(document).ready(function() {
_.extend({}, Backbone.Events).on('test').trigger('test'); _.extend({}, Backbone.Events).on('test').trigger('test');
}); });
test("if callback is truthy but not a function, `on` should throw an error just like jQuery", 1, function() {
var view = _.extend({}, Backbone.Events).on('test', 'noop');
throws(function() {
view.trigger('test');
});
});
test("remove all events for a specific context", 4, function() { test("remove all events for a specific context", 4, function() {
var obj = _.extend({}, Backbone.Events); var obj = _.extend({}, Backbone.Events);
obj.on('x y all', function() { ok(true); }); obj.on('x y all', function() { ok(true); });
@@ -259,18 +303,6 @@ $(document).ready(function() {
obj.trigger('x y'); obj.trigger('x y');
}); });
test("off is chainable", 3, function() {
var obj = _.extend({}, Backbone.Events);
// With no events
ok(obj.off() === obj);
// When removing all events
obj.on('event', function(){}, obj);
ok(obj.off() === obj);
// When removing some events
obj.on('event', function(){}, obj);
ok(obj.off('event') === obj);
});
test("#1310 - off does not skip consecutive events", 0, function() { test("#1310 - off does not skip consecutive events", 0, function() {
var obj = _.extend({}, Backbone.Events); var obj = _.extend({}, Backbone.Events);
obj.on('event', function() { ok(false); }, obj); obj.on('event', function() { ok(false); }, obj);
@@ -400,4 +432,21 @@ $(document).ready(function() {
_.extend({}, Backbone.Events).once('event').trigger('event'); _.extend({}, Backbone.Events).once('event').trigger('event');
}); });
test("event functions are chainable", function() {
var obj = _.extend({}, Backbone.Events);
var obj2 = _.extend({}, Backbone.Events);
var fn = function() {};
equal(obj, obj.trigger('noeventssetyet'));
equal(obj, obj.off('noeventssetyet'));
equal(obj, obj.stopListening('noeventssetyet'));
equal(obj, obj.on('a', fn));
equal(obj, obj.once('c', fn));
equal(obj, obj.trigger('a'));
equal(obj, obj.listenTo(obj2, 'a', fn));
equal(obj, obj.listenToOnce(obj2, 'b', fn));
equal(obj, obj.off('a c'));
equal(obj, obj.stopListening(obj2, 'a'));
equal(obj, obj.stopListening());
});
}); });

View File

@@ -46,9 +46,9 @@ $(document).ready(function() {
test("initialize with parsed attributes", 1, function() { test("initialize with parsed attributes", 1, function() {
var Model = Backbone.Model.extend({ var Model = Backbone.Model.extend({
parse: function(obj) { parse: function(attrs) {
obj.value += 1; attrs.value += 1;
return obj; return attrs;
} }
}); });
var model = new Model({value: 1}, {parse: true}); var model = new Model({value: 1}, {parse: true});
@@ -69,8 +69,8 @@ $(document).ready(function() {
test("parse can return null", 1, function() { test("parse can return null", 1, function() {
var Model = Backbone.Model.extend({ var Model = Backbone.Model.extend({
parse: function(obj) { parse: function(attrs) {
obj.value += 1; attrs.value += 1;
return null; return null;
} }
}); });
@@ -111,6 +111,23 @@ $(document).ready(function() {
equal(model.url(), '/nested/1/collection/2'); equal(model.url(), '/nested/1/collection/2');
}); });
test('url and urlRoot are directly attached if passed in the options', 2, function () {
var model = new Backbone.Model({a: 1}, {url: '/test'});
var model2 = new Backbone.Model({a: 2}, {urlRoot: '/test2'});
equal(model.url, '/test');
equal(model2.urlRoot, '/test2');
});
test("underscore methods", 5, function() {
var model = new Backbone.Model({ 'foo': 'a', 'bar': 'b', 'baz': 'c' });
var model2 = model.clone();
deepEqual(model.keys(), ['foo', 'bar', 'baz']);
deepEqual(model.values(), ['a', 'b', 'c']);
deepEqual(model.invert(), { 'a': 'foo', 'b': 'bar', 'c': 'baz' });
deepEqual(model.pick('foo', 'baz'), {'foo': 'a', 'baz': 'c'});
deepEqual(model.omit('foo', 'bar'), {'baz': 'c'});
});
test("clone", 10, function() { test("clone", 10, function() {
var a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3}); var a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3});
var b = a.clone(); var b = a.clone();
@@ -324,7 +341,7 @@ $(document).ready(function() {
"two": 2 "two": 2
} }
}); });
var model = new Defaulted({two: null}); var model = new Defaulted({two: undefined});
equal(model.get('one'), 1); equal(model.get('one'), 1);
equal(model.get('two'), 2); equal(model.get('two'), 2);
Defaulted = Backbone.Model.extend({ Defaulted = Backbone.Model.extend({
@@ -335,7 +352,7 @@ $(document).ready(function() {
}; };
} }
}); });
model = new Defaulted({two: null}); model = new Defaulted({two: undefined});
equal(model.get('one'), 3); equal(model.get('one'), 3);
equal(model.get('two'), 4); equal(model.get('two'), 4);
}); });
@@ -401,7 +418,7 @@ $(document).ready(function() {
if (attrs.admin) return "Can't change admin status."; if (attrs.admin) return "Can't change admin status.";
}; };
model.sync = function(method, model, options) { model.sync = function(method, model, options) {
options.success.call(this, this, {admin: true}, options); options.success.call(this, {admin: true});
}; };
model.on('invalid', function(model, error) { model.on('invalid', function(model, error) {
lastError = error; lastError = error;
@@ -418,6 +435,19 @@ $(document).ready(function() {
ok(_.isEqual(this.syncArgs.model, doc)); ok(_.isEqual(this.syncArgs.model, doc));
}); });
test("save, fetch, destroy triggers error event when an error occurs", 3, function () {
var model = new Backbone.Model();
model.on('error', function () {
ok(true);
});
model.sync = function (method, model, options) {
options.error();
};
model.save({data: 2, id: 1});
model.fetch();
model.destroy();
});
test("save with PATCH", function() { test("save with PATCH", function() {
doc.clear().set({id: 1, a: 1, b: 2, c: 3, d: 4}); doc.clear().set({id: 1, a: 1, b: 2, c: 3, d: 4});
doc.save(); doc.save();
@@ -435,7 +465,7 @@ $(document).ready(function() {
test("save in positional style", 1, function() { test("save in positional style", 1, function() {
var model = new Backbone.Model(); var model = new Backbone.Model();
model.sync = function(method, model, options) { model.sync = function(method, model, options) {
options.success(model, {}, options); options.success();
}; };
model.save('title', 'Twelfth Night'); model.save('title', 'Twelfth Night');
equal(model.get('title'), 'Twelfth Night'); equal(model.get('title'), 'Twelfth Night');
@@ -444,8 +474,8 @@ $(document).ready(function() {
test("save with non-object success response", 2, function () { test("save with non-object success response", 2, function () {
var model = new Backbone.Model(); var model = new Backbone.Model();
model.sync = function(method, model, options) { model.sync = function(method, model, options) {
options.success(model, '', options); options.success('', options);
options.success(model, null, options); options.success(null, options);
}; };
model.save({testing:'empty'}, { model.save({testing:'empty'}, {
success: function (model) { success: function (model) {
@@ -720,7 +750,7 @@ $(document).ready(function() {
test("#1030 - `save` with `wait` results in correct attributes if success is called during sync", 2, function() { test("#1030 - `save` with `wait` results in correct attributes if success is called during sync", 2, function() {
var model = new Backbone.Model({x: 1, y: 2}); var model = new Backbone.Model({x: 1, y: 2});
model.sync = function(method, model, options) { model.sync = function(method, model, options) {
options.success(model, {}, options); options.success();
}; };
model.on("change:x", function() { ok(true); }); model.on("change:x", function() { ok(true); });
model.save({x: 3}, {wait: true}); model.save({x: 3}, {wait: true});
@@ -893,7 +923,7 @@ $(document).ready(function() {
} }
}; };
model.sync = function(method, model, options) { model.sync = function(method, model, options) {
options.success(model, {}, options); options.success();
}; };
model.save({id: 1}, opts); model.save({id: 1}, opts);
model.fetch(opts); model.fetch(opts);
@@ -902,9 +932,8 @@ $(document).ready(function() {
test("#1412 - Trigger 'sync' event.", 3, function() { test("#1412 - Trigger 'sync' event.", 3, function() {
var model = new Backbone.Model({id: 1}); var model = new Backbone.Model({id: 1});
model.url = '/test'; model.sync = function (method, model, options) { options.success(); };
model.on('sync', function(){ ok(true); }); model.on('sync', function(){ ok(true); });
Backbone.ajax = function(settings){ settings.success(); };
model.fetch(); model.fetch();
model.save(); model.save();
model.destroy(); model.destroy();
@@ -950,7 +979,7 @@ $(document).ready(function() {
var Model = Backbone.Model.extend({ var Model = Backbone.Model.extend({
sync: function(method, model, options) { sync: function(method, model, options) {
setTimeout(function(){ setTimeout(function(){
options.success(model, {}, options); options.success();
start(); start();
}, 0); }, 0);
} }

View File

@@ -57,6 +57,15 @@ $(document).ready(function() {
}); });
var ExternalObject = {
value: 'unset',
routingFunction: function(value) {
this.value = value;
}
};
_.bindAll(ExternalObject);
var Router = Backbone.Router.extend({ var Router = Backbone.Router.extend({
count: 0, count: 0,
@@ -73,8 +82,11 @@ $(document).ready(function() {
"optional(/:item)": "optionalItem", "optional(/:item)": "optionalItem",
"named/optional/(y:z)": "namedOptional", "named/optional/(y:z)": "namedOptional",
"splat/*args/end": "splat", "splat/*args/end": "splat",
"*first/complex-:part/*rest": "complex", ":repo/compare/*from...*to": "github",
"decode/:named/*splat": "decode",
"*first/complex-*part/*rest": "complex",
":entity?*args": "query", ":entity?*args": "query",
"function/:value": ExternalObject.routingFunction,
"*anything": "anything" "*anything": "anything"
}, },
@@ -116,6 +128,12 @@ $(document).ready(function() {
this.args = args; this.args = args;
}, },
github: function(repo, from, to) {
this.repo = repo;
this.from = from;
this.to = to;
},
complex: function(first, part, rest) { complex: function(first, part, rest) {
this.first = first; this.first = first;
this.part = part; this.part = part;
@@ -135,6 +153,11 @@ $(document).ready(function() {
this.z = z; this.z = z;
}, },
decode: function(named, path) {
this.named = named;
this.path = path;
},
routeEvent: function(arg) { routeEvent: function(arg) {
} }
@@ -153,6 +176,15 @@ $(document).ready(function() {
equal(lastArgs[0], 'news'); equal(lastArgs[0], 'news');
}); });
test("routes (simple, but unicode)", 4, function() {
location.replace('http://example.com#search/тест');
Backbone.history.checkUrl();
equal(router.query, "тест");
equal(router.page, void 0);
equal(lastRoute, 'search');
equal(lastArgs[0], "тест");
});
test("routes (two part)", 2, function() { test("routes (two part)", 2, function() {
location.replace('http://example.com#search/nyc/p10'); location.replace('http://example.com#search/nyc/p10');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
@@ -213,6 +245,14 @@ $(document).ready(function() {
equal(router.args, 'long-list/of/splatted_99args'); equal(router.args, 'long-list/of/splatted_99args');
}); });
test("routes (github)", 3, function() {
location.replace('http://example.com#backbone/compare/1.0...braddunbar:with/slash');
Backbone.history.checkUrl();
equal(router.repo, 'backbone');
equal(router.from, '1.0');
equal(router.to, 'braddunbar:with/slash');
});
test("routes (optional)", 2, function() { test("routes (optional)", 2, function() {
location.replace('http://example.com#optional'); location.replace('http://example.com#optional');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
@@ -246,6 +286,23 @@ $(document).ready(function() {
equal(router.anything, 'doesnt-match-a-route'); equal(router.anything, 'doesnt-match-a-route');
}); });
test("routes (function)", 3, function() {
router.on('route', function(name) {
ok(name === '');
});
equal(ExternalObject.value, 'unset');
location.replace('http://example.com#function/set');
Backbone.history.checkUrl();
equal(ExternalObject.value, 'set');
});
test("Decode named parameters, not splats.", 2, function() {
location.replace('http://example.com#decode/a%2Fb/c%2Fd/e');
Backbone.history.checkUrl();
strictEqual(router.named, 'a/b');
strictEqual(router.path, 'c/d/e');
});
test("fires event when router doesn't have callback on it", 1, function() { test("fires event when router doesn't have callback on it", 1, function() {
router.on("route:noCallback", function(){ ok(true); }); router.on("route:noCallback", function(){ ok(true); });
location.replace('http://example.com#noCallback'); location.replace('http://example.com#noCallback');
@@ -277,9 +334,9 @@ $(document).ready(function() {
test("#967 - Route callback gets passed encoded values.", 3, function() { test("#967 - Route callback gets passed encoded values.", 3, function() {
var route = 'has%2Fslash/complex-has%23hash/has%20space'; var route = 'has%2Fslash/complex-has%23hash/has%20space';
Backbone.history.navigate(route, {trigger: true}); Backbone.history.navigate(route, {trigger: true});
strictEqual(router.first, 'has%2Fslash'); strictEqual(router.first, 'has/slash');
strictEqual(router.part, 'has%23hash'); strictEqual(router.part, 'has#hash');
strictEqual(router.rest, 'has%20space'); strictEqual(router.rest, 'has space');
}); });
test("correctly handles URLs with % (#868)", 3, function() { test("correctly handles URLs with % (#868)", 3, function() {
@@ -529,4 +586,27 @@ $(document).ready(function() {
Backbone.history.checkUrl(); Backbone.history.checkUrl();
}); });
test("#2255 - Extend routes by making routes a function.", 1, function() {
var RouterBase = Backbone.Router.extend({
routes: function() {
return {
home: "root",
index: "index.html"
};
}
});
var RouterExtended = RouterBase.extend({
routes: function() {
var _super = RouterExtended.__super__.routes;
return _.extend(_super(),
{ show: "show",
search: "search" });
}
});
var router = new RouterExtended();
deepEqual({home: "root", index: "index.html", show: "show", search: "search"}, router.routes);
});
}); });

View File

@@ -85,6 +85,13 @@ $(document).ready(function() {
equal(view.counter, 3); equal(view.counter, 3);
}); });
test("delegateEvents ignore undefined methods", 0, function() {
var view = new Backbone.View({el: '<p></p>'});
view.delegateEvents({'click': 'undefinedMethod'});
view.$el.trigger('click');
});
test("undelegateEvents", 6, function() { test("undelegateEvents", 6, function() {
var counter1 = 0, counter2 = 0; var counter1 = 0, counter2 = 0;

View File

@@ -15,7 +15,7 @@ For a list of upcoming features, check out our [roadmap](https://github.com/best
## Support ## Support
Benchmark.js has been tested in at least Chrome 5~25, Firefox 1~19, IE 6-10, Opera 9.25-12, Safari 3-6, Node.js 0.4.8-0.8.22, Narwhal 0.3.2, PhantomJS 1.8.1, RingoJS 0.9, and Rhino 1.7RC5. Benchmark.js has been tested in at least Chrome 5~25, Firefox 1~19, IE 6-10, Opera 9.25-12, Safari 3-6, Node.js 0.4.8-0.10.1, Narwhal 0.3.2, PhantomJS 1.8.1, RingoJS 0.9, and Rhino 1.7RC5.
## Installation and usage ## Installation and usage

View File

@@ -18,7 +18,7 @@ For a list of upcoming features, check out our [roadmap](https://github.com/best
## Support ## Support
Platform.js has been tested in at least Chrome 5~25, Firefox 1~19, IE 6-10, Opera 9.25-12, Safari 3-6, Node.js 0.4.8-0.8.22, Narwhal 0.3.2, PhantomJS 1.8.1, RingoJS 0.9, and Rhino 1.7RC5. Platform.js has been tested in at least Chrome 5~25, Firefox 1~19, IE 6-10, Opera 9.25-12, Safari 3-6, Node.js 0.4.8-0.10.1, Narwhal 0.3.2, PhantomJS 1.8.1, RingoJS 0.9, and Rhino 1.7RC5.
## Installation and usage ## Installation and usage

View File

@@ -1,7 +1,7 @@
# QUnit CLIB <sup>v1.3.0</sup> # QUnit CLIB <sup>v1.3.0</sup>
## command-line interface boilerplate ## command-line interface boilerplate
QUnit CLIB helps extend QUnit's CLI support to many common CLI environments. QUnit CLIB helps extend QUnits CLI support to many common CLI environments.
## Screenshot ## Screenshot
@@ -9,7 +9,7 @@ QUnit CLIB helps extend QUnit's CLI support to many common CLI environments.
## Support ## Support
QUnit CLIB has been tested in at least Node.js 0.4.8-0.8.22, Narwhal 0.3.2, PhantomJS 1.8.1, RingoJS 0.9, and Rhino 1.7RC5. QUnit CLIB has been tested in at least Node.js 0.4.8-0.10.1, Narwhal 0.3.2, PhantomJS 1.8.1, RingoJS 0.9, and Rhino 1.7RC5.
## Usage ## Usage

View File

@@ -1,5 +1,5 @@
/*! /*!
* QUnit CLI Boilerplate v1.2.0 * QUnit CLI Boilerplate v1.3.0
* Copyright 2011-2012 John-David Dalton <http://allyoucanleet.com/> * Copyright 2011-2012 John-David Dalton <http://allyoucanleet.com/>
* Based on a gist by Jörn Zaefferer <https://gist.github.com/722381> * Based on a gist by Jörn Zaefferer <https://gist.github.com/722381>
* Available under MIT license <http://mths.be/mit> * Available under MIT license <http://mths.be/mit>