Skip to content

Commit

Permalink
fix(postgres): parse enums correctly when describing a table (sequeli…
Browse files Browse the repository at this point in the history
  • Loading branch information
closingin committed Jun 23, 2020
1 parent 7fba668 commit eef2d2d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dialects/postgres/query-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
return [];
}

matches = matches.map(m => m.replace(/",$/, '').replace(/,$/, '').replace(/(^"|"$)/, ''));
matches = matches.map(m => m.replace(/",$/, '').replace(/,$/, '').replace(/(^"|"$)/g, ''));

return matches.slice(0, -1);
}
Expand Down
40 changes: 40 additions & 0 deletions test/unit/dialects/postgres/query-generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1312,5 +1312,45 @@ if (dialect.startsWith('postgres')) {
});
});
});

describe('fromArray()', () => {
beforeEach(function() {
this.queryGenerator = new QueryGenerator({
sequelize: this.sequelize,
_dialect: this.sequelize.dialect
});
});

const tests = [
{
title: 'should convert an enum with no quoted strings to an array',
arguments: '{foo,bar,foobar}',
expectation: ['foo', 'bar', 'foobar']
}, {
title: 'should convert an enum starting with a quoted string to an array',
arguments: '{"foo bar",foo,bar}',
expectation: ['foo bar', 'foo', 'bar']
}, {
title: 'should convert an enum ending with a quoted string to an array',
arguments: '{foo,bar,"foo bar"}',
expectation: ['foo', 'bar', 'foo bar']
}, {
title: 'should convert an enum with a quoted string in the middle to an array',
arguments: '{foo,"foo bar",bar}',
expectation: ['foo', 'foo bar', 'bar']
}, {
title: 'should convert an enum full of quoted strings to an array',
arguments: '{"foo bar","foo bar","foo bar"}',
expectation: ['foo bar', 'foo bar', 'foo bar']
}
];

_.each(tests, test => {
it(test.title, function() {
const convertedText = this.queryGenerator.fromArray(test.arguments);
expect(convertedText).to.deep.equal(test.expectation);
});
});
});
});
}

0 comments on commit eef2d2d

Please sign in to comment.