petejkim / factory-lady Goto Github PK
View Code? Open in Web Editor NEWa factory library for node.js / javascript inspired by factory_girl
Home Page: http://search.npmjs.org/#/factory-lady
License: MIT License
a factory library for node.js / javascript inspired by factory_girl
Home Page: http://search.npmjs.org/#/factory-lady
License: MIT License
Are dependent attributes supported?
See: https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#dependent-attributes
I am using factory-girl together with Faker.js to generate sane large amounts of data, data is generated in an async manner, so i get the "call stack exceeded" message from factory-gril, the code bellow avoids that:
Avoid exceeding call stack:
asyncForEach(hash.keys(attrs), function(key, cb) {
var fn = attrs[key];
if(typeof fn === 'function') {
fn(function(value) {
attrs[key] = value;
setImmediate(function() { cb() })
});
} else {
setImmediate(function() { cb() })
}
}, function() {
var doc = new model();
var key;
for(key in attrs) {
if(attrs.hasOwnProperty(key)) {
doc[key] = attrs[key];
}
}
setImmediate(function() { callback(doc) })
});
You might improve it
I've got a One-to-One relationship between a User
model and a few role models such as Admin
, Manager
, and Customer
. How might you handle a scenario like this? I'm using Mongoose, but I believe the same principles apply for any One-to-One relationship.
User Schema
var UserSchema = new Schema({
email: {
// ...
},
password: {
// ...
},
roles: {
admin: { type: mongoose.Schema.Types.ObjectId, ref: 'Admin' },
manager: { type: mongoose.Schema.Types.ObjectId, ref: 'Manager' },
customer: { type: mongoose.Schema.Types.ObjectId, ref: 'Customer' }
},
salt: {
// ...
},
updated: {
// ...
},
created: {
// ...
}
});
Admin Schema
var AdminSchema = new Schema({
user: {
id: { type: Schema.Types.ObjectId, ref: 'User' },
name: { type: String, default: '' }
},
created: {
// ...
}
});
Hi there,
I like girl grown up and became lady.
Is there any example of how you would write fixtures with Sequelize?
Thanks,
Sanjay
I'm trying to test the default values on some Mongoose models. The test I'm using was basically making the object without the property in question and then testing if that value is added. However, this pattern does not seem to work with Factory Lady.
Is there a specific way to test defaults with Factory Lady? I already tried passing in { property_name: undefined }
to Factory.build
, to no avail.
Is there a way to create a single file or folder with the factories in them the way actory_girl allows?
Would be cool to be able to place a folder with multiple files or single file (maybe JSON format (factories.js?) with all the factories.
Something like:
test/
factories.js
or
test/
factories/
person.js
jobs.js
....
Thoughts?
Is there a way to create subdocuments with factoryLady. For some reason I keep getting a null return.
faker = require "Faker"
Upload = app.models.broadcasts.upload
factoryLady.define "upload", Upload,
bucket: "jumper-ios-test"
region: "us-west-1"
bucketKey: "2DE45F47-6782-4532-8C4C-2B4285BAC84E"
meta:
test: faker.Lorem.words(3).join ""
This will have meta = null in my returned object
As for now I'm doing it like this. (which doesn't right at all)
Factory.create("doc", function(doc) {
Factory.create("doc", function(doc) {
Factory.create("doc", function(doc) {
done();
});
});
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.