Navigation Menu

Skip to content

Commit

Permalink
Fix error around Domain#dump() for blank domain
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 13, 2012
1 parent 9d5d4a1 commit cde9b4f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/database/domain.js
Expand Up @@ -327,6 +327,8 @@ Domain.prototype = {
});

var tableContents = dump.split('load --table ' + this.tableName)[1];
// if the table is blank, tableContents becomes undefined.
if (!tableContents) return [];
tableContents = JSON.parse(tableContents);

var columnNames = tableContents[0];
Expand Down
10 changes: 9 additions & 1 deletion test/database-domain.test.js
Expand Up @@ -408,7 +408,6 @@ suite('database', function() {
temporaryDatabase = utils.createTemporaryDatabase();
context = temporaryDatabase.get();
utils.loadDumpFile(context, __dirname + '/fixture/companies/ddl.grn');
utils.loadDumpFile(context, __dirname + '/fixture/companies/data.grn');
domain = new Domain('companies', context);
});

Expand All @@ -418,7 +417,14 @@ suite('database', function() {
temporaryDatabase = undefined;
});

test('dump for blank domain', function() {
var actualDump = domain.dump();
assert.deepEqual(actualDump, []);
});

test('dump', function() {
utils.loadDumpFile(context, __dirname + '/fixture/companies/data.grn');

var actualDump = domain.dump();
assert.isTrue(Array.isArray(actualDump), actualDump);
assert.equal(actualDump.length, 10, actualDump);
Expand Down Expand Up @@ -450,6 +456,8 @@ suite('database', function() {
});

test('load', function() {
utils.loadDumpFile(context, __dirname + '/fixture/companies/data.grn');

var values = [
{ id: 'id10',
description: 'updated',
Expand Down

0 comments on commit cde9b4f

Please sign in to comment.