Skip to content

Instantly share code, notes, and snippets.

@bendrucker
Created October 1, 2014 09:52
Show Gist options
  • Save bendrucker/cf298bf515d8b6fdcd05 to your computer and use it in GitHub Desktop.
Save bendrucker/cf298bf515d8b6fdcd05 to your computer and use it in GitHub Desktop.
Truncate data during tests with knex
'use strict';
var Promise = require('bluebird');
var knex = require('../../src/db').knex;
var tables = [
'organizations',
'campaigns',
'donors',
'pledges',
'payments'
];
function truncate () {
return Promise.each(tables, function (table) {
return knex.raw('truncate table ' + table + ' cascade');
});
};
function seed () {
return Promise.each(tables, function (table) {
return knex(table).insert(require('./seeds/' + table));
});
};
describe('Integration Tests', function () {
beforeEach(function () {
return truncate().then(seed);
});
afterEach(function () {
return truncate();
});
require('require-all')(__dirname + '/specs');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment