Socket
Socket
Sign inDemoInstall

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 0.1.0 to 0.1.1

26

index.js

@@ -16,2 +16,5 @@ (function() {

if (!factories[name]) {
return callback(new Error("No factory defined for model '" + name + "'"));
}
factory.build(name, userAttrs, function(err, doc) {

@@ -40,2 +43,5 @@ var model = factories[name].model;

if (!factories[name]) {
return callback(new Error("No factory defined for model '" + name + "'"));
}
var model = factories[name].model;

@@ -49,7 +55,7 @@ var attrs = copy(factories[name].attributes);

if (!fn.length) {
attrs[key] = fn();
attrs[key] = fn.call(attrs);
cb();
}
else {
fn(function(err, value) {
fn.call(attrs, function(err, value) {
if (err) return cb(err);

@@ -97,2 +103,18 @@ attrs[key] = value;

factory.promisify = function(promiseLibrary) {
var promisified = {};
for (var i in factory) {
promisified[i] = factory[i];
}
var promisify = promiseLibrary.promisify || promiseLibrary.denodeify;
if (promisify) {
promisified.build = promisify(factory.build);
promisified.create = promisify(factory.create);
return promisified;
}
else {
throw new Error("No 'promisify' or 'denodeify' method found in supplied promise library");
}
}
var Adapter = function() {};

@@ -99,0 +121,0 @@ factory.Adapter = Adapter;

2

package.json

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

"author": "Simon Wade",
"version": "0.1.0",
"version": "0.1.1",
"keywords": ["factory", "test", "bdd", "tdd", "fixture"],

@@ -9,0 +9,0 @@ "repository" : {

# factory-girl
`factory-girl` is a factory library for [Node.js](http://nodejs.org/) / JavaScript inspired by [Factory\_girl](http://github.com/thoughtbot/factory_girl). It works asynchronously and supports lazy attributes as well as associations.
`factory-girl` is a factory library for [Node.js](http://nodejs.org/) and the browser that is inspired by [Factory\_girl](http://github.com/thoughtbot/factory_girl). It works asynchronously and supports associations and the use of functions for generating attributes.
It is based on [factory-lady](https://github.com/petejkim/factory-lady), but uses an adapter to talk to your models (and doesn't use `throw` for errors that might occur during save).
It started out as a fork of [factory-lady](https://github.com/petejkim/factory-lady), but the fork deviated quite a bit. This module uses an adapter to talk to your models so it can support different ORMs such as [Bookshelf](https://github.com/aexmachina/factory-girl-bookshelf) and [Sequelize](https://github.com/aexmachina/factory-girl-sequelize) (and doesn't use `throw` for errors that might occur during save).

@@ -15,3 +15,3 @@ ## Installation

To use `factory-girl` in the browser or other JavaScript environments, just include `index.js`.
To use `factory-girl` in the browser or other JavaScript environments, just include `index.js` and access `window.Factory`.

@@ -30,12 +30,24 @@ ## Defining Factories

factory.define('user', User, {
email : function() { return 'user' + emailCounter++ + '@example.com'; }, // lazy attribute
async : function(cb) { somethingAsync(cb); }, // async lazy attribute
state : 'activated',
password : '123456'
state: 'activated',
// define attributes using functions
email: function() {
return 'user' + emailCounter++ + '@example.com';
},
// or using async functions by accepting a callback
async: function(callback) {
somethingAsync(callback);
},
password: '123456'
});
factory.define('post', Post, {
user_id : factory.assoc('user', 'id') // simply factory.assoc('user') for user object itself,
subject : 'Hello World',
content : 'Lorem ipsum dolor sit amet...'
// create associations using factory.assoc(model, attr)
// or factory.assoc('user') for user object itself
user_id: factory.assoc('user', 'id'),
subject: 'Hello World',
content: 'Lorem ipsum dolor sit amet...',
// you can refer to other attributes using `this`
slug: function() {
return slugify(this.subject);
}
});

@@ -42,0 +54,0 @@ ```

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