diff --git a/api/resizeImages.js b/api/resizeImages.js index 28b326ac..c49b0ecc 100644 --- a/api/resizeImages.js +++ b/api/resizeImages.js @@ -19,8 +19,11 @@ var $ = Mobify.$ var bits = [defaults.host]; if (defaults.projectName) { - var projectId = "project-" + defaults.projectName; - bits.push(projectId); + bits.push("project-" + defaults.projectName); + } + + if (options.cacheHours) { + bits.push('c' + options.cacheHours); } if (options.format) { @@ -28,7 +31,7 @@ var $ = Mobify.$ } if (options.maxWidth) { - bits.push(options.maxWidth) + bits.push(options.maxWidth); if (options.maxHeight) { bits.push(options.maxHeight); diff --git a/tests/index.html b/tests/index.html index 7fcef2ec..c0e94c89 100644 --- a/tests/index.html +++ b/tests/index.html @@ -449,6 +449,15 @@

equal(got, vow); }); + test('Mobify.getImageURL cached string', 2, function() { + var url = 'http://test/image.jpg'; + var result1 = Mobify.getImageURL(url, {maxWidth: '320', cacheHours: '8'}); + var result2 = Mobify.getImageURL(url, {maxWidth: 320, cacheHours: 8}); + var expected = '//ir0.mobify.com/c8/320/' + url; + equal(result1, expected); + equal(result2, expected); + }); + test('Mobify.getImageURL - projectName set on Mobify.conf.data', function() { expect(1); @@ -464,6 +473,22 @@

} }); + test('Mobify.getImageURL - projectName and cache expiry set', function() { + expect(1); + + try { + Mobify.$.fn.resizeImages.defaults.projectName = 'testing'; + + got = Mobify.getImageURL('http://test/image.jpg', + {maxWidth: 320, cacheHours:8}); + vow = "//ir0.mobify.com/project-testing/c8/320/http://test/image.jpg"; + + equal(got, vow); + } finally { + delete Mobify.$.fn.resizeImages.defaults.projectName; + } + }); + module('enhance'); @@ -571,15 +596,15 @@

urlmatch = Mobify.urlmatch; - /* - * Takes a path, an urlmatch path expression or regular expression and an - * expectation about whether these should match and calls qunit's - * `equal()` on the result of running urlmatch with the given expression + /* + * Takes a path, an urlmatch path expression or regular expression and an + * expectation about whether these should match and calls qunit's + * `equal()` on the result of running urlmatch with the given expression * window.location faked to the given path on http://a.com/ */ testUrlMatch = function(path, expression, expected) { var match, matched, symbol, url; - + // Set up urlmatch with a mocked window object with a mocked location object // set to `url` url = "http://a.com" + path; @@ -589,10 +614,10 @@

matched = !!match(); symbol = (expected != false ? "☑": "☒"); - expression = (typeof expression === 'string' ? + expression = (typeof expression === 'string' ? '"' + expression + '"' : expression); - equal(matched, expected, + equal(matched, expected, symbol + " : " + path + " : " + expression); }; @@ -626,7 +651,7 @@

testUrlMatch("/abb/c", "/a.b/c", false); testUrlMatch("/aab/c", "/a+b/*/", false); testUrlMatch("/a$b/c", "/a$b/*", true); - + // RegExp test suite testUrlMatch("/a", /a/, true); testUrlMatch("/a/", /^\/a\//, true); @@ -636,9 +661,9 @@

testUrlMatch("/a/some/other/other/stuff/b/", /^\/a.*b(\/)?$/, true) // Things other than path expressions and RegExps - equal(urlmatch({}), false, + equal(urlmatch({}), false, "passing the empty object to urlmatch makes it return false"); - equal(urlmatch("/a/b/c")(5), false, + equal(urlmatch("/a/b/c")(5), false, "passing a number to urlmatch makes it return false"); }); //test