Permalink
Browse files

Added treatment to existent controllers but non existent actions & ad…

…ded the render method for controllers

& call the real action method to render content
  • Loading branch information...
felipero committed Apr 21, 2009
1 parent edf8f79 commit 2fdf8ac4cc938bdf875fc16d7f01d48575afa89e
Showing with 57 additions and 12 deletions.
  1. +1 −1 build.xml
  2. +5 −1 src/ioke/controller.ik
  3. +15 −2 src/ioke/ikido.ik
  4. +15 −8 test/_controllers/simple_controller.ik
  5. +21 −0 test/ikido_spec.ik
View
@@ -12,7 +12,7 @@
<fileset dir="${lib.dir}" includes="*.jar"/>
</path>
- <target name="prepare" description="Creates the directories needed for building">
+ <target name="prepare" depends="clean" description="Creates the directories needed for building">
<mkdir dir="${build.dir}"/>
<mkdir dir="${classes.dir}"/>
</target>
View
@@ -1 +1,5 @@
-Controller = Origin mimic
+Controller = Origin mimic
+
+Controller render = method(text,
+ text
+)
View
@@ -11,13 +11,26 @@ Ikido dispatch = method(path,
result = Dict mimic
bind(
- rescue(Condition Error Load,
+ rescue(Condition Error Load, Condition Error NoSuchCell,
fn(c,
result = {status: 404, headers:{contentType:"text/html"}, content:"404: Resource not found."}
)
),
use(self basePath + "controllers/#{pathInfo[:controller]}_controller.ik")
- result = {status: 200, headers: {contentType:"text/html"}, content:"The correct content from simple controller"}
+; use("#{self basePath}controllers/#{pathInfo[:controller]}_controller.ik")
+
+ controller = self cell(pathInfo[:controller]) mimic
+
+ unless(controller cell?(pathInfo[:action]),
+ error!(Condition Error NoSuchCell)
+ )
+
+ unless(controller cell(pathInfo[:action]) kind == "DefaultMethod",
+ error!(Condition Error NoSuchCell)
+ )
+
+ content = Message fromText(pathInfo[:action]) sendTo(controller)
+ result = {status: 200, headers: {contentType:"text/html"}, content: content}
)
result
@@ -1,9 +1,16 @@
-Ikido SimpleController = Controller mimic do (
- foo = method(
- render("foo")
- )
-
- bar = method(
- render("bar")
- )
+Ikido simple = Controller mimic do (
+
+ notActivatableCell = "someValue"
+
+ action = method(
+ render("The correct content from simple controller")
+ )
+
+ foo = method(
+ render("This is the foo content")
+ )
+
+ bar = method(
+ "This is the bar content without the render method"
+ )
)
View
@@ -52,6 +52,7 @@ describe("Ikido",
Ikido dispatch("/nonExistent/action")[:content] should == "404: Resource not found."
)
)
+
describe("result's values for existent action/controller",
ikido = Ikido mimic
ikido basePath = "../../test/_"
@@ -66,6 +67,26 @@ describe("Ikido",
it("should have the correct content",
ikido dispatch("/simple/action")[:content] should == "The correct content from simple controller"
+ ikido dispatch("/simple/foo")[:content] should == "This is the foo content"
+ ikido dispatch("/simple/bar")[:content] should == "This is the bar content without the render method"
+ )
+ )
+
+ describe("result's values for existent controller but non existent action",
+ ikido = Ikido mimic
+ ikido basePath = "../../test/_"
+ it("should have a status 404",
+ ikido dispatch("/simple/nonAction")[:status] should == 404
+ ikido dispatch("/simple/notActivatableCell")[:status] should == 404
+ )
+
+ it("should have the correct headers",
+ headers = ikido dispatch("/simple/notAAction")[:headers]
+ headers[:contentType] should == "text/html"
+ )
+
+ it("should have the correct content",
+ ikido dispatch("/simple/nonExistentAction")[:content] should == "404: Resource not found."
)
)
)

0 comments on commit 2fdf8ac

Please sign in to comment.