Created
November 19, 2009 02:06
-
-
Save lukesutton/238471 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
module("Router"); | |
var routes = Bongst.Router.setup(function(r) { | |
r.map("default", "/:controller/:id/:action"); | |
r.map("extra", "/admin/:action").to({jelly: "drop"}); | |
}); | |
test("Basic route", function() { | |
var match = routes.match("/users/1/edit"); | |
ok(match.controller === "users", "should match controller"); | |
ok(match.id === "1", "should match ID"); | |
ok(match.action === "edit", "should match action"); | |
}); | |
test("Extra params", function() { | |
var match = routes.match("/admin/spong"); | |
ok(match.jelly === "drop", "should inject extra params"); | |
ok(match.action === "spong", "should still match placeholders"); | |
}); | |
test("Path generation", function() { | |
var path = routes.path("default", {controller: "users", id: 20, action: "delete"}); | |
ok(path === "/users/20/delete", "should generate path"); | |
}); | |
test("Append route", function() { | |
routes.append(function(r) { | |
r.map("appended", "/append/route/:test/:id"); | |
}); | |
ok(routes.routes.length === 3, "Should append path"); | |
var match = routes.match("/append/route/now/20"); | |
console.log(match) | |
ok(match.test === "now", "should match :test"); | |
ok(match.id === "20", "should match :id"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment