Git Product home page Git Product logo

fixer's Introduction

Fixer

Node.js module to setup your test database using fixtures in a breeze. Inspired by Rails fixtures.

Limitations

  • Only supports sequelize ORM at the moment.
  • I haven't tested many-to-many relationships for now but I will as soon as possible.

Install

npm install fixer

Usage

See example/load_fixtures.js.

var fixer = require('fixer');
/**
 * @param {Object} fixtures associative object. keys represent model names and values contain an array of fixtures for that model. fixture are simple associative objects.
 * @param {Object} models associative object. key represents the model
 * name and value is the Sequelize model
 */
fixer(fixtures, models).load(function (err) {
  if (err) return console.error(err);
  console.log('Finished loading fixtures into database.');
});

Example fixtures (in coffeescript):

students.coffee

module.exports =
  oli:
    first_name: 'Olivier'
    last_name: 'Lalonde'
    email: '[email protected]'
    school: 'NYU'
  mark:
    first_name: 'Mark'
    last_name: 'Zuckerberg'
    email: '[email protected]'
    school: 'Harvard'

schools.coffee

module.exports =
  'NYU':
    name: 'New York University'
    email: '[email protected]'
  'Harvard':
    name: 'University of Harvard'
    email: '[email protected]'

You can reference other fixtures by their key. For example, students.oli.school reference fixture schools.NYU.

fixer's People

Contributors

luka-m avatar olalonde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fixer's Issues

Why not use findOrCreate?

Hi @olalonde at line 104, why not use findOrCreate?
On my case I don't want to force the sync and the second time I ran my tests I got an error Duplicated Entry. Would be nice to use the sequelizejs findOrCreate instead of create so the second time I run my tests I wouldn't get a error message.

Associations not being persisted

I don't see associations being persisted in either my own attempt at using this library or in using the example in the project.

I've forked the project and plan to investigate myself, but are you aware of this issue? Is there a known workaround?

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.