mirror of
https://github.com/knex/knex.git
synced 2025-12-29 07:59:31 +00:00
fixing some tests
This commit is contained in:
parent
1b5fa05636
commit
eac78db9f8
@ -54,8 +54,9 @@ _.extend(Sqlite3Client.prototype, base.protoProps, {
|
||||
|
||||
// Empty the connection after we run the query, unless one was specifically
|
||||
// set (in the case of transactions, etc).
|
||||
return dfd.promise.fin(function() {
|
||||
return dfd.promise.then(function(resp) {
|
||||
if (emptyConnection) instance.pool.release(conn);
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
5
knex.js
5
knex.js
@ -1437,12 +1437,13 @@
|
||||
// sql statements used in the table creation. These need to be processed
|
||||
// on the same connection.
|
||||
if (_.isArray(builder.sql)) {
|
||||
return builder.client.getConnection().then(function(conn) {
|
||||
var emptyConnection = !builder._connection;
|
||||
return Q.resolve(builder._connection || builder.client.getConnection()).then(function(conn) {
|
||||
builder._connection = conn;
|
||||
return _.reduce(builder.sql, function(memo, sql) {
|
||||
return memo.then(function () { builder.client.query(_.extend({}, builder, {sql: sql})); });
|
||||
}, Q.resolve()).fin(function() {
|
||||
builder.client.pool.release(conn);
|
||||
if (emptyConnection) builder.client.pool.release(conn);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,10 +1,15 @@
|
||||
var Q = require('q');
|
||||
module.exports = function(Knex, item, handler, type) {
|
||||
|
||||
before(function(ok) {
|
||||
module.exports = function(Knex, handler, error) {
|
||||
|
||||
Q.all([
|
||||
|
||||
var res = null;
|
||||
return Q.all([
|
||||
Knex.Schema.dropTableIfExists('test_table_one'),
|
||||
Knex.Schema.dropTableIfExists('test_table_two'),
|
||||
Knex.Schema.dropTableIfExists('test_table_three'),
|
||||
Knex.Schema.dropTableIfExists('accounts')
|
||||
]).then(function(resp) {
|
||||
res = resp;
|
||||
return Q.all([
|
||||
Knex.Schema.createTable('test_table_one', function(table) {
|
||||
table.increments('id');
|
||||
table.string('first_name');
|
||||
@ -19,48 +24,40 @@ module.exports = function(Knex, item, handler, type) {
|
||||
t.integer('account_id');
|
||||
t.text('details');
|
||||
}),
|
||||
|
||||
Knex.Schema.createTable('test_table_three', function(table) {
|
||||
table.integer('main').primary();
|
||||
table.text('paragraph').defaultTo('Lorem ipsum Qui quis qui in.');
|
||||
})
|
||||
|
||||
]).then(function(resp) {
|
||||
|
||||
// Edit test table one
|
||||
return Knex.Schema.table('test_table_one', function(t) {
|
||||
t.string('phone').nullable();
|
||||
}).then(function(res2) {
|
||||
resp.push(res2);
|
||||
return resp;
|
||||
});
|
||||
|
||||
}).then(handler(ok, true), ok);
|
||||
|
||||
});
|
||||
|
||||
describe(item, function() {
|
||||
|
||||
it('conditionally drops tables with `dropTableIfExists` - ' + item, function(ok) {
|
||||
Knex.Schema.dropTableIfExists('items').then(handler(ok), ok);
|
||||
]);
|
||||
})
|
||||
.then(function(resp) {
|
||||
// Edit test table one
|
||||
res = res.concat(resp);
|
||||
return Knex.Schema.table('test_table_one', function(t) {
|
||||
t.string('phone').nullable();
|
||||
});
|
||||
|
||||
if (type !== 'String') {
|
||||
it('checks for table existence with `hasTable` - ' + item, function(ok) {
|
||||
Knex.Schema.hasTable('test_table_two').then(handler(ok), ok);
|
||||
});
|
||||
}
|
||||
|
||||
it('renames tables with `renameTable` - ' + item, function(ok) {
|
||||
Knex.Schema.renameTable('test_table_one', 'accounts').then(handler(ok), ok);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
after(function(ok) {
|
||||
|
||||
Knex.Schema.dropTable('test_table_three').then(handler(ok), ok);
|
||||
|
||||
});
|
||||
}).then(function(resp) {
|
||||
// conditionally drops tables with `dropTableIfExists`
|
||||
res.push(resp);
|
||||
return Knex.Schema.dropTableIfExists('items');
|
||||
})
|
||||
.then(function(resp) {
|
||||
res.push(resp);
|
||||
return Knex.Schema.hasTable('test_table_two');
|
||||
})
|
||||
.then(function(resp) {
|
||||
res.push(resp);
|
||||
return Knex.Schema.renameTable('test_table_one', 'accounts');
|
||||
})
|
||||
.then(function(resp) {
|
||||
res.push(resp);
|
||||
return Knex.Schema.dropTable('test_table_three');
|
||||
})
|
||||
.then(function(resp) {
|
||||
res.push(resp);
|
||||
return res;
|
||||
})
|
||||
.then(handler, error);
|
||||
|
||||
};
|
||||
@ -32,23 +32,17 @@ module.exports = function(Knex, type) {
|
||||
|
||||
describe('DB Tests - ' + type, function() {
|
||||
|
||||
before(function(ok) {
|
||||
Q.all([
|
||||
Knex.Schema.dropTableIfExists('test_table_one'),
|
||||
Knex.Schema.dropTableIfExists('test_table_two'),
|
||||
Knex.Schema.dropTableIfExists('test_table_three'),
|
||||
Knex.Schema.dropTableIfExists('accounts')
|
||||
]).done(function() {
|
||||
ok();
|
||||
}, ok);
|
||||
});
|
||||
|
||||
describe('Knex.SchemaBuilder', function() {
|
||||
require('./lib/schema')(Knex, type, handler(type, 'schema'), 'DB');
|
||||
});
|
||||
|
||||
describe('Knex.Builder', function() {
|
||||
|
||||
before(function(ok) {
|
||||
var val = handler(type, 'schema');
|
||||
require('./lib/schema')(Knex, function() {
|
||||
setTimeout(function() { ok(); }, 10);
|
||||
}, function(err) {
|
||||
throw new Error(err);
|
||||
}, type);
|
||||
});
|
||||
|
||||
describe('Inserts', function() {
|
||||
require('./lib/inserts')(Knex, type, handler(type, 'inserts'), 'DB');
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -5,15 +5,23 @@ var out = require('./index').output;
|
||||
|
||||
var handler = function(instance, section) {
|
||||
var item = 1;
|
||||
return function(resolver) {
|
||||
return function(data) {
|
||||
return function(resolver, isAll) {
|
||||
var fn = function(data) {
|
||||
var label = '' + section + '.' + item;
|
||||
out['string'] = out['string'] || {};
|
||||
out['string'][label] = out['string'][label] || {};
|
||||
out['string'][label][instance] = data;
|
||||
item++;
|
||||
resolver();
|
||||
if (!isAll) resolver();
|
||||
};
|
||||
if (isAll) {
|
||||
return function(data) {
|
||||
_.map(data, fn);
|
||||
resolver();
|
||||
};
|
||||
} else {
|
||||
return fn;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@ -23,8 +31,11 @@ module.exports = function(Knex, type) {
|
||||
|
||||
describe('String Tests', function() {
|
||||
|
||||
describe('Knex.SchemaBuilder', function() {
|
||||
require('./lib/schema')(Knex, type, handler(type, 'schema'), 'String');
|
||||
before(function(ok) {
|
||||
var val = handler(type, 'schema');
|
||||
require('./lib/schema')(Knex, val(ok, true), function(err) {
|
||||
throw new Error(err);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Knex.Builder', function() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user