Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: caridy/mojito
...
head fork: caridy/mojito
  • 18 commits
  • 17 files changed
  • 0 commit comments
  • 4 contributors
Commits on Dec 06, 2012
lzhan lzhan mojito start output version of mojito being run f921610
lzhan lzhan use node require f405df5
lzhan lzhan rm unused var e55464d
lzhan lzhan rm static referece of mojito version 39cb005
Commits on Dec 10, 2012
lzhan lzhan minor correction 2a4e051
Commits on Dec 11, 2012
Caridy Patiño adjusting ac.url.make routine to avoid accepting strings for querystr…
…ing. avoiding any parsing or stringifing routine at make, instead letting the route maker to deal with that. fixing all unit tests.
5c05679
lzhan lzhan use path.join for json file path df7be82
Caridy Patiño avoid warning when urlParams is empty/null. fixing functional tests f…
…or routing.
c9a3c22
Caridy Patiño Merge branch 'develop' of github.com:yahoo/mojito into micro-tunning 9619f96
Commits on Dec 12, 2012
Caridy Patiño addressing review notes from @folta 95875cb
Caridy Patiño Merge branch 'develop' of github.com:yahoo/mojito into micro-tunning eaea7a1
Caridy Patiño delinting 45f0095
Caridy Patiño Merge pull request #854 from caridy/micro-tunning
fix for ac.url.make weird behavior after micro-optmiziation
7c48652
Commits on Dec 13, 2012
Drew Folta drewfish don't set instance.base=null, since needed by client-side 23224be
Drew Folta drewfish Merge pull request #856 from drewfish/base-null
don't set instance.base=null, since needed by client-side
d6e36e0
Drew Folta drewfish remove console.log from unit tests f6b4a62
Drew Folta drewfish Merge pull request #857 from drewfish/unit-console
remove console.log from unit tests
d81aeb9
lzhan lzhan Merge pull request #840 from lzhan/mostart
mojito start output version of mojito being run
795787a
73 lib/app/addons/ac/url.common.js
View
@@ -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?
+ 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'
]});
1  lib/app/autoload/mojito.common.js
View
@@ -11,7 +11,6 @@
YUI.add('mojito', function(Y, NAME) {
- Y.namespace('mojito').version = '0.2';
Y.namespace('mojito.trans');
Y.namespace('mojito.actions');
Y.namespace('mojito.binders');
11 lib/app/autoload/route-maker.common.js
View
@@ -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';
2  lib/app/autoload/store.server.js
View
@@ -546,8 +546,6 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
instance.instanceId = Y.guid();
//DEBUGGING: instance.instanceId += '-instance-server-' + [instance.base||'', instance.type||''].join('-');
}
- // otherwise this'll show up in the returned instance
- instance.base = null;
// spec
try {
3  lib/app/commands/start.js
View
@@ -10,6 +10,7 @@
var path = require('path'),
utils = require(path.join(__dirname, '../../management/utils')),
Mojito = require(path.join(__dirname, '../../mojito')),
+ mojitoVersion = require(path.join(__dirname, '../../../package.json')).version,
fs = require('fs');
@@ -95,7 +96,7 @@ exports.run = function(params, opts, callback) {
return;
}
console.log('\n');
- utils.success('\tMojito started' +
+ utils.success('\tMojito(v' + mojitoVersion + ') started' +
(pack.name ? ' \'' + pack.name + '\'' : '') +
' on http://127.0.0.1:' + options.port + '/\n');
});
2  lib/app/mojits/HTMLFrameMojit/controller.server.js
View
@@ -88,7 +88,7 @@ YUI.add('HTMLFrameMojit', function(Y, NAME) {
// Set the default data
data.title = ac.config.get('title') ||
- 'Powered by Mojito ' + Y.mojito.version;
+ 'Powered by Mojito';
data.mojito_version = Y.mojito.version;
// Add all the assets we have been given to our local store
4 tests/fixtures/gsg5-appConfig/mojits/PagedFlickr/controller.common.js
View
@@ -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']});
4 tests/fixtures/gsg5/mojits/PagedFlickr/controller.common.iphone.js
View
@@ -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']});
3  tests/fixtures/gsg5/mojits/PagedFlickr/controller.common.js
View
@@ -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']});
124 tests/func/applications/frameworkapp/routing/mojits/ShowUrl/controller.server.js
View
@@ -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: [
6 tests/func/applications/frameworkapp/usecase/mojits/PagedFlickr/controller.common.js
View
@@ -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);
}
2  tests/func/applications/frameworkapp/usecase/mojits/PagedFlickr2/controller.common.js
View
@@ -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);
}
3  tests/func/applications/frameworkapp/usecase/mojits/PagedFlickr5/controller.common.js
View
@@ -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']});
4 tests/func/common/html5apptest_descriptor.json
View
@@ -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"
}
}
- }
+ }
},
{
4 tests/func/routing/routingtest_descriptor.json
View
@@ -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"
}
}
- }
+ }
},
{
10 tests/func/routing/testbasicrouting10-1.js
View
@@ -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);
});
195 tests/unit/lib/app/addons/ac/test-url.common.js
View
@@ -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,112 @@ 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) {
+ 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);
}
};

No commit comments for this range

Something went wrong with that request. Please try again.