factory-girl
Advanced tools
Comparing version 1.4.0 to 1.4.1
31
index.js
@@ -22,3 +22,3 @@ (function() { | ||
var builder = new Builder(); | ||
return builder[fnName].apply(this, arguments); | ||
return builder[fnName].apply(builder, arguments); | ||
}; | ||
@@ -66,7 +66,19 @@ }; | ||
} | ||
promisified.build = promisify(factory.build); | ||
promisified.create = promisify(factory.create); | ||
promisified.buildMany = promisify(factory.buildMany); | ||
promisified.createMany = promisify(factory.createMany); | ||
var promisifiedBuilderProxy = function(fnName) { | ||
return function() { | ||
var builder = new Builder(); | ||
builder.promisify(promisify) | ||
return builder[fnName].apply(builder, arguments); | ||
}; | ||
}; | ||
promisified.withOptions = promisifiedBuilderProxy('withOptions'); | ||
promisified.build = promisifiedBuilderProxy('build'); | ||
promisified.buildMany = promisifiedBuilderProxy('buildMany'); | ||
promisified.create = promisifiedBuilderProxy('create'); | ||
promisified.createMany = promisifiedBuilderProxy('createMany'); | ||
promisified.cleanup = promisify(factory.cleanup); | ||
return promisified; | ||
@@ -90,6 +102,13 @@ }; | ||
builder.promisify = function(promisify) { | ||
builder.build = promisify(builder.build); | ||
builder.create = promisify(builder.create); | ||
builder.buildMany = promisify(builder.buildMany); | ||
builder.createMany = promisify(builder.createMany); | ||
} | ||
builder.withOptions = function(options) { | ||
merge(builder.options, options); | ||
return builder; | ||
} | ||
}; | ||
@@ -96,0 +115,0 @@ builder.create = function(name, attrs, callback) { |
@@ -6,3 +6,3 @@ { | ||
"author": "Simon Wade", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"keywords": [ | ||
@@ -30,2 +30,3 @@ "factory", | ||
"devDependencies": { | ||
"bluebird": "^2.9.25", | ||
"chai": "^1.10.0", | ||
@@ -32,0 +33,0 @@ "mocha": ">= 0.7.1", |
@@ -41,3 +41,5 @@ # factory-girl | ||
}); | ||
console.log(factory.build('user')); // => {state: 'active', email: 'user1@demo.com', async: 'foo'} | ||
factory.build('user', function(err, user) { | ||
console.log(user.attributes); // => {state: 'active', email: 'user1@demo.com', async: 'foo'} | ||
)); | ||
@@ -54,9 +56,7 @@ factory.define('post', Post, { | ||
}); | ||
console.log(factory.build('post')); // => {user_id: 1, subject: 'Hello World', slug: 'hello-world'} | ||
factory.build('post', function(err, post) { | ||
console.log(post.attributes); // => {user_id: 1, subject: 'Hello World', slug: 'hello-world'} | ||
)); | ||
``` | ||
### Factory#assoc | ||
You can optionally provide attributes to the associated factory by passing an object as third argument. | ||
## Using Factories | ||
@@ -78,2 +78,6 @@ | ||
### Factory#assoc | ||
You can optionally provide attributes to the associated factory by passing an object as third argument. | ||
### Factory#buildMany | ||
@@ -123,3 +127,3 @@ | ||
``` | ||
```javascript | ||
var ObjectAdapter = factory.ObjectAdapter; | ||
@@ -126,0 +130,0 @@ anotherFactory.setAdapter(ObjectAdapter, 'post'); // use the ObjectAdapter for posts |
@@ -420,3 +420,30 @@ /* global describe, beforeEach, afterEach */ | ||
describe('#promisify', function() { | ||
var promisifiedFactory; | ||
before(function() { | ||
var Promise = require('bluebird'); | ||
promisifiedFactory = factory.promisify(Promise); | ||
}); | ||
it('promisifies #build', function(done) { | ||
promisifiedFactory.build('job').then(function(job) { | ||
(job instanceof Job).should.be.true; | ||
job.title.should.eql('Engineer'); | ||
job.company.should.eql('Foobar Inc.'); | ||
done(); | ||
}); | ||
}); | ||
it('works with chained builders too', function(done) { | ||
promisifiedFactory.withOptions({}).build('job').then(function(job) { | ||
(job instanceof Job).should.be.true; | ||
job.title.should.eql('Engineer'); | ||
job.company.should.eql('Foobar Inc.'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
Sorry, the diff of this file is not supported yet
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
117870
837
134
5