Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions lib/factory-lady.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
doc[key] = attrs[key];
}
}
callback(doc);
callback(null, doc);
});
};

Expand All @@ -92,19 +92,16 @@
userAttrs = {};
}

build(name, userAttrs, function(doc) {
build(name, userAttrs, function(err, doc) {
doc.save(function(err) {
if(err) {
throw err;
}
callback(doc);
callback(err, doc);
});
});
};

var assoc = function(name, attr) {
return function(callback) {
create(name, function(doc) {
create(name, function(err, doc) {
if(attr) {
callback(doc[attr]);
} else {
Expand Down
18 changes: 12 additions & 6 deletions test/factory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ describe('Factory', function() {

describe('#build', function() {
it('builds, but does not save the object', function(done) {
Factory.build('job', function(job) {
Factory.build('job', function(err, job) {
if (err) done(err);
(job instanceof Job).should.be.true;
job.title.should.eql('Engineer');
job.company.should.eql('Foobar Inc.');
Expand All @@ -48,7 +49,8 @@ describe('Factory', function() {

context('passing attributes as second argument', function() {
it('sets them', function(done) {
Factory.build('job', { title: "Artist", company: "Bazqux Co." }, function(job) {
Factory.build('job', { title: "Artist", company: "Bazqux Co." }, function(err, job) {
if (err) done(err);
(job instanceof Job).should.be.true;
job.title.should.eql('Artist');
job.company.should.eql('Bazqux Co.');
Expand All @@ -60,7 +62,8 @@ describe('Factory', function() {

context('factory containing an association', function() {
it('is able to handle that', function(done) {
Factory.build('person', { age: 30 }, function(person) {
Factory.build('person', { age: 30 }, function(err, person) {
if (err) done(err);
(person instanceof Person).should.be.true;
person.should.not.have.property('saveCalled');
person.name.should.eql('person 1');
Expand All @@ -79,7 +82,8 @@ describe('Factory', function() {

describe('#create', function() {
it('builds and saves the object', function(done) {
Factory.create('job', function(job) {
Factory.create('job', function(err, job) {
if (err) done(err);
(job instanceof Job).should.be.true;
job.title.should.eql('Engineer');
job.company.should.eql('Foobar Inc.');
Expand All @@ -90,7 +94,8 @@ describe('Factory', function() {

context('passing attributes as second argument', function() {
it('sets them', function(done) {
Factory.create('job', { title: "Artist", company: "Bazqux Co." }, function(job) {
Factory.create('job', { title: "Artist", company: "Bazqux Co." }, function(err, job) {
if (err) done(err);
(job instanceof Job).should.be.true;
job.title.should.eql('Artist');
job.company.should.eql('Bazqux Co.');
Expand All @@ -102,7 +107,8 @@ describe('Factory', function() {

context('Factory(...) instead of Factory.create(...)', function() {
it('is aliased, so it does the same thing as #create', function(done) {
Factory('job', function(job) {
Factory('job', function(err, job) {
if (err) done(err);
(job instanceof Job).should.be.true;
job.title.should.eql('Engineer');
job.company.should.eql('Foobar Inc.');
Expand Down