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 @@
"type": "indexeddb",
"database": randomId()
});
this._signature_storage.post("_", {
this._signature_storage.put("_", {
list: []
});
}
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),
updated_list = this._signature_storage.get("_").list.concat(id);
this._signature_storage.put("_", {list: updated_list});
var id = this._sub_storage.post.apply(this._sub_storage, arguments);
this._signature_storage.get('_').then(function (storage) {
this._signature_storage.put('_', { list: storage.list.concat(id) });
}).fail(function (err) {
throw err;
});
return id;
};
ListStorage.prototype.get = function () {
......@@ -42,7 +45,9 @@
};
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);
......
......@@ -27,7 +27,7 @@
console.log("Nocapacity");
function NoCapacityStorage(spec) {
this.sub_storage = jIO.createJIO(spec.sub_storage);
this._sub_storage = jIO.createJIO(spec.sub_storage);
}
NoCapacityStorage.prototype.hasCapacity = function () {
......
......@@ -14,25 +14,34 @@
QUnit.expect(0);
});
// line is too long (>80) if I don't do this weird indenting
QUnit.test(
"Storage list method returns ordered list of ids",
function (assert) {
var storage = jIO.createJIO({
type: "list",
QUnit.test('list method returns ordered list of ids', function (assert) {
QUnit.stop();
QUnit.expect(1);
var jio = jIO.createJIO({
type: 'list',
sub_storage: {
type: 'uuid',
sub_storage: {
type: "uuid",
sub_storage: {
type: "memory",
}
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));
......@@ -2,17 +2,6 @@
(function (jIO, QUnit) {
"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");
QUnit.test('Constructor does not crash', function () {
......@@ -20,7 +9,7 @@
type: "nocapacity",
schema: {'date': {'type': 'string', format: 'date-time'}},
sub_storage: {
type: 'teststorage'
type: 'memory'
}
});
QUnit.expect(0);
......@@ -31,7 +20,7 @@
type: "nocapacity",
schema: {'date': {'type': 'string', format: 'date-time'}},
sub_storage: {
type: 'teststorage'
type: 'memory'
}
});
assert.throws(
......@@ -40,17 +29,24 @@
});
QUnit.test('Storage calls sub-storage methods', function (assert) {
QUnit.stop();
QUnit.expect(1);
var jio = jIO.createJIO({
type: "nocapacity",
schema: {'date': {'type': 'string', format: 'date-time'}},
sub_storage: {
type: 'teststorage'
type: 'memory'
}
});
assert.ok(jio.get("fake id"));
assert.ok(jio.post());
assert.ok(jio.put("fake id"));
assert.ok(jio.remove("fake id"));
jio.put("test_id", {foo: "bar"});
jio.get("test_id").then(function (val) {
QUnit.start();
assert.deepEqual(val, {foo: "bar"});
}).fail(function (err) {
QUnit.start();
assert.ok(false, err);
});
});
}(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