Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fix for ac.url.make weird behavior after micro-optmiziation #854

Merged
merged 6 commits into from

2 participants

@caridy
Owner
  • ac.url.make issues
  • func tests failures after the first iteration of the optimization
lib/app/addons/ac/url.common.js
((21 lines not shown))
if (urlParams) {
- urlParams = objectToQueryStr(urlParams, true);
-
- if (urlParams && urlParams.length) {
- url = url + '?' + urlParams;
+ if (Y.Lang.isObject(urlParams)) {
@drewfish Owner

I think Y.Lang.isObject() returns true for arrays too, although it probably doesn't matter too much for this situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/app/addons/ac/url.common.js
((21 lines not shown))
if (urlParams) {
- urlParams = objectToQueryStr(urlParams, true);
-
- if (urlParams && urlParams.length) {
- url = url + '?' + urlParams;
+ if (Y.Lang.isObject(urlParams)) {
+ // adding querystring params to routeParams and let
+ // the url maker to create the proper url. Empty params
+ // will be left out. TODO: why?
+ for (key in urlParams) {
+ if (urlParams.hasOwnProperty(key) && urlParams[key]) {
+ params[key] = urlParams[key];
+ }
+ }
+ } else {
+ Y.log('ac.url.make is expecting an object as urlParams instead of: ' + urlParams, 'warn', NAME);
@drewfish Owner

Small point: perhaps Y.JSON.stringify(urlParams) just to be safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@drewfish
Owner

A couple of small comments. +1 even without those addressed.

@caridy
Owner

@drewfish, can you do a second pass on this one?

@drewfish drewfish commented on the diff
lib/app/addons/ac/url.common.js
((31 lines not shown))
if (urlParams) {
- urlParams = objectToQueryStr(urlParams, true);
-
- if (urlParams && urlParams.length) {
- url = url + '?' + urlParams;
+ urlParams = (typeof urlParams === 'string' ? Y.QueryString.parse(urlParams) :
+ urlParams);
+
+ // adding querystring params to routeParams and let
+ // the url maker to create the proper url. Empty params
+ // will be left out. TODO: why?
@drewfish Owner

I think empty params are left out to "optimize" the URL -- so that it's as short as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@drewfish
Owner

+1

@caridy caridy merged commit 7c48652 into yahoo:develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 11, 2012
  1. @caridy

    adjusting ac.url.make routine to avoid accepting strings for querystr…

    caridy authored
    …ing. avoiding any parsing or stringifing routine at make, instead letting the route maker to deal with that. fixing all unit tests.
  2. @caridy
  3. @caridy
Commits on Dec 12, 2012
  1. @caridy
  2. @caridy
  3. @caridy

    delinting

    caridy authored
This page is out of date. Refresh to see the latest.
View
73 lib/app/addons/ac/url.common.js
@@ -14,28 +14,6 @@
*/
YUI.add('mojito-url-addon', function(Y, NAME) {
- function objectToQueryStr(obj, removeEmpty) {
- var sanitized = {},
- key;
- // If "removeEmpty" is true we remove any params with no value.
- if (removeEmpty) {
- // by creating a copy with valid values we gain
- // a little bit with V8
- for (key in obj) {
- if (obj.hasOwnProperty(key) && obj[key]) {
- sanitized[key] = obj[key];
- }
- }
- obj = sanitized;
- }
-
- if (Y.Lang.isObject(obj) && Y.Object.size(obj) > 0) {
- obj = Y.QueryString.stringify(obj);
- }
-
- return obj;
- }
-
/**
* <strong>Access point:</strong> <em>ac.url.*</em>
@@ -45,7 +23,7 @@ YUI.add('mojito-url-addon', function(Y, NAME) {
function UrlAcAddon(command, adapter, ac) {
this.context = command.context;
this.rs = null;
- this.pathToRoot = ac.config.getAppConfig().pathToRoot;
+ this.pathToRoot = ac.staticAppConfig.pathToRoot;
this.maker = null;
}
@@ -61,39 +39,46 @@ YUI.add('mojito-url-addon', function(Y, NAME) {
* Mojito application configuration.
* @param {string} action Action reference, concatenated to the base
* using a period (.) separator.
- * @param {object} routeParams used to lookup the route in the routing
- * table.
- * @param {string} varb GET, POST, PUT, DELETE (case insensitive).
- * @param {object} urlParams added to the looked up route as query
- * params.
+ * @param {object|string} routeParams used to lookup the route in the routing
+ * table. If string is provided, Y.QueryString.parse will be used.
+ * @param {string} verb the HTTP method. Default value is "get".
+ * @param {object|string} urlParams added to the looked up route as query
+ * params, this has priority over routeParams. If string is provided,
+ * Y.QueryString.parse will be used.
*/
make: function(base, action, routeParams, verb, urlParams) {
var url,
+ key,
+ params,
query = base + '.' + action;
- routeParams = objectToQueryStr(routeParams || {});
-
- if (routeParams && routeParams.length) {
- query = query + '?' + routeParams;
- }
-
- url = this.getRouteMaker().make(query, verb);
+ params = (typeof routeParams === 'string' ? Y.QueryString.parse(routeParams) :
+ Y.merge(routeParams || {}));
if (urlParams) {
- urlParams = objectToQueryStr(urlParams, true);
-
- if (urlParams && urlParams.length) {
- url = url + '?' + urlParams;
+ urlParams = (typeof urlParams === 'string' ? Y.QueryString.parse(urlParams) :
+ urlParams);
+
+ // adding querystring params to routeParams and let
+ // the url maker to create the proper url. Empty params
+ // will be left out. TODO: why?
@drewfish Owner

I think empty params are left out to "optimize" the URL -- so that it's as short as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ for (key in urlParams) {
+ if (urlParams.hasOwnProperty(key) && urlParams[key]) {
+ params[key] = urlParams[key];
+ }
}
+
}
+ url = this.getRouteMaker().make(query, (verb || 'GET').toUpperCase(), params);
+
// IOS PATCH
- if (typeof window !== 'undefined') {
+ if (url && (typeof window !== 'undefined')) {
url = Y.mojito.util.iOSUrl(url);
}
// this is mainly used by html5app
- if (this.pathToRoot) {
+ if (url && this.pathToRoot) {
url = this.pathToRoot + url;
}
@@ -105,7 +90,7 @@ YUI.add('mojito-url-addon', function(Y, NAME) {
* Finds the first matching route from the given URL
* @method find
* @param {string} url the URL to find a route for.
- * @param {string} verb the HTTP method.
+ * @param {string} the HTTP method. Default value is "get".
*/
find: function(url, verb) {
@@ -119,7 +104,7 @@ YUI.add('mojito-url-addon', function(Y, NAME) {
url = url.slice(0, url.indexOf('?'));
}
- return this.getRouteMaker().find(url, verb);
+ return this.getRouteMaker().find(url, (verb || 'GET').toUpperCase());
},
getRouteMaker: function() {
@@ -146,8 +131,8 @@ YUI.add('mojito-url-addon', function(Y, NAME) {
Y.namespace('mojito.addons.ac').url = UrlAcAddon;
}, '0.1.0', {requires: [
- 'querystring',
'mojito-config-addon',
'mojito-route-maker',
+ 'querystring-parse-simple',
'mojito-util'
]});
View
11 lib/app/autoload/route-maker.common.js
@@ -72,9 +72,8 @@ YUI.add('mojito-route-maker', function(Y, NAME) {
// not recomputed.
if (route.verbs.length && route.path && route.call) {
- // FUTURE: [Issue 73] allow object params, not just string
if (!route.params) {
- route.params = '';
+ route.params = {};
}
if (!route.regex) {
route.regex = {};
@@ -218,18 +217,22 @@ YUI.add('mojito-route-maker', function(Y, NAME) {
* @method make
* @param {String} query string to convert to a URL
* @param {String} verb http method
+ * @param {Object} params object representing extra querystring
+ * params. `query` might have querystring portion
+ * portion, in which case they have priority.
*/
- make: function(query, verb) {
+ make: function(query, verb, params) {
// Y.log('make(' + query + ', ' + verb + ')', 'debug', NAME);
var parts = query.split('?'),
call = parts[0],
- params = {},
residual = {},
route,
uri,
k;
+ params = params || {};
+
// TODO: don't assign to a parameter.
verb = verb || 'GET';
View
4 tests/fixtures/gsg5-appConfig/mojits/PagedFlickr/controller.common.js
@@ -84,7 +84,7 @@ YUI.add('PagedFlickr', function(Y) {
for (var k in mods) {
params[k] = mods[k];
}
- return ac.url.make(mojitType, 'index', Y.QueryString.stringify(params));
+ return ac.url.make(mojitType, 'index', params);
}
-}, '0.0.1', {requires: ['mojito-intl-addon', 'mojito-util', 'querystring-stringify', 'ModelFlickr'], lang: ['de', 'en-US']});
+}, '0.0.1', {requires: ['mojito-intl-addon', 'mojito-util', 'ModelFlickr'], lang: ['de', 'en-US']});
View
4 tests/fixtures/gsg5/mojits/PagedFlickr/controller.common.iphone.js
@@ -84,7 +84,7 @@ YUI.add('PagedFlickr', function(Y) {
for (var k in mods) {
params[k] = mods[k];
}
- return ac.url.make(mojitType, 'index', Y.QueryString.stringify(params));
+ return ac.url.make(mojitType, 'index', params);
}
-}, '0.0.1', {requires: ['mojito-intl-addon', 'mojito-util', 'querystring-stringify', 'ModelFlickr'], lang: ['de', 'en-US']});
+}, '0.0.1', {requires: ['mojito-intl-addon', 'mojito-util', 'ModelFlickr'], lang: ['de', 'en-US']});
View
3  tests/fixtures/gsg5/mojits/PagedFlickr/controller.common.js
@@ -84,7 +84,7 @@ YUI.add('PagedFlickr', function(Y) {
for (var k in mods) {
params[k] = mods[k];
}
- return ac.url.make(mojitType, 'index', Y.QueryString.stringify(params));
+ return ac.url.make(mojitType, 'index', params);
}
}, '0.0.1', {requires: [
@@ -92,6 +92,5 @@ YUI.add('PagedFlickr', function(Y) {
'mojito-params-addon',
'mojito-url-addon',
'mojito-util',
- 'querystring-stringify',
'ModelFlickr'
], lang: ['de', 'en-US']});
View
124 tests/func/applications/frameworkapp/routing/mojits/ShowUrl/controller.server.js
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2011 Yahoo! Inc. All rights reserved.
*/
-YUI.add('ShowUrl', function(Y, NAME) {
+YUI.add('ShowUrl', function (Y, NAME) {
/**
* The ShowUrl module.
@@ -23,68 +23,72 @@ YUI.add('ShowUrl', function(Y, NAME) {
* @param ac {Object} The action context that provides access
* to the Mojito API.
*/
- index: function(ac) {
- var mojitName = ac.params.getFromUrl('mojit_name'),
- mojitAction = ac.params.getFromUrl('mojit_action'),
- mojitUrlParams = ac.params.getFromUrl('mojit_urlparams'),
- mojitUrl = ac.params.getFromUrl('mojit_url'),
- mojitVerb = ac.params.getFromUrl('mojit_verb'),
- nameExists = mojitName ? "YES" : "NO",
- actionExists = mojitAction ? "YES" : "NO";
- urlparamsExists = mojitUrlParams ? "YES" : "NO";
- urlExists = mojitUrl ? "YES" : "NO";
+ index: function (ac) {
+ var mojitName = ac.params.getFromUrl('mojit_name'),
+ mojitAction = ac.params.getFromUrl('mojit_action'),
+ mojitUrlParams = ac.params.getFromUrl('mojit_urlparams'),
+ mojitUrl = ac.params.getFromUrl('mojit_url'),
+ mojitVerb = ac.params.getFromUrl('mojit_verb'),
+ nameExists = mojitName ? "YES" : "NO",
+ actionExists = mojitAction ? "YES" : "NO",
+ urlparamsExists = mojitUrlParams ? "YES" : "NO",
+ urlExists = mojitUrl ? "YES" : "NO",
+ url,
+ data,
+ matchroute;
- console.log("**********************" + mojitName);
- console.log("**********************" + mojitAction);
- console.log("**********************" + mojitUrlParams);
- console.log("**********************" + mojitUrl);
- console.log("**********************" + mojitVerb);
+ console.log("**********************" + mojitName);
+ console.log("**********************" + mojitAction);
+ console.log("**********************" + mojitUrlParams);
+ console.log("**********************" + mojitUrl);
+ console.log("**********************" + mojitVerb);
- if (nameExists === "YES" && actionExists === "YES")
- {
- var url = "";
- var error = "";
- try{
- if (urlparamsExists === "YES"){
- url = ac.url.make(mojitName, mojitAction, 'MySpecialRoute', 'GET', mojitUrlParams);
- } else {
- url = ac.url.make(mojitName, mojitAction);
- }
- }catch(error) {
- url = error;
- }
- var data = {
- url: url,
- name: mojitName,
- action: mojitAction
- };
- //ac.http.setHeader('content-type', 'text/html');
- ac.done(data);
- } else if (urlExists === "YES"){
- var matchroute = "";
- var error = "";
- try{
- matchroute = ac.url.find(mojitUrl, mojitVerb);
- }catch(error) {
- url = error;
- }
- console.log(matchroute);
- if(matchroute != null){
- var data = {
- url: mojitUrl,
- verbs: matchroute.verbs.GET,
- call: matchroute.call,
- name: matchroute.name,
- params: matchroute.params.secret,
- }
- }else{
- var data = {
- url: mojitUrl,
- }
+ if (nameExists === "YES" && actionExists === "YES") {
+ url = "";
+ try {
+ if (urlparamsExists === "YES") {
+ url = ac.url.make(mojitName, mojitAction, {
+ id: 'MySpecialRoute'
+ }, mojitVerb, {
+ u: mojitUrlParams
+ });
+ } else {
+ url = ac.url.make(mojitName, mojitAction);
+ }
+ } catch (err1) {
+ url = err1;
}
- ac.done(data);
- }
- }
+ data = {
+ url: url,
+ name: mojitName,
+ action: mojitAction
+ };
+ //ac.http.setHeader('content-type', 'text/html');
+ ac.done(data);
+ } else if (urlExists === "YES") {
+ matchroute = "";
+ try {
+ matchroute = ac.url.find(mojitUrl, mojitVerb);
+ } catch (err2) {
+ url = err2;
+ }
+ console.log(matchroute);
+ if (matchroute !== null) {
+ data = {
+ url: mojitUrl,
+ verbs: matchroute.verbs.GET,
+ call: matchroute.call,
+ name: matchroute.name,
+ params: matchroute.params.secret
+ };
+ } else {
+ data = {
+ url: mojitUrl
+ };
+ }
+ ac.done(data);
+ }
+ }
};
}, '0.0.1', {requires: [
View
6 tests/func/applications/frameworkapp/usecase/mojits/PagedFlickr/controller.common.js
@@ -41,17 +41,17 @@ YUI.add('PagedFlickr', function(Y, NAME) {
data.has_prev = true;
}
ac.done(data);
-
+
});
}
};
-
+
function selfUrl(ac, mods) {
var params = Y.mojito.util.copy(ac.params.getFromMerged());
for (var k in mods) {
params[k] = mods[k];
}
- return ac.url.make('flickr', 'index', Y.QueryString.stringify(params));
+ return ac.url.make('flickr', 'index', params);
}
View
2  tests/func/applications/frameworkapp/usecase/mojits/PagedFlickr2/controller.common.js
@@ -51,7 +51,7 @@ YUI.add('PagedFlickr2', function(Y, NAME) {
for (var k in mods) {
params[k] = mods[k];
}
- return ac.url.make('flickr2', 'index', Y.QueryString.stringify(params));
+ return ac.url.make('flickr2', 'index', params);
}
View
3  tests/func/applications/frameworkapp/usecase/mojits/PagedFlickr5/controller.common.js
@@ -74,7 +74,7 @@ YUI.add('PagedFlickr5', function(Y, NAME) {
for (var k in mods) {
params[k] = mods[k];
}
- return ac.url.make('flickr5', 'index', Y.QueryString.stringify(params));
+ return ac.url.make('flickr5', 'index', params);
}
}, '0.0.1', {requires: [
@@ -84,5 +84,4 @@ YUI.add('PagedFlickr5', function(Y, NAME) {
'mojito-url-addon',
'mojito-intl-addon',
'mojito-util',
- 'querystring-stringify',
'PagedFlickr5Model'], lang: ['de', 'en-US']});
View
4 tests/func/common/html5apptest_descriptor.json
@@ -8,7 +8,7 @@
"baseUrl" : "http://localhost:4084"
},
- "dataprovider" : {
+ "dataprovider" : {
"acmojitdone1client" : {
"group" : "smoke,html5app,acmojit",
"params" : {
@@ -422,7 +422,7 @@
"page" : "$$config.baseUrl$$/mytestpath/index.html"
}
}
- }
+ }
},
{
View
4 tests/func/routing/routingtest_descriptor.json
@@ -8,7 +8,7 @@
"baseUrl" : "http://localhost:4082"
},
- "dataprovider" : {
+ "dataprovider" : {
"BasicRouting1" : {
"group" : "functional,smoke,routing",
"params" : {
@@ -202,7 +202,7 @@
"page" : "$$config.baseUrl$$/showurl?mojit_name=route-2&mojit_action=nothing"
}
}
- }
+ }
},
{
View
10 tests/func/routing/testbasicrouting10-1.js
@@ -6,15 +6,15 @@ YUI({
useBrowserConsole: true,
logInclude: { TestRunner: true }
}).use('node', 'node-event-simulate', 'test', 'console', function (Y) {
-
+
var suite = new Y.Test.Suite("Routing: BasicRouting10-1");
suite.add(new Y.Test.Case({
- "test BasicRouting10-1": function(){
- Y.Assert.areEqual('Click to execute the action \'route-2\' for the mojit \'nothing\'', Y.one('#mylink').get('innerHTML'));
- Y.Assert.areEqual('/route-2/nothing?http://www.abc.com', Y.one('#mylink').get('href').match(/\/route-2\/nothing\?http:\/\/www.abc.com/gi));
+ "test BasicRouting10-1": function(){
+ Y.Assert.areEqual('Click to execute the action \'route-2\' for the mojit \'nothing\'', Y.one('#mylink').get('innerHTML'));
+ Y.Assert.areEqual('/route-2/nothing', Y.one('#mylink').get('href').match(/\/route-2\/nothing/gi));
Y.Assert.areEqual('route-2', Y.one('#name').get('innerHTML'));
}
- }));
+ }));
Y.Test.Runner.add(suite);
});
View
196 tests/unit/lib/app/addons/ac/test-url.common.js
@@ -10,7 +10,8 @@ YUI().use('mojito-url-addon', 'test', 'querystring', function(Y) {
A = Y.Assert,
AA = Y.ArrayAssert,
OA = Y.ObjectAssert,
- RouteMaker;
+ RouteMaker,
+ acMock;
cases = {
name: 'make url tests',
@@ -18,6 +19,9 @@ YUI().use('mojito-url-addon', 'test', 'querystring', function(Y) {
setUp: function() {
// Capture the real RouteMaker
RouteMaker = Y.mojito.RouteMaker;
+ acMock = {
+ staticAppConfig: {}
+ };
},
tearDown: function() {
@@ -31,16 +35,12 @@ YUI().use('mojito-url-addon', 'test', 'querystring', function(Y) {
return {
find: function(url, verb) {
A.areSame('myid.myaction', url);
- A.areSame('get', verb);
+ A.areSame('GET', verb);
return 'ohhai url';
}
};
};
- var addon = new Y.mojito.addons.ac.url({}, null, {
- config: {
- getAppConfig: function() { return {}; }
- }
- });
+ var addon = new Y.mojito.addons.ac.url({}, null, acMock);
addon.setStore({
getRoutes: function() { return 'routes'; }
});
@@ -61,11 +61,7 @@ YUI().use('mojito-url-addon', 'test', 'querystring', function(Y) {
//need to use real find() which needs real RouteMaker
Y.mojito.RouteMaker = RouteMaker;
- addon = new Y.mojito.addons.ac.url({}, null, {
- config: {
- getAppConfig: function() { return {}; }
- }
- });
+ addon = new Y.mojito.addons.ac.url({}, null, acMock);
addon.setStore({
getRoutes: function() { return routes; }
});
@@ -104,11 +100,7 @@ YUI().use('mojito-url-addon', 'test', 'querystring', function(Y) {
//need to use real find() which needs real RouteMaker
Y.mojito.RouteMaker = RouteMaker;
- addon = new Y.mojito.addons.ac.url({}, null, {
- config: {
- getAppConfig: function() { return {}; }
- }
- });
+ addon = new Y.mojito.addons.ac.url({}, null, acMock);
addon.setStore({
getRoutes: function() { return routes; }
});
@@ -125,16 +117,12 @@ YUI().use('mojito-url-addon', 'test', 'querystring', function(Y) {
return {
find: function(url, verb) {
A.areSame('myid.myaction', url);
- A.areSame('post', verb);
+ A.areSame('POST', verb);
return 'ohhai url';
}
};
};
- var addon = new Y.mojito.addons.ac.url({}, null, {
- config: {
- getAppConfig: function() { return {}; }
- }
- });
+ var addon = new Y.mojito.addons.ac.url({}, null, acMock);
addon.setStore({
getRoutes: function() { return 'routes'; }
});
@@ -147,23 +135,20 @@ YUI().use('mojito-url-addon', 'test', 'querystring', function(Y) {
Y.mojito.RouteMaker = function(rtes) {
A.areSame('routes', rtes);
return {
- make: function(query, verb) {
- A.areSame('myid.myaction?foo=bar', query);
- A.areSame('get', verb);
+ make: function(query, verb, params) {
+ A.areSame('myid.myaction', query);
+ A.areSame('bar', params.foo);
+ A.areSame('GET', verb);
return 'ohhai url';
}
};
};
- var addon = new Y.mojito.addons.ac.url({}, null, {
- config: {
- getAppConfig: function() { return {}; }
- }
- });
+ var addon = new Y.mojito.addons.ac.url({}, null, acMock);
addon.setStore({
getRoutes: function() { return 'routes'; }
});
- url = addon.make('myid', 'myaction', 'foo=bar', 'get');
+ url = addon.make('myid', 'myaction', {foo: 'bar'}, 'get');
A.areSame('ohhai url', url);
},
@@ -172,47 +157,43 @@ YUI().use('mojito-url-addon', 'test', 'querystring', function(Y) {
Y.mojito.RouteMaker = function(rtes) {
A.areSame('routes', rtes);
return {
- make: function(query, verb) {
- A.areSame('myid.myaction?foo=bar', query);
- A.areSame('get', verb);
+ make: function(query, verb, params) {
+ A.areSame('myid.myaction', query);
+ A.areSame('bar', params.foo);
+ A.areSame(1, params.a);
+ A.areSame(2, params.b);
+ A.areSame('GET', verb);
return 'ohhai url';
}
};
};
- var addon = new Y.mojito.addons.ac.url({}, null, {
- config: {
- getAppConfig: function() { return {}; }
- }
- });
+ var addon = new Y.mojito.addons.ac.url({}, null, acMock);
addon.setStore({
getRoutes: function() { return 'routes'; }
});
- url = addon.make('myid', 'myaction', 'foo=bar', 'get', {a:1, b:2});
- A.areSame('ohhai url?a=1&b=2', url);
+ url = addon.make('myid', 'myaction', {foo: 'bar'}, 'get', {a:1, b:2});
+ A.areSame('ohhai url', url);
},
'test make url (post)': function() {
Y.mojito.RouteMaker = function(rtes) {
A.areSame('routes', rtes);
return {
- make: function(query, verb) {
- A.areSame('myid.myaction?foo=bar', query);
- A.areSame('post', verb);
+ make: function(query, verb, params) {
+ A.areSame('myid.myaction', query);
+ A.areSame('bar', params.foo);
+ A.areSame('POST', verb);
return 'ohhai url';
}
};
};
- var addon = new Y.mojito.addons.ac.url({}, null, {
- config: {
- getAppConfig: function() { return {}; }
- }
- });
+ var addon = new Y.mojito.addons.ac.url({}, null, acMock);
addon.setStore({
getRoutes: function() { return 'routes'; }
});
- url = addon.make('myid', 'myaction', 'foo=bar', 'post');
+ url = addon.make('myid', 'myaction', {foo: 'bar' }, 'post');
A.areSame('ohhai url', url);
},
@@ -222,16 +203,12 @@ YUI().use('mojito-url-addon', 'test', 'querystring', function(Y) {
return {
make: function(query, verb) {
A.areSame('myid.myaction', query);
- A.isUndefined(verb);
+ A.areSame('GET', verb);
return 'ohhai url';
}
};
};
- var addon = new Y.mojito.addons.ac.url({}, null, {
- config: {
- getAppConfig: function() { return {}; }
- }
- });
+ var addon = new Y.mojito.addons.ac.url({}, null, acMock);
addon.setStore({
getRoutes: function() { return 'routes'; }
});
@@ -244,24 +221,113 @@ YUI().use('mojito-url-addon', 'test', 'querystring', function(Y) {
Y.mojito.RouteMaker = function(rtes) {
A.areSame('routes', rtes);
return {
- make: function(query, verb) {
- A.areSame('myid.myaction?foo=bar', query);
- A.areSame('get', verb);
+ make: function(query, verb, params) {
+ A.areSame('myid.myaction', query);
+ A.areSame('bar', params.foo);
+ A.areSame('GET', verb);
return 'ohhai url';
}
};
};
- var addon = new Y.mojito.addons.ac.url({}, null, {
- config: {
- getAppConfig: function() { return {}; }
- }
- });
+ var addon = new Y.mojito.addons.ac.url({}, null, acMock);
addon.setStore({
getRoutes: function() { return 'routes'; }
});
url = addon.make('myid', 'myaction', {foo:'bar'}, 'get');
A.areSame('ohhai url', url);
+ },
+
+ 'test default verb': function() {
+ Y.mojito.RouteMaker = function(rtes) {
+ A.areSame('routes', rtes);
+ return {
+ make: function(query, verb, params) {
+ A.areSame('myid.myaction', query);
+ A.areSame('GET', verb);
+ return 'ohhai url';
+ }
+ };
+ };
+ var addon = new Y.mojito.addons.ac.url({}, null, acMock);
+ addon.setStore({
+ getRoutes: function() { return 'routes'; }
+ });
+
+ url = addon.make('myid', 'myaction');
+ A.areSame('ohhai url', url);
+ },
+
+ 'test routeParams and queryParams priorities': function() {
+ Y.mojito.RouteMaker = function(rtes) {
+ A.areSame('routes', rtes);
+ return {
+ make: function(query, verb, params) {
+ A.areSame('myid.myaction', query);
+ A.areSame('baz', params.foo, 'queryParams should have the priority');
+ A.areSame('GET', verb);
+ return 'ohhai url';
+ }
+ };
+ };
+ var addon = new Y.mojito.addons.ac.url({}, null, acMock);
+ addon.setStore({
+ getRoutes: function() { return 'routes'; }
+ });
+
+ url = addon.make('myid', 'myaction', {foo: 'bar'}, 'get', {foo: 'baz'});
+ A.areSame('ohhai url', url);
+ },
+
+ 'test routeParams and queryParams as strings': function() {
+ Y.mojito.RouteMaker = function(rtes) {
+ A.areSame('routes', rtes);
+ return {
+ make: function(query, verb, params) {
+ A.areSame('myid.myaction', query);
+ A.areSame('bar', params.foo);
+ A.areSame('baz', params.bar);
+ A.areSame('1', params.a);
+ A.areSame('2', params.b);
+ A.areSame('GET', verb);
+ return 'ohhai url';
+ }
+ };
+ };
+ var addon = new Y.mojito.addons.ac.url({}, null, acMock);
+ addon.setStore({
+ getRoutes: function() { return 'routes'; }
+ });
+
+ url = addon.make('myid', 'myaction', 'foo=bar&bar=baz', 'get', 'a=1&b=2');
+ A.areSame('ohhai url', url);
+ },
+
+ 'test routeParams and queryParams as arrays': function() {
+ Y.mojito.RouteMaker = function(rtes) {
+ A.areSame('routes', rtes);
+ return {
+ make: function(query, verb, params) {
+ console.error(params);
+ A.areSame('myid.myaction', query);
+ A.areSame('a', params['0']);
+ A.areSame('b', params['1']);
+ A.isUndefined(params.foo);
+ A.isUndefined(params.bar);
+ A.isUndefined(params.a);
+ A.isUndefined(params.b);
+ A.areSame('GET', verb);
+ return 'ohhai url';
+ }
+ };
+ };
+ var addon = new Y.mojito.addons.ac.url({}, null, acMock);
+ addon.setStore({
+ getRoutes: function() { return 'routes'; }
+ });
+
+ url = addon.make('myid', 'myaction', ['foo', 'bar'], 'get', ['a', 'b']);
+ A.areSame('ohhai url', url);
}
};
Something went wrong with that request. Please try again.