Update Underscore/Backbone vendors.

Former-commit-id: beb38126acaebf1045c2676aeda037e35f0b99c8
This commit is contained in:
John-David Dalton
2012-09-06 20:56:02 -07:00
parent 102d6d8c84
commit e3ec76418b
16 changed files with 265 additions and 236 deletions

View File

@@ -18,7 +18,7 @@ $(document).ready(function() {
}));
test("Collection: new and sort", 7, function() {
test("new and sort", 7, function() {
equal(col.first(), a, "a should be first");
equal(col.last(), d, "d should be last");
col.comparator = function(a, b) {
@@ -34,7 +34,7 @@ $(document).ready(function() {
equal(col.length, 4);
});
test("Collection: new and parse", 3, function() {
test("new and parse", 3, function() {
var Collection = Backbone.Collection.extend({
parse : function(data) {
return _.filter(data, function(datum) {
@@ -49,13 +49,13 @@ $(document).ready(function() {
strictEqual(collection.last().get('a'), 4);
});
test("Collection: get, getByCid", 3, function() {
test("get, getByCid", 3, function() {
equal(col.get(0), d);
equal(col.get(2), b);
equal(col.getByCid(col.first().cid), col.first());
});
test("Collection: get with non-default ids", 2, function() {
test("get with non-default ids", 2, function() {
var col = new Backbone.Collection();
var MongoModel = Backbone.Model.extend({
idAttribute: '_id'
@@ -67,7 +67,7 @@ $(document).ready(function() {
equal(col.get(101), model);
});
test("Collection: update index when id changes", 3, function() {
test("update index when id changes", 3, function() {
var col = new Backbone.Collection();
col.add([
{id : 0, name : 'one'},
@@ -80,15 +80,15 @@ $(document).ready(function() {
equal(col.get(101).get('name'), 'one');
});
test("Collection: at", 1, function() {
test("at", 1, function() {
equal(col.at(2), c);
});
test("Collection: pluck", 1, function() {
test("pluck", 1, function() {
equal(col.pluck('label').join(' '), 'a b c d');
});
test("Collection: add", 11, function() {
test("add", 11, function() {
var added, opts, secondAdded;
added = opts = secondAdded = null;
e = new Backbone.Model({id: 10, label : 'e'});
@@ -120,7 +120,7 @@ $(document).ready(function() {
equal(atCol.last(), h);
});
test("Collection: add multiple models", 6, function() {
test("add multiple models", 6, function() {
var col = new Backbone.Collection([{at: 0}, {at: 1}, {at: 9}]);
col.add([{at: 2}, {at: 3}, {at: 4}, {at: 5}, {at: 6}, {at: 7}, {at: 8}], {at: 2});
for (var i = 0; i <= 5; i++) {
@@ -128,7 +128,7 @@ $(document).ready(function() {
}
});
test("Collection: add; at should have preference over comparator", 1, function() {
test("add; at should have preference over comparator", 1, function() {
var Col = Backbone.Collection.extend({
comparator: function(a,b) {
return a.id > b.id ? -1 : 1;
@@ -141,19 +141,19 @@ $(document).ready(function() {
equal(col.pluck('id').join(' '), '3 1 2');
});
test("Collection: can't add model to collection twice", function() {
test("can't add model to collection twice", function() {
var col = new Backbone.Collection([{id: 1}, {id: 2}, {id: 1}, {id: 2}, {id: 3}]);
equal(col.pluck('id').join(' '), '1 2 3');
});
test("Collection: can't add different model with same id to collection twice", 1, function() {
test("can't add different model with same id to collection twice", 1, function() {
var col = new Backbone.Collection;
col.unshift({id: 101});
col.add({id: 101});
equal(col.length, 1);
});
test("Collection: merge in duplicate models with {merge: true}", 3, function() {
test("merge in duplicate models with {merge: true}", 3, function() {
var col = new Backbone.Collection;
col.add([{id: 1, name: 'Moe'}, {id: 2, name: 'Curly'}, {id: 3, name: 'Larry'}]);
col.add({id: 1, name: 'Moses'});
@@ -164,7 +164,7 @@ $(document).ready(function() {
equal(col.first().get('name'), 'Tim');
});
test("Collection: add model to multiple collections", 10, function() {
test("add model to multiple collections", 10, function() {
var counter = 0;
var e = new Backbone.Model({id: 10, label : 'e'});
e.on('add', function(model, collection) {
@@ -192,7 +192,7 @@ $(document).ready(function() {
equal(e.collection, colE);
});
test("Collection: add model with parse", 1, function() {
test("add model with parse", 1, function() {
var Model = Backbone.Model.extend({
parse: function(obj) {
obj.value += 1;
@@ -206,7 +206,7 @@ $(document).ready(function() {
equal(col.at(0).get('value'), 2);
});
test("Collection: 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;
col.comparator = function(a, b) {
return a.get('name') < b.get('name') ? -1 : 1;
@@ -222,7 +222,7 @@ $(document).ready(function() {
equal(col.indexOf(tom), 2);
});
test("Collection: comparator that depends on `this`", 1, function() {
test("comparator that depends on `this`", 1, function() {
var col = new Backbone.Collection;
col.negative = function(num) {
return -num;
@@ -234,7 +234,7 @@ $(document).ready(function() {
equal(col.pluck('id').join(' '), '3 2 1');
});
test("Collection: remove", 5, function() {
test("remove", 5, function() {
var removed = null;
var otherRemoved = null;
col.on('remove', function(model, col, options) {
@@ -251,20 +251,20 @@ $(document).ready(function() {
equal(otherRemoved, null);
});
test("Collection: shift and pop", 2, function() {
test("shift and pop", 2, function() {
var col = new Backbone.Collection([{a: 'a'}, {b: 'b'}, {c: 'c'}]);
equal(col.shift().get('a'), 'a');
equal(col.pop().get('c'), 'c');
});
test("Collection: slice", 2, function() {
test("slice", 2, function() {
var col = new Backbone.Collection([{a: 'a'}, {b: 'b'}, {c: 'c'}]);
var array = col.slice(1, 3);
equal(array.length, 2);
equal(array[0].get('b'), 'b');
});
test("Collection: events are unbound on remove", 3, function() {
test("events are unbound on remove", 3, function() {
var counter = 0;
var dj = new Backbone.Model();
var emcees = new Backbone.Collection([dj]);
@@ -277,7 +277,7 @@ $(document).ready(function() {
equal(counter, 1);
});
test("Collection: remove in multiple collections", 7, function() {
test("remove in multiple collections", 7, function() {
var modelData = {
id : 5,
title : 'Othello'
@@ -301,7 +301,7 @@ $(document).ready(function() {
equal(passed, true);
});
test("Collection: remove same model in multiple collection", 16, function() {
test("remove same model in multiple collection", 16, function() {
var counter = 0;
var e = new Backbone.Model({id: 5, title: 'Othello'});
e.on('remove', function(model, collection) {
@@ -335,7 +335,7 @@ $(document).ready(function() {
equal(counter, 2);
});
test("Collection: 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'});
e.sync = function(method, model, options) { options.success({}); };
var colE = new Backbone.Collection([e]);
@@ -357,7 +357,7 @@ $(document).ready(function() {
equal(undefined, e.collection);
});
test("Collection: fetch", 4, function() {
test("fetch", 4, function() {
var collection = new Backbone.Collection;
collection.url = '/test';
collection.fetch();
@@ -369,7 +369,7 @@ $(document).ready(function() {
equal(this.syncArgs.options.parse, false);
});
test("Collection: create", 4, function() {
test("create", 4, function() {
var collection = new Backbone.Collection;
collection.url = '/test';
var model = collection.create({label: 'f'}, {wait: true});
@@ -379,7 +379,7 @@ $(document).ready(function() {
equal(model.collection, collection);
});
test("Collection: create enforces validation", 1, function() {
test("create enforces validation", 1, function() {
var ValidatingModel = Backbone.Model.extend({
validate: function(attrs) {
return "fail";
@@ -392,7 +392,7 @@ $(document).ready(function() {
equal(col.create({"foo":"bar"}), false);
});
test("Collection: a failing create runs the error callback", 1, function() {
test("a failing create runs the error callback", 1, function() {
var ValidatingModel = Backbone.Model.extend({
validate: function(attrs) {
return "fail";
@@ -408,7 +408,7 @@ $(document).ready(function() {
equal(flag, true);
});
test("collection: initialize", 1, function() {
test("initialize", 1, function() {
var Collection = Backbone.Collection.extend({
initialize: function() {
this.one = 1;
@@ -418,11 +418,11 @@ $(document).ready(function() {
equal(coll.one, 1);
});
test("Collection: toJSON", 1, function() {
test("toJSON", 1, function() {
equal(JSON.stringify(col), '[{"id":3,"label":"a"},{"id":2,"label":"b"},{"id":1,"label":"c"},{"id":0,"label":"d"}]');
});
test("Collection: where", 6, function() {
test("where", 6, function() {
var coll = new Backbone.Collection([
{a: 1},
{a: 1},
@@ -438,7 +438,7 @@ $(document).ready(function() {
equal(coll.where({a: 1, b: 2}).length, 1);
});
test("Collection: Underscore methods", 13, function() {
test("Underscore methods", 13, function() {
equal(col.map(function(model){ return model.get('label'); }).join(' '), 'a b c d');
equal(col.any(function(model){ return model.id === 100; }), false);
equal(col.any(function(model){ return model.id === 0; }), true);
@@ -458,7 +458,7 @@ $(document).ready(function() {
[4, 0]);
});
test("Collection: reset", 10, function() {
test("reset", 10, function() {
var resetCount = 0;
var models = col.models;
col.on('reset', function() { resetCount += 1; });
@@ -477,7 +477,7 @@ $(document).ready(function() {
ok(_.isEqual(col.last().attributes, d.attributes));
});
test("Collection: reset passes caller options", 3, function() {
test("reset passes caller options", 3, function() {
var Model = Backbone.Model.extend({
initialize: function(attrs, options) {
this.model_parameter = options.model_parameter;
@@ -491,14 +491,14 @@ $(document).ready(function() {
});
});
test("Collection: trigger custom events on models", 1, function() {
test("trigger custom events on models", 1, function() {
var fired = null;
a.on("custom", function() { fired = true; });
a.trigger("custom");
equal(fired, true);
});
test("Collection: add does not alter arguments", 2, function(){
test("add does not alter arguments", 2, function(){
var attrs = {};
var models = [attrs];
new Backbone.Collection().add(models);
@@ -549,7 +549,7 @@ $(document).ready(function() {
});
});
test("Collection: index with comparator", 4, function() {
test("index with comparator", 4, function() {
var counter = 0;
var col = new Backbone.Collection([{id: 2}, {id: 4}], {
comparator: function(model){ return model.id; }
@@ -566,7 +566,7 @@ $(document).ready(function() {
col.add([{id: 3}, {id: 1}]);
});
test("Collection: throwing during add leaves consistent state", 4, function() {
test("throwing during add leaves consistent state", 4, function() {
var col = new Backbone.Collection();
col.on('test', function() { ok(false); });
col.model = Backbone.Model.extend({
@@ -580,7 +580,7 @@ $(document).ready(function() {
equal(col.length, 0);
});
test("Collection: multiple copies of the same model", 3, function() {
test("multiple copies of the same model", 3, function() {
var col = new Backbone.Collection();
var model = new Backbone.Model();
col.add([model, model]);
@@ -613,7 +613,7 @@ $(document).ready(function() {
ok(!collection.get('undefined'));
});
test("Collection: falsy comparator", 4, function(){
test("falsy comparator", 4, function(){
var Col = Backbone.Collection.extend({
comparator: function(model){ return model.id; }
});

View File

@@ -2,7 +2,7 @@ $(document).ready(function() {
module("Backbone.Events");
test("Events: on and trigger", 2, function() {
test("on and trigger", 2, function() {
var obj = { counter: 0 };
_.extend(obj,Backbone.Events);
obj.on('event', function() { obj.counter += 1; });
@@ -15,7 +15,7 @@ $(document).ready(function() {
equal(obj.counter, 5, 'counter should be incremented five times.');
});
test("Events: binding and triggering multiple events", 4, function() {
test("binding and triggering multiple events", 4, function() {
var obj = { counter: 0 };
_.extend(obj,Backbone.Events);
@@ -35,7 +35,7 @@ $(document).ready(function() {
equal(obj.counter, 5);
});
test("Events: trigger all for each event", 3, function() {
test("trigger all for each event", 3, function() {
var a, b, obj = { counter: 0 };
_.extend(obj, Backbone.Events);
obj.on('all', function(event) {
@@ -49,7 +49,7 @@ $(document).ready(function() {
equal(obj.counter, 2);
});
test("Events: on, then unbind all functions", 1, function() {
test("on, then unbind all functions", 1, function() {
var obj = { counter: 0 };
_.extend(obj,Backbone.Events);
var callback = function() { obj.counter += 1; };
@@ -60,7 +60,7 @@ $(document).ready(function() {
equal(obj.counter, 1, 'counter should have only been incremented once.');
});
test("Events: bind two callbacks, unbind only one", 2, function() {
test("bind two callbacks, unbind only one", 2, function() {
var obj = { counterA: 0, counterB: 0 };
_.extend(obj,Backbone.Events);
var callback = function() { obj.counterA += 1; };
@@ -73,7 +73,7 @@ $(document).ready(function() {
equal(obj.counterB, 2, 'counterB should have been incremented twice.');
});
test("Events: unbind a callback in the midst of it firing", 1, function() {
test("unbind a callback in the midst of it firing", 1, function() {
var obj = {counter: 0};
_.extend(obj, Backbone.Events);
var callback = function() {
@@ -87,7 +87,7 @@ $(document).ready(function() {
equal(obj.counter, 1, 'the callback should have been unbound.');
});
test("Events: two binds that unbind themeselves", 2, function() {
test("two binds that unbind themeselves", 2, function() {
var obj = { counterA: 0, counterB: 0 };
_.extend(obj,Backbone.Events);
var incrA = function(){ obj.counterA += 1; obj.off('event', incrA); };
@@ -101,7 +101,7 @@ $(document).ready(function() {
equal(obj.counterB, 1, 'counterB should have only been incremented once.');
});
test("Events: bind a callback with a supplied context", 1, function () {
test("bind a callback with a supplied context", 1, function () {
var TestClass = function () {
return this;
};
@@ -114,7 +114,7 @@ $(document).ready(function() {
obj.trigger('event');
});
test("Events: nested trigger with unbind", 1, function () {
test("nested trigger with unbind", 1, function () {
var obj = { counter: 0 };
_.extend(obj, Backbone.Events);
var incr1 = function(){ obj.counter += 1; obj.off('event', incr1); obj.trigger('event'); };
@@ -125,7 +125,7 @@ $(document).ready(function() {
equal(obj.counter, 3, 'counter should have been incremented three times');
});
test("Events: callback list is not altered during trigger", 2, function () {
test("callback list is not altered during trigger", 2, function () {
var counter = 0, obj = _.extend({}, Backbone.Events);
var incr = function(){ counter++; };
obj.on('event', function(){ obj.on('event', incr).on('all', incr); })

View File

@@ -22,7 +22,7 @@ $(document).ready(function() {
}));
test("Model: initialize", 3, function() {
test("initialize", 3, function() {
var Model = Backbone.Model.extend({
initialize: function() {
this.one = 1;
@@ -34,7 +34,7 @@ $(document).ready(function() {
equal(model.collection, collection);
});
test("Model: initialize with attributes and options", 1, function() {
test("initialize with attributes and options", 1, function() {
var Model = Backbone.Model.extend({
initialize: function(attributes, options) {
this.one = options.one;
@@ -44,7 +44,7 @@ $(document).ready(function() {
equal(model.one, 1);
});
test("Model: initialize with parsed attributes", 1, function() {
test("initialize with parsed attributes", 1, function() {
var Model = Backbone.Model.extend({
parse: function(obj) {
obj.value += 1;
@@ -55,7 +55,7 @@ $(document).ready(function() {
equal(model.get('value'), 2);
});
test("Model: url", 3, function() {
test("url", 3, function() {
doc.urlRoot = null;
equal(doc.url(), '/collection/1-the-tempest');
doc.collection.url = '/collection/';
@@ -65,7 +65,7 @@ $(document).ready(function() {
doc.collection = collection;
});
test("Model: url when using urlRoot, and uri encoding", 2, function() {
test("url when using urlRoot, and uri encoding", 2, function() {
var Model = Backbone.Model.extend({
urlRoot: '/collection'
});
@@ -75,7 +75,7 @@ $(document).ready(function() {
equal(model.url(), '/collection/%2B1%2B');
});
test("Model: url when using urlRoot as a function to determine urlRoot at runtime", 2, function() {
test("url when using urlRoot as a function to determine urlRoot at runtime", 2, function() {
var Model = Backbone.Model.extend({
urlRoot: function() {
return '/nested/' + this.get('parent_id') + '/collection';
@@ -88,7 +88,7 @@ $(document).ready(function() {
equal(model.url(), '/nested/1/collection/2');
});
test("Model: clone", 8, function() {
test("clone", 8, function() {
var a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3});
var b = a.clone();
equal(a.get('foo'), 1);
@@ -102,7 +102,7 @@ $(document).ready(function() {
equal(b.get('foo'), 1, "Changing a parent attribute does not change the clone.");
});
test("Model: isNew", 6, function() {
test("isNew", 6, function() {
var a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3});
ok(a.isNew(), "it should be new");
a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3, 'id': -5 });
@@ -114,12 +114,12 @@ $(document).ready(function() {
ok(!new Backbone.Model({ 'id': -5 }).isNew(), "is false for a negative integer");
});
test("Model: get", 2, function() {
test("get", 2, function() {
equal(doc.get('title'), 'The Tempest');
equal(doc.get('author'), 'Bill Shakespeare');
});
test("Model: escape", 5, function() {
test("escape", 5, function() {
equal(doc.escape('title'), 'The Tempest');
doc.set({audience: 'Bill & Bob'});
equal(doc.escape('audience'), 'Bill &amp; Bob');
@@ -131,7 +131,7 @@ $(document).ready(function() {
equal(doc.escape('audience'), '');
});
test("Model: has", 10, function() {
test("has", 10, function() {
var model = new Backbone.Model();
strictEqual(model.has('name'), false);
@@ -161,7 +161,7 @@ $(document).ready(function() {
strictEqual(model.has('undefined'), false);
});
test("Model: set and unset", 8, function() {
test("set and unset", 8, function() {
var a = new Backbone.Model({id: 'id', foo: 1, bar: 2, baz: 3});
var changeCount = 0;
a.on("change:foo", function() { changeCount += 1; });
@@ -184,7 +184,7 @@ $(document).ready(function() {
equal(a.id, undefined, "Unsetting the id should remove the id property.");
});
test("Model: multiple unsets", 1, function() {
test("multiple unsets", 1, function() {
var i = 0;
var counter = function(){ i++; };
var model = new Backbone.Model({a: 1});
@@ -195,7 +195,7 @@ $(document).ready(function() {
equal(i, 2, 'Unset does not fire an event for missing attributes.');
});
test("Model: unset and changedAttributes", 2, function() {
test("unset and changedAttributes", 2, function() {
var model = new Backbone.Model({a: 1});
model.unset('a', {silent: true});
var changedAttributes = model.changedAttributes();
@@ -205,7 +205,7 @@ $(document).ready(function() {
ok('a' in changedAttributes, 'changedAttributes should contain unset properties when running changedAttributes again after an unset.');
});
test("Model: using a non-default id attribute.", 5, function() {
test("using a non-default id attribute.", 5, function() {
var MongoModel = Backbone.Model.extend({idAttribute : '_id'});
var model = new MongoModel({id: 'eye-dee', _id: 25, title: 'Model'});
equal(model.get('id'), 'eye-dee');
@@ -216,13 +216,13 @@ $(document).ready(function() {
equal(model.isNew(), true);
});
test("Model: set an empty string", 1, function() {
test("set an empty string", 1, function() {
var model = new Backbone.Model({name : "Model"});
model.set({name : ''});
equal(model.get('name'), '');
});
test("Model: clear", 3, function() {
test("clear", 3, function() {
var changed;
var model = new Backbone.Model({id: 1, name : "Model"});
model.on("change:name", function(){ changed = true; });
@@ -235,7 +235,7 @@ $(document).ready(function() {
equal(model.get('name'), undefined);
});
test("Model: defaults", 4, function() {
test("defaults", 4, function() {
var Defaulted = Backbone.Model.extend({
defaults: {
"one": 1,
@@ -258,7 +258,7 @@ $(document).ready(function() {
equal(model.get('two'), null);
});
test("Model: change, hasChanged, changedAttributes, previous, previousAttributes", 12, function() {
test("change, hasChanged, changedAttributes, previous, previousAttributes", 12, function() {
var model = new Backbone.Model({name : "Tim", age : 10});
equal(model.changedAttributes(), false);
model.on('change', function() {
@@ -279,14 +279,14 @@ $(document).ready(function() {
});
test("Model: changedAttributes", 3, function() {
test("changedAttributes", 3, function() {
var model = new Backbone.Model({a: 'a', b: 'b'});
equal(model.changedAttributes(), false);
equal(model.changedAttributes({a: 'a'}), false);
equal(model.changedAttributes({a: 'b'}).a, 'b');
});
test("Model: change with options", 2, function() {
test("change with options", 2, function() {
var value;
var model = new Backbone.Model({name: 'Rob'});
model.on('change', function(model, options) {
@@ -299,7 +299,7 @@ $(document).ready(function() {
equal(value, 'Ms. Sue');
});
test("Model: change after initialize", 1, function () {
test("change after initialize", 1, function () {
var changed = 0;
var attrs = {id: 1, label: 'c'};
var obj = new Backbone.Model(attrs);
@@ -308,7 +308,7 @@ $(document).ready(function() {
equal(changed, 0);
});
test("Model: save within change event", 1, function () {
test("save within change event", 1, function () {
var env = this;
var model = new Backbone.Model({firstName : "Taylor", lastName: "Swift"});
model.url = '/test';
@@ -319,7 +319,7 @@ $(document).ready(function() {
model.set({lastName: 'Hicks'});
});
test("Model: validate after save", 1, function() {
test("validate after save", 1, function() {
var lastError, model = new Backbone.Model();
model.validate = function(attrs) {
if (attrs.admin) return "Can't change admin status.";
@@ -334,7 +334,7 @@ $(document).ready(function() {
equal(lastError, "Can't change admin status.");
});
test("Model: isValid", 5, function() {
test("isValid", 5, function() {
var model = new Backbone.Model({valid: true});
model.validate = function(attrs) {
if (!attrs.valid) return "invalid";
@@ -346,13 +346,13 @@ $(document).ready(function() {
equal(model.isValid(), false);
});
test("Model: save", 2, function() {
test("save", 2, function() {
doc.save({title : "Henry V"});
equal(this.syncArgs.method, 'update');
ok(_.isEqual(this.syncArgs.model, doc));
});
test("Model: save in positional style", 1, function() {
test("save in positional style", 1, function() {
var model = new Backbone.Model();
model.sync = function(method, model, options) {
options.success();
@@ -363,13 +363,13 @@ $(document).ready(function() {
test("Model: fetch", 2, function() {
test("fetch", 2, function() {
doc.fetch();
equal(this.syncArgs.method, 'read');
ok(_.isEqual(this.syncArgs.model, doc));
});
test("Model: destroy", 3, function() {
test("destroy", 3, function() {
doc.destroy();
equal(this.syncArgs.method, 'delete');
ok(_.isEqual(this.syncArgs.model, doc));
@@ -378,14 +378,14 @@ $(document).ready(function() {
equal(newModel.destroy(), false);
});
test("Model: non-persisted destroy", 1, function() {
test("non-persisted destroy", 1, function() {
var a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3});
a.sync = function() { throw "should not be called"; };
a.destroy();
ok(true, "non-persisted model should not call sync");
});
test("Model: validate", 7, function() {
test("validate", 7, function() {
var lastError;
var model = new Backbone.Model();
model.validate = function(attrs) {
@@ -406,7 +406,7 @@ $(document).ready(function() {
equal(model.get('a'), 100);
});
test("Model: validate on unset and clear", 6, function() {
test("validate on unset and clear", 6, function() {
var error;
var model = new Backbone.Model({name: "One"});
model.validate = function(attrs) {
@@ -428,7 +428,7 @@ $(document).ready(function() {
equal(model.get('name'), undefined);
});
test("Model: validate with error callback", 8, function() {
test("validate with error callback", 8, function() {
var lastError, boundError;
var model = new Backbone.Model();
model.validate = function(attrs) {
@@ -452,7 +452,7 @@ $(document).ready(function() {
equal(boundError, true);
});
test("Model: defaults always extend attrs (#459)", 2, function() {
test("defaults always extend attrs (#459)", 2, function() {
var Defaulted = Backbone.Model.extend({
defaults: {one: 1},
initialize : function(attrs, opts) {
@@ -463,7 +463,7 @@ $(document).ready(function() {
var emptyattrs = new Defaulted();
});
test("Model: Inherit class properties", 6, function() {
test("Inherit class properties", 6, function() {
var Parent = Backbone.Model.extend({
instancePropSame: function() {},
instancePropDiff: function() {}
@@ -487,7 +487,7 @@ $(document).ready(function() {
notEqual(Child.prototype.instancePropDiff, undefined);
});
test("Model: Nested change events don't clobber previous attributes", 4, function() {
test("Nested change events don't clobber previous attributes", 4, function() {
new Backbone.Model()
.on('change:state', function(model, newState) {
equal(model.previous('state'), undefined);

View File

@@ -2,7 +2,7 @@ $(document).ready(function() {
module("Backbone.noConflict");
test('Backbone.noConflict', 2, function() {
test('noConflict', 2, function() {
var noconflictBackbone = Backbone.noConflict();
equal(window.Backbone, undefined, 'Returned window.Backbone');
window.Backbone = noconflictBackbone;

View File

@@ -126,11 +126,11 @@ $(document).ready(function() {
});
test("Router: initialize", 1, function() {
test("initialize", 1, function() {
equal(router.testing, 101);
});
test("Router: routes (simple)", 4, function() {
test("routes (simple)", 4, function() {
location.replace('http://example.com#search/news');
Backbone.history.checkUrl();
equal(router.query, 'news');
@@ -139,26 +139,26 @@ $(document).ready(function() {
equal(lastArgs[0], 'news');
});
test("Router: routes (two part)", 2, function() {
test("routes (two part)", 2, function() {
location.replace('http://example.com#search/nyc/p10');
Backbone.history.checkUrl();
equal(router.query, 'nyc');
equal(router.page, '10');
});
test("Router: routes via navigate", 2, function() {
test("routes via navigate", 2, function() {
Backbone.history.navigate('search/manhattan/p20', {trigger: true});
equal(router.query, 'manhattan');
equal(router.page, '20');
});
test("Router: routes via navigate for backwards-compatibility", 2, function() {
test("routes via navigate for backwards-compatibility", 2, function() {
Backbone.history.navigate('search/manhattan/p20', true);
equal(router.query, 'manhattan');
equal(router.page, '20');
});
test("Router: route precedence via navigate", 6, function(){
test("route precedence via navigate", 6, function(){
// check both 0.9.x and backwards-compatibility options
_.each([ { trigger: true }, true ], function( options ){
Backbone.history.navigate('contacts', options);
@@ -178,13 +178,13 @@ $(document).ready(function() {
Backbone.history.navigate('/route');
});
test("Router: use implicit callback if none provided", 1, function() {
test("use implicit callback if none provided", 1, function() {
router.count = 0;
router.navigate('implicit', {trigger: true});
equal(router.count, 1);
});
test("Router: routes via navigate with {replace: true}", 1, function() {
test("routes via navigate with {replace: true}", 1, function() {
location.replace('http://example.com#start_here');
Backbone.history.checkUrl();
location.replace = function(href) {
@@ -193,13 +193,13 @@ $(document).ready(function() {
Backbone.history.navigate('end_here', {replace: true});
});
test("Router: routes (splats)", 1, function() {
test("routes (splats)", 1, function() {
location.replace('http://example.com#splat/long-list/of/splatted_99args/end');
Backbone.history.checkUrl();
equal(router.args, 'long-list/of/splatted_99args');
});
test("Router: routes (complex)", 3, function() {
test("routes (complex)", 3, function() {
location.replace('http://example.com#one/two/three/complex-part/four/five/six/seven');
Backbone.history.checkUrl();
equal(router.first, 'one/two/three');
@@ -207,7 +207,7 @@ $(document).ready(function() {
equal(router.rest, 'four/five/six/seven');
});
test("Router: routes (query)", 5, function() {
test("routes (query)", 5, function() {
location.replace('http://example.com#mandel?a=b&c=d');
Backbone.history.checkUrl();
equal(router.entity, 'mandel');
@@ -217,13 +217,13 @@ $(document).ready(function() {
equal(lastArgs[1], 'a=b&c=d');
});
test("Router: routes (anything)", 1, function() {
test("routes (anything)", 1, function() {
location.replace('http://example.com#doesnt-match-a-route');
Backbone.history.checkUrl();
equal(router.anything, 'doesnt-match-a-route');
});
test("Router: 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); });
location.replace('http://example.com#noCallback');
Backbone.history.checkUrl();
@@ -251,7 +251,7 @@ $(document).ready(function() {
if (!Backbone.history.iframe) ok(true);
});
test("Router: route callback gets passed decoded values", 3, function() {
test("route callback gets passed decoded values", 3, function() {
var route = 'has%2Fslash/complex-has%23hash/has%20space';
Backbone.history.navigate(route, {trigger: true});
equal(router.first, 'has/slash');
@@ -259,7 +259,7 @@ $(document).ready(function() {
equal(router.rest, 'has space');
});
test("Router: correctly handles URLs with % (#868)", 3, function() {
test("correctly handles URLs with % (#868)", 3, function() {
location.replace('http://example.com#search/fat%3A1.5%25');
Backbone.history.checkUrl();
location.replace('http://example.com#search/fat');
@@ -317,7 +317,7 @@ $(document).ready(function() {
strictEqual(Backbone.history.fragment, 'x');
});
test("Router: Normalize root.", 1, function() {
test("Normalize root.", 1, function() {
Backbone.history.stop();
location.replace('http://example.com/root');
Backbone.history = new Backbone.History({
@@ -336,7 +336,7 @@ $(document).ready(function() {
Backbone.history.navigate('fragment');
});
test("Router: Normalize root.", 1, function() {
test("Normalize root.", 1, function() {
Backbone.history.stop();
location.replace('http://example.com/root#fragment');
Backbone.history = new Backbone.History({
@@ -354,7 +354,7 @@ $(document).ready(function() {
});
});
test("Router: Normalize root.", 1, function() {
test("Normalize root.", 1, function() {
Backbone.history.stop();
location.replace('http://example.com/root');
Backbone.history = new Backbone.History({location: location});

View File

@@ -21,7 +21,7 @@ $(document).ready(function() {
}));
test("sync: read", 4, function() {
test("read", 4, function() {
library.fetch();
equal(this.ajaxSettings.url, '/library');
equal(this.ajaxSettings.type, 'GET');
@@ -29,14 +29,14 @@ $(document).ready(function() {
ok(_.isEmpty(this.ajaxSettings.data));
});
test("sync: passing data", 3, function() {
test("passing data", 3, function() {
library.fetch({data: {a: 'a', one: 1}});
equal(this.ajaxSettings.url, '/library');
equal(this.ajaxSettings.data.a, 'a');
equal(this.ajaxSettings.data.one, 1);
});
test("sync: create", 6, function() {
test("create", 6, function() {
equal(this.ajaxSettings.url, '/library');
equal(this.ajaxSettings.type, 'POST');
equal(this.ajaxSettings.dataType, 'json');
@@ -46,7 +46,7 @@ $(document).ready(function() {
equal(data.length, 123);
});
test("sync: update", 7, function() {
test("update", 7, function() {
library.first().save({id: '1-the-tempest', author: 'William Shakespeare'});
equal(this.ajaxSettings.url, '/library/1-the-tempest');
equal(this.ajaxSettings.type, 'PUT');
@@ -58,7 +58,7 @@ $(document).ready(function() {
equal(data.length, 123);
});
test("sync: update with emulateHTTP and emulateJSON", 7, function() {
test("update with emulateHTTP and emulateJSON", 7, function() {
Backbone.emulateHTTP = Backbone.emulateJSON = true;
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
equal(this.ajaxSettings.url, '/library/2-the-tempest');
@@ -72,7 +72,7 @@ $(document).ready(function() {
Backbone.emulateHTTP = Backbone.emulateJSON = false;
});
test("sync: update with just emulateHTTP", 6, function() {
test("update with just emulateHTTP", 6, function() {
Backbone.emulateHTTP = true;
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
equal(this.ajaxSettings.url, '/library/2-the-tempest');
@@ -85,7 +85,7 @@ $(document).ready(function() {
Backbone.emulateHTTP = false;
});
test("sync: update with just emulateJSON", 6, function() {
test("update with just emulateJSON", 6, function() {
Backbone.emulateJSON = true;
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
equal(this.ajaxSettings.url, '/library/2-the-tempest');
@@ -98,7 +98,7 @@ $(document).ready(function() {
Backbone.emulateJSON = false;
});
test("sync: read model", 3, function() {
test("read model", 3, function() {
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
library.first().fetch();
equal(this.ajaxSettings.url, '/library/2-the-tempest');
@@ -106,7 +106,7 @@ $(document).ready(function() {
ok(_.isEmpty(this.ajaxSettings.data));
});
test("sync: destroy", 3, function() {
test("destroy", 3, function() {
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
library.first().destroy({wait: true});
equal(this.ajaxSettings.url, '/library/2-the-tempest');
@@ -114,7 +114,7 @@ $(document).ready(function() {
equal(this.ajaxSettings.data, null);
});
test("sync: destroy with emulateHTTP", 3, function() {
test("destroy with emulateHTTP", 3, function() {
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
Backbone.emulateHTTP = Backbone.emulateJSON = true;
library.first().destroy();
@@ -124,7 +124,7 @@ $(document).ready(function() {
Backbone.emulateHTTP = Backbone.emulateJSON = false;
});
test("sync: urlError", 2, function() {
test("urlError", 2, function() {
var model = new Backbone.Model();
raises(function() {
model.fetch();

View File

@@ -13,27 +13,27 @@ $(document).ready(function() {
});
test("View: constructor", 4, function() {
test("constructor", 4, function() {
equal(view.el.id, 'test-view');
equal(view.el.className, 'test-view');
equal(view.options.id, 'test-view');
equal(view.options.className, 'test-view');
});
test("View: jQuery", 2, function() {
test("jQuery", 2, function() {
view.setElement(document.body);
ok(view.$('#qunit-header a').get(0).innerHTML.match(/Backbone Test Suite/));
ok(view.$('#qunit-header a').get(1).innerHTML.match(/Backbone Speed Suite/));
});
test("View: make", 3, function() {
test("make", 3, function() {
var div = view.make('div', {id: 'test-div'}, "one two three");
equal(div.tagName.toLowerCase(), 'div');
equal(div.id, 'test-div');
equal($(div).text(), 'one two three');
});
test("View: make can take falsy values for content", 2, function() {
test("make can take falsy values for content", 2, function() {
var div = view.make('div', {id: 'test-div'}, 0);
equal($(div).text(), '0');
@@ -41,7 +41,7 @@ $(document).ready(function() {
equal($(div).text(), '');
});
test("View: initialize", 1, function() {
test("initialize", 1, function() {
var View = Backbone.View.extend({
initialize: function() {
this.one = 1;
@@ -51,7 +51,7 @@ $(document).ready(function() {
equal(view.one, 1);
});
test("View: delegateEvents", 6, function() {
test("delegateEvents", 6, function() {
var counter = 0;
var counter2 = 0;
view.setElement(document.body);
@@ -71,7 +71,7 @@ $(document).ready(function() {
equal(counter2, 3);
});
test("View: delegateEvents allows functions for callbacks", 3, function() {
test("delegateEvents allows functions for callbacks", 3, function() {
view.counter = 0;
view.setElement("#qunit-banner");
var events = {"click": function() { this.counter++; }};
@@ -85,7 +85,7 @@ $(document).ready(function() {
equal(view.counter, 3);
});
test("View: undelegateEvents", 6, function() {
test("undelegateEvents", 6, function() {
var counter = 0;
var counter2 = 0;
view.setElement(document.body);
@@ -107,7 +107,7 @@ $(document).ready(function() {
equal(counter2, 3);
});
test("View: _ensureElement with DOM node el", 1, function() {
test("_ensureElement with DOM node el", 1, function() {
var ViewClass = Backbone.View.extend({
el: document.body
});
@@ -115,7 +115,7 @@ $(document).ready(function() {
equal(view.el, document.body);
});
test("View: _ensureElement with string el", 3, function() {
test("_ensureElement with string el", 3, function() {
var ViewClass = Backbone.View.extend({
el: "body"
});
@@ -135,7 +135,7 @@ $(document).ready(function() {
ok(!view.el);
});
test("View: with className and id functions", 2, function() {
test("with className and id functions", 2, function() {
var View = Backbone.View.extend({
className: function() {
return 'className';
@@ -149,13 +149,13 @@ $(document).ready(function() {
strictEqual(view.el.id, 'id');
});
test("View: with attributes", 2, function() {
test("with attributes", 2, function() {
var view = new Backbone.View({attributes : {'class': 'one', id: 'two'}});
equal(view.el.className, 'one');
equal(view.el.id, 'two');
});
test("View: with attributes as a function", 1, function() {
test("with attributes as a function", 1, function() {
var viewClass = Backbone.View.extend({
attributes: function() {
return {'class': 'dynamic'};
@@ -164,7 +164,7 @@ $(document).ready(function() {
equal((new viewClass).el.className, 'dynamic');
});
test("View: multiple views per element", 3, function() {
test("multiple views per element", 3, function() {
var count = 0, ViewClass = Backbone.View.extend({
el: $("body"),
events: {
@@ -188,7 +188,7 @@ $(document).ready(function() {
equal(5, count);
});
test("View: custom events, with namespaces", 2, function() {
test("custom events, with namespaces", 2, function() {
var count = 0;
var ViewClass = Backbone.View.extend({
el: $('body'),