Skip to content

Commit

Permalink
Added support for `dustbin.store('bin', obj)
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgul committed Apr 17, 2013
1 parent 4595551 commit 07b886a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
26 changes: 18 additions & 8 deletions dustbin.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,28 @@ function buildDustbin()
if(!value)
{
value = key;
var unique = false;
key = undefined;

while(!unique)
if(value.$metadata)
{
// Generate a new key that is highly likely to be unique.
key = this._generate_key();
key = value.$metadata.key;
} // end if

if(!key)
{
var unique = false;

if(!binObj[key])
while(!unique)
{
unique = true;
} // end if
} // end while
// Generate a new key that is highly likely to be unique.
key = this._generate_key();

if(!binObj[key])
{
unique = true;
} // end if
} // end while
} // else
} // end if

// Store the value, setting metadata, etc.
Expand Down
19 changes: 19 additions & 0 deletions tests/dustbin.session.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ describe("DustBin Session Store", function()
expect(newObj).toBeDefined();
});

it("allows storage of objects with metadata, when specifying bucket..", function()
{
var testObj = {foo:"bar"};
var key = dustbin.store("test_bin", "test_key", testObj) ;
var obj = dustbin.get("test_bin", key);

var newObj;
var testObjStore = function()
{
dustbin.store("test_bin", obj);
newObj = dustbin.get("test_bin", key);
}; // end testObjStore

expect(testObjStore).not.toThrow();
expect(newObj).toBeDefined();
expect(newObj).toEqual(obj);

});

it("allows retrieval of the bin directly.", function()
{
var testObj = {foo:"bar"};
Expand Down
19 changes: 19 additions & 0 deletions tests/dustbin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,25 @@ describe("DustBin", function()
});
});

it("allows storage of objects with metadata, when specifying bucket..", function()
{
var testObj = {foo:"bar"};
var key = dustbin.store("test_bin", "test_key", testObj) ;
var obj = dustbin.get("test_bin", key);

var newObj;
var testObjStore = function()
{
dustbin.store("test_bin", obj);
newObj = dustbin.get("test_bin", key);
}; // end testObjStore

expect(testObjStore).not.toThrow();
expect(newObj).toBeDefined();
expect(newObj).toEqual(obj);

});

it("allows direct storage of objects with metadata.", function()
{
var testObj = {foo:"bar"};
Expand Down

0 comments on commit 07b886a

Please sign in to comment.