Browse files

Merge branch 'ie10'

  • Loading branch information...
2 parents 3a6ed3a + 3fff5af commit f57e5e4498f6806d846404d36825340c93d588bf @lcalvy committed Jan 28, 2012
Showing with 139 additions and 14 deletions.
  1. +6 −5 backbone-indexeddb.js
  2. +133 −9 tests/backbone-indexeddbTests.js
View
11 backbone-indexeddb.js
@@ -12,7 +12,7 @@
// Naming is a mess!
var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB ;
var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction; // No prefix in moz
- var IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange; // No prefix in moz
+ var IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange ; // No prefix in moz
/* Horrible Hack to prevent ' Expected an identifier and instead saw 'continue' (a reserved word).'*/
if (window.indexedDB) {
@@ -22,6 +22,7 @@
}
window.indexedDB = indexedDB;
+ window.IDBCursor = window.IDBCursor || window.webkitIDBCursor || window.mozIDBCursor || window.msIDBCursor ;
// Driver object
// That's the interesting part.
// There is a driver for each schema provided. The schema is a te combination of name (for the database), a version as well as migrations to reach that
@@ -329,10 +330,10 @@
if (options.conditions[index.keyPath][0] > options.conditions[index.keyPath][1]) {
// Looks like we want the DESC order
- readCursor = index.openCursor(bounds, 2);
+ readCursor = index.openCursor(bounds, window.IDBCursor.PREV);
} else {
// We want ASC order
- readCursor = index.openCursor(bounds, 0);
+ readCursor = index.openCursor(bounds, window.IDBCursor.NEXT);
}
} else if (options.conditions[index.keyPath]) {
bounds = IDBKeyRange.only(options.conditions[index.keyPath]);
@@ -347,9 +348,9 @@
upper = options.range[0] > options.range[1] ? options.range[0] : options.range[1];
bounds = IDBKeyRange.bound(lower, upper);
if (options.range[0] > options.range[1]) {
- readCursor = store.openCursor(bounds, 2);
+ readCursor = store.openCursor(bounds, window.IDBCursor.PREV);
} else {
- readCursor = store.openCursor(bounds, 0);
+ readCursor = store.openCursor(bounds, window.IDBCursor.NEXT);
}
} else {
readCursor = store.openCursor();
View
142 tests/backbone-indexeddbTests.js
@@ -179,7 +179,7 @@ backboneIndexedDBTest.prototype.testCreateModelBeforeAndNext = function (queue)
},
{
version:2,
- before : callbacks.add(function (next) {
+ before:callbacks.add(function (next) {
jstestdriver.console.log("before");
jstestdriver.console.log("migration path step before #1");
assertEquals("migration path step before", 1, stepOnUpgrade);
@@ -203,14 +203,14 @@ backboneIndexedDBTest.prototype.testCreateModelBeforeAndNext = function (queue)
stepOnUpgrade++;
next();
}),
- after : callbacks.add(function (next) {
+ after:callbacks.add(function (next) {
jstestdriver.console.log("after");
var m = new MovieV3();
m.save({
title:"The Matrix 3",
format:"dvd"
}, {
- success: callbacks.add(function(){
+ success:callbacks.add(function () {
jstestdriver.console.log("migration path step save #4");
assertEquals("migration path step save", 4, stepOnUpgrade);
stepOnUpgrade++;
@@ -233,7 +233,6 @@ backboneIndexedDBTest.prototype.testCreateModelBeforeAndNext = function (queue)
});
-
var onSuccess = callbacks.add(function () {
jstestdriver.console.log("get model v3 Success");
jstestdriver.console.log("migration path step is 5 #5");
@@ -499,7 +498,7 @@ backboneIndexedDBTest.prototype.testReadCollection = function (queue) {
});
var onError = callbacks.addErrback(function () {
- jstestdriver.console.log("fetc collection Error");
+ jstestdriver.console.log("clean collection Error");
});
theater = new Theater();
@@ -521,7 +520,7 @@ backboneIndexedDBTest.prototype.testReadCollection = function (queue) {
});
var onError = callbacks.addErrback(function () {
- jstestdriver.console.log("create model v2 Error");
+ jstestdriver.console.log("read collection with no options Error");
});
theater.fetch({
@@ -538,7 +537,7 @@ backboneIndexedDBTest.prototype.testReadCollection = function (queue) {
});
var onError = callbacks.addErrback(function () {
- jstestdriver.console.log("create model v2 Error");
+ jstestdriver.console.log("ead collection with limit Error");
});
theater.fetch({
@@ -556,7 +555,7 @@ backboneIndexedDBTest.prototype.testReadCollection = function (queue) {
});
var onError = callbacks.addErrback(function () {
- jstestdriver.console.log("create model v2 Error");
+ jstestdriver.console.log("read collection with offset Error");
});
theater.fetch({
@@ -574,7 +573,7 @@ backboneIndexedDBTest.prototype.testReadCollection = function (queue) {
});
var onError = callbacks.addErrback(function () {
- jstestdriver.console.log("create model v2 Error");
+ jstestdriver.console.log("read collection with offset and limit Error");
});
theater.fetch({
@@ -584,4 +583,129 @@ backboneIndexedDBTest.prototype.testReadCollection = function (queue) {
}
);
+ queue.call("Try read collection with range", function (callbacks) {
+
+ var onSuccess = callbacks.add(function () {
+ assertEquals("Should have 3 elements", 3, theater.models.length);
+ assertEquals("Should have [\"Bonjour\", \"Halo\", \"Nihao\"]", ["Bonjour", "Halo", "Nihao"], theater.pluck("title"));
+ });
+
+ var onError = callbacks.addErrback(function () {
+ jstestdriver.console.log("ead collection with range Error");
+ });
+
+ theater.fetch({
+ range:["1.5", "4.5"],
+ success:onSuccess,
+ error:onError});
+ }
+ );
+
+ queue.call("Try read collection via condition on index with a single value", function (callbacks) {
+
+ var onSuccess = callbacks.add(function () {
+ assertEquals("Should have 2 elements", 2, theater.models.length);
+ assertEquals("Should have [\"Bonjour\", \"Ciao\"]", ["Bonjour", "Ciao"], theater.pluck("title"));
+ });
+
+ var onError = callbacks.addErrback(function () {
+ jstestdriver.console.log("read collection via condition on index with a single value Error");
+ });
+
+ theater.fetch({
+ conditions:{
+ format:"dvd"
+ },
+ success:onSuccess,
+ error:onError});
+ }
+ );
+
+ queue.call("Try read collection via condition on index with a range and a limit", function (callbacks) {
+
+ var onSuccess = callbacks.add(function () {
+ assertEquals("Should have 2 elements", 2, theater.models.length);
+ assertEquals("Should have [\"Hello\", \"Halo\"]", ["Hello", "Halo"], theater.pluck("title"));
+ });
+
+ var onError = callbacks.addErrback(function () {
+ jstestdriver.console.log("read collection via condition on index with a range and a limit Error");
+ });
+
+ theater.fetch({
+ limit:2,
+ conditions:{
+ format:["a", "f"]
+ },
+ success:onSuccess,
+ error:onError});
+ }
+ );
+
+ queue.call("Try read collection via condition on index with a range, an offset and a limit", function (callbacks) {
+
+ var onSuccess = callbacks.add(function () {
+ assertEquals("Should have 2 elements", 2, theater.models.length);
+ assertEquals("Should have [\"Bonjour\", \"Ciao\"]", ["Bonjour", "Ciao"], theater.pluck("title"));
+ });
+
+ var onError = callbacks.addErrback(function () {
+ jstestdriver.console.log("read collection via condition on index with a range, an offset and a limit Error");
+ });
+
+ theater.fetch({
+ offset:2,
+ limit:2,
+ conditions:{
+ format:["a", "f"]
+ },
+ success:onSuccess,
+ error:onError});
+ }
+ );
+
+ queue.call("Try read collection via condition on index with a range reversed", function (callbacks) {
+
+ var onSuccess = callbacks.add(function () {
+ assertEquals("Should have 4 elements", 4, theater.models.length);
+ assertEquals("Should have [\"Ciao\", \"Bonjour\", \"Halo\", \"Hello\"]", ["Ciao", "Bonjour", "Halo", "Hello"], theater.pluck("title"));
+ });
+
+ var onError = callbacks.addErrback(function () {
+ jstestdriver.console.log("read collection via condition on index with a range reversed");
+ });
+
+ theater.fetch({
+ conditions:{
+ format:["f", "a"]
+ },
+ success:onSuccess,
+ error:onError});
+ }
+ );
+
+
+ queue.call("Try support for the 'addIndividually' property", function (callbacks) {
+
+
+ var onSuccess = callbacks.add(function (model, collection) {
+
+ if(collection.length == 5){
+ assertEquals("Should have 5 elements", 5, collection.length);
+ }
+ });
+
+ var onError = callbacks.addErrback(function () {
+ jstestdriver.console.log("support for the 'addIndividually' property error");
+ });
+
+ theater.bind("add", onSuccess);
+
+ theater.fetch({
+ addIndividually:true,
+ success:onSuccess,
+ error:onError});
+ }
+ );
+
};

0 comments on commit f57e5e4

Please sign in to comment.