From 424cc6d93b716a706278b8532aecf47a5a39728b Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Thu, 19 May 2016 15:54:58 +0200 Subject: [PATCH] Fail on turbo-carto invalid quantification methods --- NEWS.md | 6 +++++- lib/cartodb/utils/style/postgres-datasource.js | 7 ++++++- test/acceptance/turbo-cartocss/anonymous-maps.js | 14 ++++++++++++++ test/acceptance/turbo-cartocss/error-cases.js | 15 +++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 9eeb06e3..36ee909f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,11 @@ Released 2016-mm-dd -Adds support for sql wrap in all layers +New features: + - Adds support for sql wrap in all layers + +Bug fixes: + - Fail on turbo-carto invalid quantification methods ## 2.43.1 diff --git a/lib/cartodb/utils/style/postgres-datasource.js b/lib/cartodb/utils/style/postgres-datasource.js index 5db35607..447c9143 100644 --- a/lib/cartodb/utils/style/postgres-datasource.js +++ b/lib/cartodb/utils/style/postgres-datasource.js @@ -38,7 +38,12 @@ PostgresDatasource.prototype.getName = function () { }; PostgresDatasource.prototype.getRamp = function (column, buckets, method, callback) { - var methodName = methods.hasOwnProperty(method) ? method : 'quantiles'; + if (method && !methodTemplates.hasOwnProperty(method)) { + return callback(new Error( + 'Invalid method "' + method + '", valid methods: [' + Object.keys(methodTemplates).join(',') + ']' + )); + } + var methodName = method || 'quantiles'; var template = methodTemplates[methodName]; var query = template({ _column: column, _sql: this.query, _buckets: buckets }); diff --git a/test/acceptance/turbo-cartocss/anonymous-maps.js b/test/acceptance/turbo-cartocss/anonymous-maps.js index 82801815..c0fcbda4 100644 --- a/test/acceptance/turbo-cartocss/anonymous-maps.js +++ b/test/acceptance/turbo-cartocss/anonymous-maps.js @@ -53,6 +53,20 @@ describe('turbo-carto for anonymous maps', function() { var fixturePath = 'test_turbo_carto_greens_13_4011_3088.png'; this.testClient.getTile(13, 4011, 3088, imageCompareFn(fixturePath, done)); }); + + it('should work for different char case in quantification names', function(done) { + this.testClient = new TestClient( + makeMapconfig('#layer { marker-fill: ramp([price], colorbrewer(Greens, 3), jeNkS); }') + ); + this.testClient.getLayergroup(function(err, layergroup) { + assert.ok(!err, err); + + assert.ok(layergroup.hasOwnProperty('layergroupid')); + assert.ok(!layergroup.hasOwnProperty('errors')); + + done(); + }); + }); }); describe('parsing ramp function with colorbrewer for reds and mapnik renderer', function () { diff --git a/test/acceptance/turbo-cartocss/error-cases.js b/test/acceptance/turbo-cartocss/error-cases.js index f43a3636..3967738b 100644 --- a/test/acceptance/turbo-cartocss/error-cases.js +++ b/test/acceptance/turbo-cartocss/error-cases.js @@ -78,6 +78,21 @@ describe('turbo-carto error cases', function() { }); }); + it('should return invalid method from datasource', function(done) { + this.testClient = new TestClient(makeMapconfig(null, 'ramp([wadus_column], (red, green, blue), wadusmethod)')); + this.testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroup) { + assert.ok(!err, err); + + assert.ok(layergroup.hasOwnProperty('errors')); + assert.equal(layergroup.errors.length, 1); + assert.ok(layergroup.errors[0].match(/^turbo-carto/)); + assert.ok(layergroup.errors[0].match(/unable\sto\scompute\sramp/i)); + assert.ok(layergroup.errors[0].match(/invalid\smethod\s\"wadusmethod\"/i)); + + done(); + }); + }); + it('should fail by falling back to normal carto parser', function(done) { this.testClient = new TestClient(makeMapconfig('ramp([price], (8,24,96), (8,24,96));//(red, green, blue))')); this.testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroup) {