Permalink
Browse files

id treatment for URLs added - not definitive

  • Loading branch information...
1 parent 2a465ce commit 8097c107628fc1c1ec5856e4f45b79511797aa0f @felipero committed Apr 21, 2009
Showing with 24 additions and 6 deletions.
  1. +12 −4 src/ioke/ikido.ik
  2. +12 −2 test/ikido_spec.ik
View
@@ -15,15 +15,23 @@ Ikido dispatch = method(path,
)
),
use("../../test/_controllers/#{pathInfo[:controller]}_controller.ik")
-
result = {status: 200, headers: {contentType:"text/html"}, content:"The correct content from simple controller"}
)
result
)
Ikido treatPath = method(path,
- controller = path split("/")[0]
- action = path split("/")[1]
- {controller: controller, action: action}
+
+ pathParts = path split("/")
+
+ controller = pathParts[0]
+ action = pathParts[1]
+ routes = {controller: controller, action: action}
+
+ if(pathParts length > 2,
+ routes[:id] = pathParts[2]
+ )
+
+ routes
)
View
@@ -65,11 +65,21 @@ describe("Ikido",
describe("result for a valid path",
it("should have the correct controller",
- Ikido treatPath("/my/action") [:controller] should be == "my"
+ Ikido treatPath("/my/action") [:controller] should == "my"
)
it("should have the correct action",
- Ikido treatPath("/my/action")[:action] should be == "action"
+ Ikido treatPath("/my/action")[:action] should == "action"
+ )
+
+ it("should have the correct id",
+ Ikido treatPath("/my/action/foo")[:id] should == "foo"
+ Ikido treatPath("/my/action/3")[:id] should be == 3
+ )
+
+ it("should have the right size of elements",
+ Ikido treatPath("/my/action") size should == 2
+ Ikido treatPath("/my/action/3") size should == 3
)
)
)

0 comments on commit 8097c10

Please sign in to comment.