Removed unused code, added comments
diff --git a/helpers/build.js b/helpers/build.js
index fdcd313..af17953 100644
--- a/helpers/build.js
+++ b/helpers/build.js
@@ -237,11 +237,13 @@
options.to = options.from
}
+ // if an entity object or UsergridEntity instance is the first argument (source)
if (_.isObject(args[0]) && !_.isFunction(args[0]) && _.isString(args[1])) {
_.assign(options.entity, args[0])
options.relationship = _.first([options.relationship, args[1]].filter(_.isString))
}
+ // if an entity object or UsergridEntity instance is the third argument (target)
if (_.isObject(args[2]) && !_.isFunction(args[2])) {
_.assign(options.to, args[2])
}
@@ -255,6 +257,7 @@
} else if (_.isString(args[2]) && !_.isUuid(args[2]) && _.isString(args[3]) && _.isObject(args[0]) && !_.isFunction(args[0])) {
options.to.type = args[2]
}
+
options.to.uuidOrName = _.first([options.to.uuidOrName, options.to.uuid, options.to.name, args[4], args[3], args[2]].filter(function(u) {
return (_.isString(options.to.type) && _.isString(u) || _.isUuid(u))
}))
@@ -320,6 +323,7 @@
options.direction = _.first([options.direction, args[0]].filter(function(d) {
return (d === "IN" || d === "OUT")
}))
+
options.relationship = _.first([options.relationship, args[3], args[2]].filter(_.isString))
options.uuidOrName = _.first([options.uuidOrName, options.uuid, options.name, args[2]].filter(_.isString))
options.type = _.first([options.type, args[1]].filter(_.isString))
diff --git a/helpers/index.js b/helpers/index.js
index 6ab2b35..aaa05a1 100644
--- a/helpers/index.js
+++ b/helpers/index.js
@@ -7,6 +7,9 @@
time = require('./time'),
_ = require('lodash')
+// By mixing this in here, lodash-uuid is available everywhere lodash is used.
+_.mixin(require('lodash-uuid'))
+
module.exports = _.assign(module.exports, {
cb: cb,
build: build,
diff --git a/helpers/query.js b/helpers/query.js
index 8b8a095..c0f4394 100644
--- a/helpers/query.js
+++ b/helpers/query.js
@@ -3,8 +3,6 @@
var util = require('util'),
_ = require('lodash')
-_.mixin(require('lodash-uuid'))
-
module.exports = {
useQuotesIfRequired: function(value) {
return (_.isFinite(value) || _.isUuid(value) || _.isBoolean(value) || _.isObject(value) && !_.isFunction(value) || _.isArray(value)) ? value : util.format("'%s'", value)
diff --git a/lib/client.js b/lib/client.js
index fa3a99f..a705cdc 100644
--- a/lib/client.js
+++ b/lib/client.js
@@ -82,7 +82,7 @@
options.callback(error, usergridResponse, usergridResponse.entities)
})
},
- disconnect: function(options, callback) {
+ disconnect: function() {
var options = helpers.build.connection(this, Array.prototype.slice.call(arguments))
request({
uri: options.uri,
@@ -94,7 +94,7 @@
options.callback(error, usergridResponse, usergridResponse.entities)
})
},
- getConnections: function(options, callback) {
+ getConnections: function() {
var options = helpers.build.getConnections(this, Array.prototype.slice.call(arguments))
request({
uri: options.uri,
diff --git a/tests/lib/client.test.js b/tests/lib/client.test.js
index 142beee..f78ad1d 100644
--- a/tests/lib/client.test.js
+++ b/tests/lib/client.test.js
@@ -631,7 +631,7 @@
it('should fail to connect entities when specifying target name without type', function() {
should(function() {
- client.connect(entity1.type, entity1.name, "fails", 'badName', function(err, usergridResponse) {})
+ client.connect(entity1.type, entity1.name, "fails", 'badName', function() {})
}).throw()
})
})
@@ -777,7 +777,7 @@
var entity2 = response.last
should(function() {
- client.disconnect(entity1.type, entity1.name, "fails", entity2.name, function(err, usergridResponse) {})
+ client.disconnect(entity1.type, entity1.name, "fails", entity2.name, function() {})
}).throw()
})
})
diff --git a/tests/lib/entity.test.js b/tests/lib/entity.test.js
index fceca09..ea5b5b0 100644
--- a/tests/lib/entity.test.js
+++ b/tests/lib/entity.test.js
@@ -5,13 +5,11 @@
config = require('../../helpers').config,
UsergridClient = require('../../lib/client'),
UsergridQuery = require('../../lib/query'),
- UsergridEntity = require('../../lib/entity'),
_ = require('lodash')
_.mixin(require('lodash-uuid'))
-var _uuid,
- _slow = 500,
+var _slow = 800,
_timeout = 4000
describe('connect()', function() {
@@ -103,7 +101,7 @@
it('should fail to connect entities when specifying target name without type', function() {
should(function() {
- entity1.connect("fails", 'badName', function(err, usergridResponse) {})
+ entity1.connect("fails", 'badName', function() {})
}).throw()
})
})
@@ -230,7 +228,7 @@
var entity2 = response.last
should(function() {
- client.disconnect(entity1.type, entity1.name, "fails", entity2.name, function(err, usergridResponse) {})
+ client.disconnect(entity1.type, entity1.name, "fails", entity2.name, function() {})
}).throw()
})
})
\ No newline at end of file