Merge pull request #1738 from strongloop/fix/modification-of-datasource-config
datasource: copy settings object in constructor
This commit is contained in:
commit
91ab3e9162
|
@ -126,6 +126,12 @@ function DataSource(name, settings, modelBuilder) {
|
||||||
settings = utils.parseSettings(settings);
|
settings = utils.parseSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shallow-clone the settings so that updates to `ds.settings`
|
||||||
|
// do not modify the original object provided via constructor arguments
|
||||||
|
if (settings) settings = Object.assign({}, settings);
|
||||||
|
// It's possible to provide settings object via the "name" arg too!
|
||||||
|
if (typeof name === 'object') name = Object.assign({}, name);
|
||||||
|
|
||||||
this.modelBuilder = modelBuilder || new ModelBuilder();
|
this.modelBuilder = modelBuilder || new ModelBuilder();
|
||||||
this.models = this.modelBuilder.models;
|
this.models = this.modelBuilder.models;
|
||||||
this.definitions = this.modelBuilder.definitions;
|
this.definitions = this.modelBuilder.definitions;
|
||||||
|
|
|
@ -9,6 +9,15 @@ const should = require('./init.js');
|
||||||
const DataSource = require('../lib/datasource.js').DataSource;
|
const DataSource = require('../lib/datasource.js').DataSource;
|
||||||
|
|
||||||
describe('DataSource', function() {
|
describe('DataSource', function() {
|
||||||
|
it('clones settings to prevent surprising changes in passed args', () => {
|
||||||
|
const config = {connector: 'memory'};
|
||||||
|
|
||||||
|
const ds = new DataSource(config);
|
||||||
|
ds.settings.extra = true;
|
||||||
|
|
||||||
|
config.should.eql({connector: 'memory'});
|
||||||
|
});
|
||||||
|
|
||||||
it('reports helpful error when connector init throws', function() {
|
it('reports helpful error when connector init throws', function() {
|
||||||
const throwingConnector = {
|
const throwingConnector = {
|
||||||
name: 'loopback-connector-throwing',
|
name: 'loopback-connector-throwing',
|
||||||
|
|
Loading…
Reference in New Issue