Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New stable release #63

Closed
lblazecki opened this issue Aug 14, 2016 · 14 comments
Closed

New stable release #63

lblazecki opened this issue Aug 14, 2016 · 14 comments

Comments

@lblazecki
Copy link

Hello

I like your work. Factory_girl is module that is much needed in nodeJS community.
Unfortunately, I didn't managed to connect new factory_girl version with sequelize adapter factory_girl.
When do you think new stable version will be out?

@chetanism
Copy link
Collaborator

Hi @lblazecki, thanks for raising the issue. I suppose there are two problems to fix here: #64 and that we haven't put the new version for factory-girl-sequelize yet. Sorry for the confusion that you had to face, but we'll need another 1-2 weeks to sort everything out.

@lblazecki
Copy link
Author

@chetanism thank you for your response :)
I am looking forward to it!

@chetanism
Copy link
Collaborator

Hi @lblazecki, we just managed to fix #64 as well as add a Sequelize adapter to factory girl itself.
You should be able to:
import factory, { SequelizeAdapter } from 'factory-girl'
Let us know in case you face any issues.

@lblazecki
Copy link
Author

Hi @chetanism

I faced an issue:

.../node_modules/factory-girl/index.js:66
      throw new Error('Invalid Model constructor passed to the factory');
      ^
Error: Invalid Model constructor passed to the factory

This is the line in code:

if (!Model || typeof Model !== 'function') {
  throw new Error('Invalid Model constructor passed to the factory');
}

When typeof Model !== 'function' is removed it's working normally, but I am not sure what are the consequences of removing it.

@chetanism
Copy link
Collaborator

@lblazecki, if I am right, the issue is probably because of Sequelize Model. FactoryGirl expects Model to be a constructor function that can be used to create new instances. In case of Sequelize I guess Model.Instance is the constructor function.

Thanks for pointing out the issue. Here is what you can do to keep things working at your end, till we get this fixed:

  • update your package.json to point factory-girl to https://github.com/chetanism/factory-girl.git#v4-sequelize-fix
  • Import factory-girl from `factory-girl/dist'
  • To avoid putting factory-girl/dist at all places, create a wrapper script in your app and import the wrapper script wherever required, once the issue is fixed, you can easily change it back to importing from factory-girl

I have just pushed the updated build to the above mentioned branch. This should keep you going while we fix the issue.

@lblazecki
Copy link
Author

@chetanism

Thank you :)
It's working now 👍

@gunar
Copy link

gunar commented Oct 26, 2016

It seems both #63 & #64 are resolved now. Can we haz stable version? 😇 TY!!

@createthis
Copy link

createthis commented Oct 26, 2016

I can't seem to get v4 working with Sequelize 3.24.4. I think npm installed factory-girl 4.0.0-beta.7.

Here's my setup:

var factory = require('factory-girl');
const adapter = new factory.SequelizeAdapter();
factory = factory.factory;

const Models = require('../../models');

factory.define('products', Models.products, {
  name: 'Some Foo',
  priority: 50, 
});

At this point I get TypeError: Model is not a constructor. I can't seem to find the magic incantation to get a sequelize model object that factory-girl finds kosher.

I'm using sequelize's import method to place one model per file: http://docs.sequelizejs.com/en/latest/api/sequelize/#importpath-model
You can see an example of what that looks like here: https://github.com/sequelize/express-example/blob/master/models/task.js

Any ideas?

@createthis
Copy link

Solved.

Looking at the source of the failure message, here: https://github.com/aexmachina/factory-girl/blob/7e4335330a4e85d4c6c2ecf9a881df8ff9b77965/src/adapters/DefaultAdapter.js#L4

It looked like I just wasn't initializing the SequelizeAdapter properly, so I was hitting the DefaultAdapter. I would have noticed that earlier, but I'm running my tests in mocha and it took me forever to figure out how to get a trace from Node's UnhandledPromiseRejectionWarning via the unhandledRejection event. In case anyone else is curious, just added this to the mocha test file:

process.on('unhandledRejection', (reason, p) => {
  console.log('Unhandled Rejection at: Promise', p);
  console.log('reason:', reason);
});

Anyway, I just needed to call setAdapter. Here's the working code:

var factory = require('factory-girl');
const adapter = new factory.SequelizeAdapter();
factory = factory.factory;
factory.setAdapter(adapter);

const Models = require('../../models');

factory.define('products', Models.products, {
  name: 'Some Foo',
  priority: 50, 
});

@chetanism
Copy link
Collaborator

Hi @createthis, glad that your problem is solved. I did saw the mail for this issue, but couldn't find time to look into it. Thanks for posting the comment, it would help if someone else faces the issue.
I just have one request, if you face any issues, please open a new issue for it. Not just it would keep the discussion separate, it would also help others to find it easily if they face similar problem.

@chetanism
Copy link
Collaborator

@gunar, it should happen soon!

@gunar
Copy link

gunar commented Jan 30, 2017

@chetanism what about now? 😇

@simonexmachina
Copy link
Owner

I've published v4 🎉 Thanks everyone who's contributed to this release, and sorry it took us so long to get it released!

@hschoenburg
Copy link

@createthis THANK YOU SO MUCH FOR POSTING YOUR SOLUTION!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants