diff --git a/gun.js b/gun.js index d51b71ed..ea1b67ea 100644 --- a/gun.js +++ b/gun.js @@ -2024,8 +2024,10 @@ ;(function(){ Gun.chain.set = function(item, cb, opt){ - var gun = this; + var gun = this, soul; cb = cb || function(){}; + if (soul = Gun.node.soul(item)) return gun.set(gun.get(soul), cb, opt); + if (Gun.obj.is(item) && !Gun.is(item)) return gun.set(gun._.root.put(item), cb, opt); return item.val(function(node){ var put = {}, soul = Gun.node.soul(node); if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + node + '"!')}) } diff --git a/test/common.js b/test/common.js index 4bcce18b..d668a814 100644 --- a/test/common.js +++ b/test/common.js @@ -6088,12 +6088,19 @@ describe('Gun', function(){ var alice = gun.put({name: 'alice', birth: Math.random()}).key('person/alice'); var bob = gun.put({name: 'bob', birth: Math.random()}).key('person/bob'); var carl = gun.put({name: 'carl', birth: Math.random()}).key('person/carl'); - var dave = gun.put({name: 'dave', birth: Math.random()}).key('person/dave'); - + var dave = gun.put({name: 'dave', birth: Math.random()}).key('person/dave'); + + // Test set with new object + var alan = users.set({name: 'alan', birth: Math.random()}).key('person/alan'); + alan.val(function(alan) { + // Test set with node + dave.path('friends').set(alan); + }); + users.set(alice); users.set(bob); users.set(carl); - users.set(dave); + users.set(dave); alice.path('friends').set(bob).back.set(carl); bob.path('friends').set(alice); @@ -6101,7 +6108,8 @@ describe('Gun', function(){ var team = gun.get('team/lions').put({name: "Lions"}); team.path('members').set(alice); - team.path('members').set(bob); + team.path('members').set(bob); + team.path('members').set(alan); // Test set with set alice.path('team').put(team); bob.path('team').put(team); @@ -6113,10 +6121,14 @@ describe('Gun', function(){ } else if('bob' === member.name){ done.bob = true; - } else { + } else + if('alan' === member.name){ + done.alan = true; + } else + { expect(member).to.not.be.ok(); } - if(done.alice && done.bob){ + if(done.alice && done.bob && done.alan){ setTimeout(function(){ done(); },10);