不要怂,就是干,撸起袖子干!

Commit 834b9f07 by Rémi Weislinger Committed by GitHub

fix(postgres): parse enums correctly when describing a table (#12409) (#12411)

1 parent 7fba6684
...@@ -838,7 +838,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator { ...@@ -838,7 +838,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
return []; return [];
} }
matches = matches.map(m => m.replace(/",$/, '').replace(/,$/, '').replace(/(^"|"$)/, '')); matches = matches.map(m => m.replace(/",$/, '').replace(/,$/, '').replace(/(^"|"$)/g, ''));
return matches.slice(0, -1); return matches.slice(0, -1);
} }
......
...@@ -1312,5 +1312,45 @@ if (dialect.startsWith('postgres')) { ...@@ -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);
});
});
});
}); });
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!