factory-girl
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -33,7 +33,8 @@ (function() { | ||
factory.assoc = function(name, attr) { | ||
factory.assoc = function(name, key, attrs) { | ||
attrs = attrs || {}; | ||
return function(callback) { | ||
factory.create(name, function(err, doc) { | ||
factory.create(name, attrs, function(err, doc) { | ||
if (err) return callback(err); | ||
callback(null, attr ? doc[attr] : doc); | ||
callback(null, key ? doc[key] : doc); | ||
}); | ||
@@ -40,0 +41,0 @@ }; |
@@ -6,3 +6,3 @@ { | ||
"author": "Simon Wade", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"keywords": [ | ||
@@ -9,0 +9,0 @@ "factory", |
@@ -44,4 +44,4 @@ # factory-girl | ||
factory.define('post', Post, { | ||
// create associations using factory.assoc(model, attr) | ||
// or factory.assoc('user') for user object itself | ||
// create associations using factory.assoc(model, key) | ||
// or factory.assoc('user') to return the user object itself. | ||
user_id: factory.assoc('user', 'id'), | ||
@@ -57,2 +57,6 @@ subject: 'Hello World', | ||
### Factory#assoc | ||
You can optionally provide attributes to the associated factory by passing an object as third argument. | ||
## Using Factories | ||
@@ -59,0 +63,0 @@ |
@@ -41,3 +41,3 @@ /* global describe, beforeEach, afterEach */ | ||
age: 25, | ||
job: factory.assoc('job'), | ||
job: factory.assoc('job', null, { company: 'Bazqux Co.' }), | ||
title: factory.assoc('job', 'title') | ||
@@ -83,3 +83,3 @@ }); | ||
person.job.title.should.eql('Engineer'); | ||
person.job.company.should.eql('Foobar Inc.'); | ||
person.job.company.should.eql('Bazqux Co.'); | ||
person.job.saveCalled.should.be.true; | ||
@@ -86,0 +86,0 @@ person.title.should.eql('Engineer'); |
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
112571
800
130