Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

factory-girl

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

factory-girl - npm Package Compare versions

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc