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 2.1.0 to 2.2.0

38

index.js

@@ -0,4 +1,3 @@

/* global window, define */
(function(factory) {
if (typeof exports !== 'undefined') {

@@ -89,10 +88,12 @@ module.exports = factory();

return fn(sequenceNum++);
} else {
}
else {
return sequenceNum++;
}
}
} else {
};
}
else {
result = function(cb) {
return fn(sequenceNum++, cb);
}
};
}

@@ -130,3 +131,3 @@ return result;

var builder = new Builder();
builder.promisify(promisify)
builder.promisify(promisify);
return builder[fnName].apply(builder, arguments);

@@ -167,3 +168,3 @@ };

builder.createMany = promisify(builder.createMany);
}
};

@@ -186,12 +187,3 @@ builder.withOptions = function(options) {

if (err) return callback(err);
save(name, doc, function(saveErr, saveDoc) {
if(saveErr) return callback(saveErr);
if (factories[name].options.afterCreate) {
factories[name].options.afterCreate.call(this, saveDoc, builder.options, callback);
} else {
callback(saveErr, saveDoc);
}
});
save(name, doc, callback);
});

@@ -327,4 +319,10 @@ };

factory.adapterFor(name).save(doc, model, function (err) {
if (!err) created.push([name, doc]);
callback(err, doc);
if (err) return callback(err);
created.push([name, doc]);
if (factories[name].options.afterCreate) {
factories[name].options.afterCreate.call(this, doc, builder.options, callback);
}
else {
callback(err, doc);
}
});

@@ -331,0 +329,0 @@ }

@@ -6,3 +6,3 @@ {

"author": "Simon Wade",
"version": "2.1.0",
"version": "2.2.0",
"keywords": [

@@ -9,0 +9,0 @@ "factory",

@@ -59,2 +59,22 @@ # factory-girl

### Options
Options can be provided when you define a model:
```javascript
factory.define('user', User, { foo: 'bar' }, options);
```
Alternatively you can create a new factory that specifies options for all of its models:
```javascript
var builder = factory.withOptions(options);
```
Currently the supported options are:
#### `afterCreate: function(instance, options, callback)`
Provides a function that is called after a new model instance is saved.
## Defining Associations

@@ -76,2 +96,3 @@

## Defining Sequences
```javascript

@@ -78,0 +99,0 @@ factory.define('post', Post, {

@@ -222,5 +222,6 @@ /* global describe, beforeEach, afterEach */

context('defined with an afterCreate handler', function() {
var spy = sinon.spy();
var spy;
before(function() {
beforeEach(function() {
spy = sinon.spy();
factory.define('job with after create', Job, {

@@ -246,5 +247,13 @@ title: 'Engineer',

factory.create('job with after create', function(err, job) {
job.title.should.eql('Astronaut')
job.title.should.eql('Astronaut');
});
});
it('calls afterCreate with createMany', function() {
var num = 10;
factory.createMany('job with after create', num, function(err) {
spy.callCount.should.equal(num);
});
});
});

@@ -477,3 +486,4 @@

factory.withOptions({ key: 'value' }).create('job with after create', function() {});
var builder = factory.withOptions({ key: 'value' });
builder.create('job with after create', function() {});
});

@@ -493,5 +503,3 @@

var builder = factory.withOptions({ key: 'value' });
builder.withOptions({ key: 'value 2', anotherKey: 'value' });
var builder = factory.withOptions({ key: 'value 2', anotherKey: 'value' });
builder.create('job with after create', function() {});

@@ -498,0 +506,0 @@ });

Sorry, the diff of this file is not supported yet

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