Skip to content

Commit

Permalink
Merge pull request #9 from Swaagie/clone
Browse files Browse the repository at this point in the history
[fix] Clone by default.
  • Loading branch information
Martijn Swaagman committed Aug 18, 2015
2 parents 0fc2131 + db8a7d9 commit e04391f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/memory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var fuse = require('fusing')
, clone = require('clone')
, has = Object.prototype.hasOwnProperty;

/**
Expand Down Expand Up @@ -45,7 +46,7 @@ Memory.readable('api', function api(dynamis) {
* @api private
*/
function get(key, fn) {
fn(undefined, memory.database[key]);
fn(undefined, clone(memory.database[key]));
}

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"homepage": "https://github.com/swaagie/dynamis",
"dependencies": {
"async": "~1.4.0",
"clone": "~1.0.2",
"debug": "~2.2.0",
"eventemitter3": "~1.1.1",
"fusing": "~1.0.0"
Expand Down
16 changes: 16 additions & 0 deletions test/lib/memory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ describe('Memory persistence layer', function () {
done();
});
});

it('returns a clone of the set object', function (done) {
dynamis.set('foo', { example: 'lol' }, function () {
dynamis.get('foo', function (error, result) {
expect(result).to.be.a('object');
expect(result.lol).to.equal(undefined);

result.lol = 1;

dynamis.get('foo', function (error, res) {
expect(res.lol).to.equal(undefined);
done();
});
});
});
});
});

describe('#del', function () {
Expand Down

0 comments on commit e04391f

Please sign in to comment.