Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
avoid warning when urlParams is empty/null. fixing functional tests f…
Browse files Browse the repository at this point in the history
…or routing.
  • Loading branch information
caridy committed Dec 11, 2012
1 parent 5c05679 commit c9a3c22
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 45 deletions.
20 changes: 11 additions & 9 deletions lib/app/addons/ac/url.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,19 @@ YUI.add('mojito-url-addon', function(Y, NAME) {

params = Y.merge(routeParams || {});

if (urlParams && 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];
if (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);
}
} else {
Y.log('ac.url.make is expecting an object as urlParams instead of: ' + urlParams, 'warn', NAME);
}

url = this.getRouteMaker().make(query, verb, params);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -23,67 +23,71 @@ YUI.add('ShowUrl', function(Y, NAME) {
* @param ac {Object} The action context that provides access
* to the Mojito API.
*/
index: function(ac) {
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'),
mojitVerb = (ac.params.getFromUrl('mojit_verb') || 'get').toLowerCase(),
nameExists = mojitName ? "YES" : "NO",
actionExists = mojitAction ? "YES" : "NO";
urlparamsExists = mojitUrlParams ? "YES" : "NO";
urlExists = mojitUrl ? "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);

if (nameExists === "YES" && actionExists === "YES")
{
var url = "";
var error = "";
try{
if (urlparamsExists === "YES"){
url = ac.url.make(mojitName, mojitAction, 'MySpecialRoute', 'GET', mojitUrlParams);
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(error) {
url = error;
} catch (err1) {
url = err1;
}
var data = {
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{
} else if (urlExists === "YES") {
matchroute = "";
try {
matchroute = ac.url.find(mojitUrl, mojitVerb);
}catch(error) {
url = error;
} catch (err2) {
url = err2;
}
console.log(matchroute);
if(matchroute != null){
var data = {
if (matchroute !== null) {
data = {
url: mojitUrl,
verbs: matchroute.verbs.GET,
call: matchroute.call,
name: matchroute.name,
params: matchroute.params.secret,
}
}else{
var data = {
url: mojitUrl,
}
params: matchroute.params.secret
};
} else {
data = {
url: mojitUrl
};
}
ac.done(data);
}
}
}
};

Expand Down
10 changes: 5 additions & 5 deletions tests/func/routing/testbasicrouting10-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("error:%20No%20route%20match%20found%20for%20'route-2.nothing'%20(get)", Y.one('#mylink').get('href'), 'invalid routes should trigger an error');
Y.Assert.areEqual('route-2', Y.one('#name').get('innerHTML'));
}
}));
}));

Y.Test.Runner.add(suite);
});

0 comments on commit c9a3c22

Please sign in to comment.