Permalink
Browse files

Merge pull request #62 from niallsmart/master

Fixes issue #57 & #59. THANK YOU!!!
  • Loading branch information...
2 parents 4ef3b28 + 62cb126 commit 04514fd65ef1dfd5241e02f5d2ab9bbdb9dc5062 @brianleroux brianleroux committed Sep 23, 2011
Showing with 24 additions and 8 deletions.
  1. +3 −3 src/adapters/dom.js
  2. +2 −3 src/adapters/ie-userdata.js
  3. +19 −2 test/lawnchair-spec.js
View
@@ -68,8 +68,8 @@ Lawnchair.adapter('dom', (function() {
// now we kil the key and use it in the store colleciton
delete obj.key;
storage.setItem(key, JSON.stringify(obj))
+ obj.key = key.slice(this.name.length + 1)
if (callback) {
- obj.key = key.replace(this.name + '.', '')
this.lambda(callback).call(this, obj)
}
return this
@@ -104,15 +104,15 @@ Lawnchair.adapter('dom', (function() {
var k = this.name + '.' + key[i]
, obj = JSON.parse(storage.getItem(k))
if (obj) {
- obj.key = k
+ obj.key = key[i]
r.push(obj)
}
}
if (callback) this.lambda(callback).call(this, r)
} else {
var k = this.name + '.' + key
, obj = JSON.parse(storage.getItem(k))
- if (obj) obj.key = k
+ if (obj) obj.key = key
if (callback) this.lambda(callback).call(this, obj)
}
return this
@@ -39,7 +39,6 @@ Lawnchair.adapter('ie-userdata', {
},
all:function(callback){
- var cb = this.terseToVerboseCallback(callback);
var ca = this.storage.XMLDocument.firstChild.attributes;
var yar = [];
var v,o;
@@ -52,8 +51,8 @@ Lawnchair.adapter('ie-userdata', {
yar.push(o);
}
}
- if (cb)
- cb(yar);
+ if (callback)
+ callback(yar);
},
remove:function(keyOrObj,callback) {
var key = (typeof keyOrObj == 'string') ? keyOrObj : keyOrObj.key;
View
@@ -203,6 +203,20 @@ test( 'saving objects', function() {
})
})
+test( 'save without callback', function() {
+
+ QUnit.stop();
+ QUnit.expect(1);
+
+ store.save(me, function(obj) {
+ var key = obj.key;
+ store.save(obj);
+ equals(obj.key, key, "save without callback retains key");
+ QUnit.start();
+ })
+
+});
+
module('batch()', {
setup:function() {
QUnit.stop();
@@ -270,11 +284,12 @@ test( 'should it be chainable?', function() {
});
test('get functionality', function() {
- QUnit.expect(3);
+ QUnit.expect(4);
QUnit.stop();
store.save({key:'xyz', name:'tim'}, function() {
store.get('xyz', function(r) {
+ equals(r.key, 'xyz', 'should return key in loaded object');
equals(r.name, 'tim', 'should return proper object when calling get with a key');
store.get('doesntexist', function(s) {
ok(true, 'should call callback even for non-existent key');
@@ -286,12 +301,14 @@ test('get functionality', function() {
});
test('get batch functionality', function() {
- QUnit.expect(1);
+ QUnit.expect(3);
QUnit.stop(500);
var t = [{key:'test-get'},{key:'test-get-1'}]
store.batch(t, function() {
this.get(['test-get','test-get-1'], function(r) {
+ equals(r[0].key, 'test-get', "get first object");
+ equals(r[1].key, 'test-get-1', "get second object");
equals(r.length, t.length, "should batch get")
QUnit.start()
})

0 comments on commit 04514fd

Please sign in to comment.