Skip to content

Commit

Permalink
Break all the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wswoodruff committed Dec 29, 2016
1 parent 821fcbb commit fd3e14c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
45 changes: 35 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Hoek = require('hoek');
const Joi = require('joi');
const Schema = require('./schema');
const Package = require('../package.json');
const Items = require('items');

const internals = {};

Expand Down Expand Up @@ -87,11 +88,6 @@ internals.registrationConfig = (options) => {

exports.Model = class SchwiftyModel extends Model {

constructor(...args) {

super(...args);
}

// $beforeInsert() {
// this.createdAt = new Date().toISOString();
// };
Expand All @@ -106,7 +102,15 @@ exports.Model = class SchwiftyModel extends Model {
return err;
}

$validate(json = this, options = {}) {
$validate(json, options) {

if (!json) {
json = this;
}

if (!options) {
options = {};
}

const ModelClass = this.constructor;

Expand Down Expand Up @@ -153,14 +157,35 @@ internals.initialize = function (server, next) {

internals.stop = function (server, next) {

const collector = internals.state(server.root).collector;
const rootCollector = internals.state(server.root).collector;

// Do not teardown if specifically asked not to
if (collector.teardownOnStop === false) {
if (rootCollector.teardownOnStop === false) {
return next();
}

return server.root.knex().destroy(next);
const knexConnections = [];

Object.keys(rootCollector.knexGroups).forEach((key) => {

console.log(rootCollector.knexGroups[key].models);
knexConnections.push(rootCollector.knexGroups[key].knex);
});


/////
console.log(knexConnections.length);
Items.parallel(knexConnections, (item, nxt) => {

knexConnections.knex.destroy(nxt);
},
(err) => {

if(err) {
throw new Error(err);
}
return next();
})
};

internals.schwifty = function (config) {
Expand Down Expand Up @@ -301,7 +326,7 @@ internals.knex = function (serverFrom, realmPath) {

const rootCollector = internals.state(serverFrom(this).root).collector;
const knexGroupId = Hoek.reach(this, `${realmPath}.plugins.schwifty.knexGroupId`);

console.log(knexGroupId);
return rootCollector.knexGroups[knexGroupId].knex;
};
};
Expand Down
8 changes: 4 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ describe('Schwifty', () => {

// Monkeypatch the destroy func
const oldDestroy = srv.knex().destroy;
srv.knex().destroy = (...args) => {
srv.knex().destroy = () => {

++toredown;
oldDestroy(...args);
Function.prototype.apply(oldDestroy, arguments);
};

expect(server.knex()).to.exist();
Expand Down Expand Up @@ -175,10 +175,10 @@ describe('Schwifty', () => {

// Monkeypatch the destroy func
const oldDestroy = srv.knex().destroy;
srv.knex().destroy = (...args) => {
srv.knex().destroy = () => {

++toredown;
oldDestroy(...args);
Function.prototype.apply(oldDestroy, arguments);
};

expect(server.knex()).to.exist();
Expand Down

0 comments on commit fd3e14c

Please sign in to comment.