Giter Site home page Giter Site logo

Comments (14)

createthis avatar createthis commented on September 25, 2024 6

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, 
});

from factory-girl.

simonexmachina avatar simonexmachina commented on September 25, 2024 3

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

from factory-girl.

chetanism avatar chetanism commented on September 25, 2024 2

@gunar, it should happen soon!

from factory-girl.

chetanism avatar chetanism commented on September 25, 2024 1

@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.

from factory-girl.

chetanism avatar chetanism commented on September 25, 2024

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.

from factory-girl.

lblazecki avatar lblazecki commented on September 25, 2024

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

from factory-girl.

chetanism avatar chetanism commented on September 25, 2024

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.

from factory-girl.

lblazecki avatar lblazecki commented on September 25, 2024

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.

from factory-girl.

lblazecki avatar lblazecki commented on September 25, 2024

@chetanism

Thank you :)
It's working now 👍

from factory-girl.

gunar avatar gunar commented on September 25, 2024

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

from factory-girl.

createthis avatar createthis commented on September 25, 2024

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?

from factory-girl.

chetanism avatar chetanism commented on September 25, 2024

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.

from factory-girl.

gunar avatar gunar commented on September 25, 2024

@chetanism what about now? 😇

from factory-girl.

hschoenburg avatar hschoenburg commented on September 25, 2024

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

from factory-girl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.