factory-girl
Advanced tools
Comparing version 1.6.0 to 2.0.0
16
index.js
(function(factory) { | ||
if (typeof exports !== 'undefined') { | ||
@@ -304,3 +305,3 @@ module.exports = factory(); | ||
} | ||
} | ||
}; | ||
}; | ||
@@ -336,13 +337,4 @@ | ||
function merge(obj1, obj2) { | ||
if (obj1 && obj2) { | ||
var key; | ||
for (key in obj2) { | ||
if (obj2.hasOwnProperty(key)) { | ||
obj1[key] = obj2[key]; | ||
} | ||
} | ||
} | ||
return obj1; | ||
} | ||
var merge = require('lodash.merge'); | ||
function copy(obj) { | ||
@@ -349,0 +341,0 @@ var newObj = {}; |
(function(adapter) { | ||
if (typeof module !== 'undefined') { | ||
@@ -4,0 +3,0 @@ var ObjectAdapter = adapter(); |
@@ -6,3 +6,3 @@ { | ||
"author": "Simon Wade", | ||
"version": "1.6.0", | ||
"version": "2.0.0", | ||
"keywords": [ | ||
@@ -19,2 +19,3 @@ "factory", | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
@@ -29,3 +30,5 @@ "url": "http://github.com/aexmachina/factory-girl/issues" | ||
], | ||
"dependencies": {}, | ||
"dependencies": { | ||
"lodash.merge": "^3.3.2" | ||
}, | ||
"devDependencies": { | ||
@@ -32,0 +35,0 @@ "bluebird": "^2.9.25", |
@@ -13,3 +13,3 @@ # factory-girl | ||
``` bash | ||
```bash | ||
npm install factory-girl | ||
@@ -22,3 +22,3 @@ ``` | ||
``` javascript | ||
```javascript | ||
var factory = require('factory-girl'), | ||
@@ -45,3 +45,3 @@ User = require('../../app/models/user'), | ||
console.log(user.attributes); // => {state: 'active', email: 'user1@demo.com', async: 'foo'} | ||
)); | ||
}); | ||
@@ -67,3 +67,3 @@ factory.define('comment', Comment, { | ||
// subject: 'Hello World', slug: 'hello-world'} | ||
)); | ||
}); | ||
``` | ||
@@ -73,3 +73,3 @@ | ||
``` javascript | ||
```javascript | ||
factory.build('post', function(err, post) { | ||
@@ -96,3 +96,3 @@ // post is a Post instance that is not saved | ||
``` javascript | ||
```javascript | ||
factory.buildMany('post', 10, function(err, posts) { | ||
@@ -121,21 +121,27 @@ // build 10 posts | ||
``` javascript | ||
```javascript | ||
var doc = factory.buildSync('post', {title: 'Foo'}); | ||
``` | ||
## Creating new Factories and Adapters | ||
## Adapters | ||
Adapters provide [support for different databases and ORMs](https://www.npmjs.org/browse/keyword/factory-girl). | ||
Adapters can be registered for specific models, or as the 'default adapter', which is used for any models for which an adapter has not been specified. | ||
See the adapter docs for usage, but typical usage is: | ||
``` javascript | ||
var anotherFactory = new factory.Factory(); | ||
var BookshelfAdapter = require('factory-girl-bookshelf').BookshelfAdapter; | ||
anotherFactory.setAdapter(BookshelfAdapter); // use the Bookshelf adapter | ||
```javascript | ||
// use the bookshelf adapter as the default adapter | ||
require('factory-girl-bookshelf')(); | ||
// use the ObjectAdapter (that simply returns raw objects) for the `post` model | ||
factory.setAdapter(factory.ObjectAdapter, 'post'); | ||
``` | ||
Or use the ObjectAdapter that simply returns raw objects. | ||
## Creating new Factories | ||
You can create multiple factories which have different settings: | ||
```javascript | ||
var ObjectAdapter = factory.ObjectAdapter; | ||
anotherFactory.setAdapter(ObjectAdapter, 'post'); // use the ObjectAdapter for posts | ||
var anotherFactory = new factory.Factory(); | ||
var BookshelfAdapter = require('factory-girl-bookshelf').BookshelfAdapter; | ||
anotherFactory.setAdapter(BookshelfAdapter); // use the Bookshelf adapter | ||
``` | ||
@@ -142,0 +148,0 @@ |
@@ -50,3 +50,8 @@ /* global describe, beforeEach, afterEach */ | ||
title: 'Engineer', | ||
company: 'Foobar Inc.' | ||
company: 'Foobar Inc.', | ||
duties: { | ||
cleaning: false, | ||
writing: true, | ||
computing: true | ||
} | ||
}); | ||
@@ -73,3 +78,3 @@ | ||
it('sets them', function(done) { | ||
factory.build('job', { title: "Artist", company: "Bazqux Co." }, function(err, job) { | ||
factory.build('job', { title: "Artist", company: "Bazqux Co.", duties: { cleaning: true, writing: false } }, function(err, job) { | ||
(job instanceof Job).should.be.true; | ||
@@ -79,2 +84,5 @@ job.title.should.eql('Artist'); | ||
job.should.not.have.property('saveCalled'); | ||
job.duties.cleaning.should.be.true; | ||
job.duties.writing.should.be.false; | ||
job.duties.computing.should.be.true; | ||
done(); | ||
@@ -486,2 +494,1 @@ }); | ||
}); | ||
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
122344
147
1
913
+ Addedlodash.merge@^3.3.2
+ Addedlodash._arraycopy@3.0.0(transitive)
+ Addedlodash._arrayeach@3.0.0(transitive)
+ Addedlodash._basecopy@3.0.1(transitive)
+ Addedlodash._basefor@3.0.3(transitive)
+ Addedlodash._bindcallback@3.0.1(transitive)
+ Addedlodash._createassigner@3.1.1(transitive)
+ Addedlodash._getnative@3.9.1(transitive)
+ Addedlodash._isiterateecall@3.0.9(transitive)
+ Addedlodash.isarguments@3.1.0(transitive)
+ Addedlodash.isarray@3.0.4(transitive)
+ Addedlodash.isplainobject@3.2.0(transitive)
+ Addedlodash.istypedarray@3.0.6(transitive)
+ Addedlodash.keys@3.1.2(transitive)
+ Addedlodash.keysin@3.0.8(transitive)
+ Addedlodash.merge@3.3.2(transitive)
+ Addedlodash.restparam@3.6.1(transitive)
+ Addedlodash.toplainobject@3.0.0(transitive)