downstairs
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -21,4 +21,11 @@ var Collection = {} | ||
var caller = function(modelCallbackName, _cb){ | ||
record.callbacks[modelCallbackName](data, _cb); | ||
var caller = function(invocation, _cb){ | ||
if (typeof invocation === "string"){ | ||
record.callbacks[invocation](data, _cb); | ||
} | ||
else { //we assume it's an object matching {name: 'callbackName', args: [...]} | ||
invocation.args.push(_cb); | ||
var func = record.callbacks[invocation.name].bind(null, data); | ||
func.apply(null, invocation.args); | ||
} | ||
} | ||
@@ -25,0 +32,0 @@ |
{ | ||
"name": "downstairs", | ||
"description": "A light ORM wrapped about brianc's node-sql and node-pg", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"homepage": "https://github.com/moneytribeaustralia/downstairs.js", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -91,3 +91,2 @@ var Downstairs = require('../lib/downstairs') | ||
describe('defining callbacks on the Model that are run on the Record', function(done){ | ||
@@ -99,5 +98,2 @@ beforeEach(function(done) { | ||
it("after find", function(done) { | ||
var pgConnection = new Connection.PostgreSQL(env.connectionString); | ||
Downstairs.add(pgConnection); | ||
var User = Collection.model('User', helper.userConfig); | ||
@@ -124,5 +120,2 @@ var Role = Collection.model('Role', helper.roleConfig); | ||
it("after findAll", function(done) { | ||
var pgConnection = new Connection.PostgreSQL(env.connectionString); | ||
Downstairs.add(pgConnection); | ||
var User = Collection.model('User', helper.userConfig); | ||
@@ -153,4 +146,41 @@ var Role = Collection.model('Role', helper.roleConfig); | ||
}); | ||
}) | ||
it('with arguments', function(done){ | ||
var User = Collection.model('User', helper.userConfig); | ||
var Role = Collection.model('Role', helper.roleConfig); | ||
Role.hasMany(User); | ||
User.belongsTo(Role); | ||
var loadUsers = function(users, roleName, cb){ | ||
var f = function(){ | ||
if (roleName === 'test'){ | ||
this.secretData = {level: 'yellow access'}; | ||
} else if (roleName === 'admin'){ | ||
this.secretData = {level: 'you see everything as an admin!'}; | ||
} | ||
} | ||
async.forEach(users | ||
, function(user, cb2){ | ||
f.apply(user); | ||
cb2(); | ||
} | ||
, cb) | ||
}; | ||
User.when('securityDisplay', loadUsers); | ||
User.create({username: 'donald'}, function(err, user) { | ||
User.findAll({callbacks: [{name: 'securityDisplay', args: ['test']}]}, function(err, users){ | ||
users[0].secretData.level.should.equal('yellow access'); | ||
User.findAll({callbacks: [{name: 'securityDisplay', args: ['admin']}]}, function(err, users){ | ||
users[0].secretData.level.should.equal('you see everything as an admin!'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('defining events on the Model that are run on a Record', function(done){ | ||
@@ -161,6 +191,9 @@ beforeEach(function(done) { | ||
it("an event for asynchronously creating a dependent", function(done) { | ||
beforeEach(function(done){ | ||
var pgConnection = new Connection.PostgreSQL(env.connectionString); | ||
Downstairs.add(pgConnection); | ||
done(); | ||
}); | ||
it("an event for asynchronously creating a dependent", function(done) { | ||
var User = Collection.model('User', helper.userConfig); | ||
@@ -183,2 +216,2 @@ var Account = Collection.model('Account', helper.accountConfig); | ||
}); | ||
}) | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
107531
1635