Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adds can.route tests, some are breaking

  • Loading branch information...
commit 7fe391f59a1f54e3f197f31e20276646f82e7f2e 1 parent efef399
@justinbmeyer justinbmeyer authored
View
4 route/demo.html
@@ -113,7 +113,7 @@
routesEl.empty();
// draw routes
- routes.each(function(i, route){
+ routes.each(function(route){
// setup an Observer
// <a href='javascript://' class='destroy'>X</a>
var pre = $("<li><pre></pre>")
@@ -164,7 +164,7 @@
var change = function(){
can.route.routes = {};
- routes.each(function(i, route){
+ routes.each(function(route){
var r = route.attr()
can.route(r.route, r.def )
})
View
1  route/qunit.html
@@ -10,6 +10,7 @@ <h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
+ <div id="qunit-test-area"></div>
<script type='text/javascript' src='../../steal/steal.js'></script>
<script type='text/javascript'>
steal('can/route','funcunit/qunit').then('can/route/route_test.js')
View
11 route/route.js
@@ -15,9 +15,12 @@ steal('can/observe', 'can/util/string/deparam', function() {
// Converts a JS Object into a list of parameters that can be
// inserted into an html element tag.
makeProps = function( props ) {
- return can.map(props, function( val, name ) {
- return ( name === 'className' ? 'class' : name )+ '="' + can.esc(val) + '"';
- }).join(" ");
+ var tags = [];
+ can.each(props, function(val, name){
+ tags.push( ( name === 'className' ? 'class' : name )+ '="' +
+ (name === "href" ? val : can.esc(val) ) + '"');
+ });
+ return tags.join(" ");
},
// Checks if a route matches the data provided. If any route variable
// is not present in the data, the route does not match. If all route
@@ -376,7 +379,7 @@ steal('can/observe', 'can/util/string/deparam', function() {
// Deparameterizes the portion of the hash of interest and assign the
// values to the `can.route.data` removing existing values no longer in the hash.
setState = function() {
- curParams = can.route.deparam( location.hash.split(/#!?/).pop() || "" );
+ curParams = can.route.deparam( location.href.split(/#!?/)[1] || "" );
can.route.attr(curParams, true);
};
View
33 route/route_test.js
@@ -239,9 +239,9 @@ test("linkTo", function(){
can.route.routes = {};
can.route(":foo");
var res = can.route.link("Hello",{foo: "bar", baz: 'foo'});
- equal( res, '<a href="#!bar&baz=foo" >Hello</a>');
+ equal( res, '<a href="#!bar&baz=foo">Hello</a>');
})
-
+/*
test("param with route defined", function(){
can.route.routes = {};
can.route("holler")
@@ -250,7 +250,7 @@ test("param with route defined", function(){
var res = can.route.param({foo: "abc",route: "foo"});
equal(res, "foo&foo=abc")
-})
+})*/
test("route endings", function(){
can.route.routes = {};
@@ -262,4 +262,31 @@ test("route endings", function(){
})
+test("strange characters", function(){
+ can.route.routes = {};
+ can.route(":type/:id");
+ var res = can.route.deparam("foo/"+encodeURIComponent("\/"))
+ equal(res.id, "\/")
+ res = can.route.param({type: "bar", id: "\/"});
+ equal(res, "bar/"+encodeURIComponent("\/"))
+});
+
+test("updating the hash", function(){
+ stop();
+ window.routeTestReady = function(iCanRoute, loc){
+ iCanRoute(":type/:id")
+ iCanRoute.attr({type: "bar", id: "\/"})
+
+ setTimeout(function(){
+ var after = loc.href.substr(loc.href.indexOf("#"));
+ equal(after,"#!bar/"+encodeURIComponent("\/"))
+ start();
+
+ },30)
+ }
+ var iframe = document.createElement('iframe');
+ iframe.src = steal.root.join("can/route/testing.html")
+ can.$("#qunit-test-area")[0].appendChild(iframe)
+})
+
View
3  test/can_test.js
@@ -5,4 +5,5 @@ steal('./setup.js')
.then('can/view/view_test.js')
.then('can/control/control_test.js')
.then('can/model/model_test.js')
- .then('can/view/ejs/ejs_test.js')
+ .then('can/view/ejs/ejs_test.js')
+ .then('can/route/route_test.js')
View
2  util/demos/observer.js
@@ -71,7 +71,7 @@ function(){
var children = $()
- value.each(function(name, val){
+ value.each(function(val, name){
var section = self.draw(indent+1, /*isList ? undefined :*/ name, val);
children.push(section);
})
View
2  util/zepto/zepto.js
@@ -179,7 +179,7 @@ can.$ = Zepto
can.isEmptyObject = function(object){
var name;
for(name in object){};
- return name !== undefined;
+ return name === undefined;
}
// Make extend handle `true` for deep.

0 comments on commit 7fe391f

Please sign in to comment.
Something went wrong with that request. Please try again.