Commit 40764fad authored by Yaxel Perez's avatar Yaxel Perez

making the stuff use promises like it's supposed to

parent d21cdad4
...@@ -15,16 +15,19 @@ ...@@ -15,16 +15,19 @@
"type": "indexeddb", "type": "indexeddb",
"database": randomId() "database": randomId()
}); });
this._signature_storage.post("_", { this._signature_storage.put("_", {
list: [] list: []
}); });
} }
ListStorage.prototype.post = function () { ListStorage.prototype.post = function () {
console.log('alright alright alright alright alright ok now ladies'); var id = this._sub_storage.post.apply(this._sub_storage, arguments);
var id = this._sub_storage.post.apply(this._sub_storage, arguments), this._signature_storage.get('_').then(function (storage) {
updated_list = this._signature_storage.get("_").list.concat(id); this._signature_storage.put('_', { list: storage.list.concat(id) });
this._signature_storage.put("_", {list: updated_list}); }).fail(function (err) {
throw err;
});
return id;
}; };
ListStorage.prototype.get = function () { ListStorage.prototype.get = function () {
...@@ -42,7 +45,9 @@ ...@@ -42,7 +45,9 @@
}; };
ListStorage.prototype.list = function () { ListStorage.prototype.list = function () {
return this._sub_storage.get("_").list; return this._sub_storage.get("_").then(function (storage) {
return storage.list;
});
}; };
jIO.addStorage("list", ListStorage); jIO.addStorage("list", ListStorage);
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
console.log("Nocapacity"); console.log("Nocapacity");
function NoCapacityStorage(spec) { function NoCapacityStorage(spec) {
this.sub_storage = jIO.createJIO(spec.sub_storage); this._sub_storage = jIO.createJIO(spec.sub_storage);
} }
NoCapacityStorage.prototype.hasCapacity = function () { NoCapacityStorage.prototype.hasCapacity = function () {
......
...@@ -14,25 +14,34 @@ ...@@ -14,25 +14,34 @@
QUnit.expect(0); QUnit.expect(0);
}); });
// line is too long (>80) if I don't do this weird indenting QUnit.test('list method returns ordered list of ids', function (assert) {
QUnit.test( QUnit.stop();
"Storage list method returns ordered list of ids", QUnit.expect(1);
function (assert) {
var storage = jIO.createJIO({ var jio = jIO.createJIO({
type: "list", type: 'list',
sub_storage: {
type: 'uuid',
sub_storage: { sub_storage: {
type: "uuid", type: 'memory'
sub_storage: {
type: "memory",
}
} }
}), }
ids = RSVP.all([storage.post(), storage.post(), storage.post()]); }),
ids = [jio.post({}), jio.post({}), jio.post({})];
ids.then(function (values) { RSVP.all(ids).then(
}); function (values) {
} jio.list().then(function (list) {
); QUnit.start();
assert.equal(values, jio.list());
}).fail(function (err) {
assert.ok(false, err);
});
}
).fail(function (err) {
QUnit.start();
assert.ok(false, err);
});
});
}(jIO, RSVP, QUnit)); }(jIO, RSVP, QUnit));
...@@ -2,17 +2,6 @@ ...@@ -2,17 +2,6 @@
(function (jIO, QUnit) { (function (jIO, QUnit) {
"use strict"; "use strict";
function TestStorage() {
return this;
}
TestStorage.prototype.get = function () { return true; };
TestStorage.prototype.post = function () { return true; };
TestStorage.prototype.put = function () { return true; };
TestStorage.prototype.remove = function () { return true; };
jIO.addStorage('teststorage', TestStorage);
module("NoCapacityStorage"); module("NoCapacityStorage");
QUnit.test('Constructor does not crash', function () { QUnit.test('Constructor does not crash', function () {
...@@ -20,7 +9,7 @@ ...@@ -20,7 +9,7 @@
type: "nocapacity", type: "nocapacity",
schema: {'date': {'type': 'string', format: 'date-time'}}, schema: {'date': {'type': 'string', format: 'date-time'}},
sub_storage: { sub_storage: {
type: 'teststorage' type: 'memory'
} }
}); });
QUnit.expect(0); QUnit.expect(0);
...@@ -31,7 +20,7 @@ ...@@ -31,7 +20,7 @@
type: "nocapacity", type: "nocapacity",
schema: {'date': {'type': 'string', format: 'date-time'}}, schema: {'date': {'type': 'string', format: 'date-time'}},
sub_storage: { sub_storage: {
type: 'teststorage' type: 'memory'
} }
}); });
assert.throws( assert.throws(
...@@ -40,17 +29,24 @@ ...@@ -40,17 +29,24 @@
}); });
QUnit.test('Storage calls sub-storage methods', function (assert) { QUnit.test('Storage calls sub-storage methods', function (assert) {
QUnit.stop();
QUnit.expect(1);
var jio = jIO.createJIO({ var jio = jIO.createJIO({
type: "nocapacity", type: "nocapacity",
schema: {'date': {'type': 'string', format: 'date-time'}},
sub_storage: { sub_storage: {
type: 'teststorage' type: 'memory'
} }
}); });
assert.ok(jio.get("fake id"));
assert.ok(jio.post()); jio.put("test_id", {foo: "bar"});
assert.ok(jio.put("fake id")); jio.get("test_id").then(function (val) {
assert.ok(jio.remove("fake id")); QUnit.start();
assert.deepEqual(val, {foo: "bar"});
}).fail(function (err) {
QUnit.start();
assert.ok(false, err);
});
}); });
}(jIO, QUnit)); }(jIO, QUnit));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment