diff --git a/NEWS.md b/NEWS.md index 643ff5c1..f8bb3b17 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ 1.1.2 (DD//MM//YY) ----- +* Fix use of "style_version" with GET (inline styles) 1.1.1 (DD//MM//YY) diff --git a/config/environments/test.js.example b/config/environments/test.js.example index a021f25b..908d39a6 100644 --- a/config/environments/test.js.example +++ b/config/environments/test.js.example @@ -10,7 +10,6 @@ var config = { user: "publicuser", host: '127.0.0.1', port: 5432, - srid: 4326, extent: "-20005048.4188,-20005048.4188,20005048.4188,20005048.4188", simplify: true } diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index e1ab444b..7550d871 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -65,7 +65,7 @@ module.exports = function(){ me.req2params = function(req, callback){ // Whitelist query parameters and attach format - var good_query = ['sql', 'geom_type', 'cache_buster', 'cache_policy', 'callback', 'interactivity', 'map_key', 'api_key', 'style']; + var good_query = ['sql', 'geom_type', 'cache_buster', 'cache_policy', 'callback', 'interactivity', 'map_key', 'api_key', 'style', 'style_version']; var bad_query = _.difference(_.keys(req.query), good_query); _.each(bad_query, function(key){ delete req.query[key]; }); diff --git a/test/acceptance/server.js b/test/acceptance/server.js index fb564ff7..a31eaa46 100644 --- a/test/acceptance/server.js +++ b/test/acceptance/server.js @@ -247,7 +247,7 @@ suite('server', function() { }, function(res) { var parsed = JSON.parse(res.body); assert.equal(parsed.style, 'Map {background-color:#fff;}'); - //assert.equal(parsed.version, '2.0.0'); + assert.equal(parsed.style_version, '2.0.0'); done(); }); @@ -261,7 +261,7 @@ suite('server', function() { url: '/tiles/my_table5/style?map_key=1234', method: 'POST', headers: {host: 'localhost', 'Content-Type': 'application/x-www-form-urlencoded' }, - data: querystring.stringify({style: style}) + data: querystring.stringify({style: style, style_version: '2.0.2'}) },{ }, function(res) { @@ -276,7 +276,7 @@ suite('server', function() { }, function(res) { var parsed = JSON.parse(res.body); assert.equal(parsed.style, style); - //assert.equal(parsed.version, '2.0.0'); + assert.equal(parsed.style_version, '2.0.2'); done(); }); @@ -689,6 +689,47 @@ suite('server', function() { }); }); + var test_style_black_200 = "#test_table{marker-fill:black;marker-line-color:red;marker-width:10}"; + var test_style_black_210 = "#test_table{marker-fill:black;marker-line-color:red;marker-width:20}"; + + test("get'ing a tile with url specified 2.0.0 style should return an expected tile", function(done){ + var style = querystring.stringify({style: test_style_black_200, style_version: '2.0.0'}); + assert.response(server, { + headers: {host: 'localhost'}, + url: '/tiles/test_table/15/16046/12354.png?cache_buster=4&' + style, // madrid + method: 'GET', + encoding: 'binary' + },{}, function(res){ + assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); + var ct = res.headers['content-type']; + assert.equal(ct, 'image/png'); + assert.imageEqualsFile(res.body, './test/fixtures/test_table_15_16046_12354_styled_black.png', 2, + function(err, similarity) { + if (err) throw err; + done(); + }); + }); + }); + + test("get'ing a tile with url specified 2.1.0 style should return an expected tile", function(done){ + var style = querystring.stringify({style: test_style_black_210, style_version: '2.1.0'}); + assert.response(server, { + headers: {host: 'localhost'}, + url: '/tiles/test_table/15/16046/12354.png?cache_buster=4&' + style, // madrid + method: 'GET', + encoding: 'binary' + },{}, function(res){ + assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); + var ct = res.headers['content-type']; + assert.equal(ct, 'image/png'); + assert.imageEqualsFile(res.body, './test/fixtures/test_table_15_16046_12354_styled_black.png', 2, + function(err, similarity) { + if (err) throw err; + done(); + }); + }); + }); + ///////////////////////////////////////////////////////////////////////////////// // // DELETE CACHE diff --git a/test/support/assert.js b/test/support/assert.js index bd1c45ce..82fcf99d 100644 --- a/test/support/assert.js +++ b/test/support/assert.js @@ -8,29 +8,35 @@ var exec = require('child_process').exec; var assert = module.exports = exports = require('assert'); -assert.imageEqualsFile = function(buffer, file_b, callback) { +// +// @param tol tolerated color distance as a percent over max channel value +// by default this is zero. For meaningful values, see +// http://www.imagemagick.org/script/command-line-options.php#metric +// +assert.imageEqualsFile = function(buffer, file_b, tol, callback) { if (!callback) callback = function(err) { if (err) throw err; }; file_b = path.resolve(file_b); - var file_a = '/tmp/' + (Math.random() * 1e16); + var file_a = '/tmp/windshaft-test-image-test.png'; // + (Math.random() * 1e16); // TODO: make predictable var err = fs.writeFileSync(file_a, buffer, 'binary'); if (err) throw err; - exec('compare -metric PSNR "' + file_a + '" "' + + var fuzz = tol + '%'; + exec('compare -fuzz ' + fuzz + ' -metric AE "' + file_a + '" "' + file_b + '" /dev/null', function(err, stdout, stderr) { if (err) { fs.unlinkSync(file_a); callback(err); } else { stderr = stderr.trim(); - if (stderr === 'inf') { - fs.unlinkSync(file_a); - callback(null); + var similarity = parseFloat(stderr); + if ( similarity > 0 ) { + var err = new Error('Images not equal(' + similarity + '): ' + + file_a + ' ' + file_b); + err.similarity = similarity; + callback(err); } else { - var similarity = parseFloat(stderr); - var err = new Error('Images not equal(' + similarity + '): ' + - file_a + ' ' + file_b); - err.similarity = similarity; - callback(err); + fs.unlinkSync(file_a); + callback(null); } } });