Merge pull request #2737 from jaswilli/issue-2736-pg

Ensure settings values are strings before saving
This commit is contained in:
Hannah Wolfe 2014-05-13 14:28:29 +01:00
commit 169a984372
2 changed files with 18 additions and 2 deletions

View File

@ -214,6 +214,10 @@ settings = {
return when.all(checks);
};
if (!_.isString(value)) {
value = JSON.stringify(value);
}
// Allow shorthand syntax
if (_.isString(key)) {
key = { settings: [{ key: key, value: value }]};
@ -247,4 +251,4 @@ settings = {
};
module.exports = settings;
module.exports.updateSettingsCache = updateSettingsCache;
module.exports.updateSettingsCache = updateSettingsCache;

View File

@ -163,4 +163,16 @@ describe('Settings API', function () {
done();
});
});
});
it('ensures values are stringified before saving to database', function (done) {
return callApiWithContext(defaultContext, 'edit', 'title', []).then(function (response) {
should.exist(response);
testUtils.API.checkResponse(response, 'settings');
response.settings.length.should.equal(1);
testUtils.API.checkResponse(response.settings[0], 'setting');
response.settings[0].value.should.equal('[]');
done();
}).catch(done);
});
});