Skip to content
Browse files

Built out GET tests on nested resources

  • Loading branch information...
1 parent d8a57ce commit 8231c6d167d529a2b8e56feb121f046963364fa4 @gus gus committed Jun 2, 2010
View
10 lib/riot/action_controller/http_methods.rb
@@ -4,14 +4,8 @@ class ControllerMismatch < Exception; end
module HttpMethods
def http_reset; @env = {}; end
-
- def get(uri, params={})
- perform_request("GET", uri, params)
- end
-
- def post(uri, params={})
- perform_request("POST", uri, params)
- end
+ def get(uri, params={}) perform_request("GET", uri, params); end
+ def post(uri, params={}) perform_request("POST", uri, params); end
def put(uri, params={}); raise Exception, "PUT isn't ready yet"; end
def delete(uri, params={}); raise Exception, "DELETE isn't ready yet"; end
View
16 test/action_controller/get_with_nested_resource_test.rb
@@ -1,16 +0,0 @@
-require 'teststrap'
-
-context "GET request for a nested RESTful resource" do
- setup do
- situation = Riot::Situation.new
- context = Riot::Context.new(PartiesController) {}
- context.asserts("stuff") { get("/gremlins/1/parties/2") }
- context.local_run(Riot::SilentReporter.new, situation)
- situation
- end
-
- asserts("parameters inferred from the URL") do
- topic.request.params
- end.equals({ "controller" => "parties", "action" => "show", "gremlin_id" => "1", "id" => "2" })
-
-end
View
23 test/action_controller/restful_get_request_test.rb
@@ -0,0 +1,23 @@
+require 'teststrap'
+
+context "RESTful GET request on resource" do
+
+ context GremlinsController do
+ setup { get("/gremlins/1") }
+
+ asserts("controller name") { controller.controller_name }.equals("gremlins")
+ asserts("action name") { controller.action_name }.equals("show")
+ asserts("id param") { controller.params["id"] }.equals("1")
+ asserts("response body") { response.body }.equals("show me the money")
+ end # on a top level resource
+
+ context PartiesController do
+ setup { get("/gremlins/1/parties/2") }
+
+ asserts("controller name") { controller.controller_name }.equals("parties")
+ asserts("action name") { controller.action_name }.equals("show")
+ asserts("gremlin_id param") { controller.params["gremlin_id"] }.equals("1")
+ asserts("id param") { controller.params["id"] }.equals("2")
+ asserts("response body") { response.body }.equals("woot")
+ end # on a nested resource
+end # RESTful GET request
View
8 test/rails_root/app/controllers/gremlins_controller.rb
@@ -1,3 +1,9 @@
class GremlinsController < ActionController::Base
- def index; render :text => "bar"; end
+ def index
+ render :text => "bar"
+ end
+
+ def show
+ render :text => "show me the money"
+ end
end

0 comments on commit 8231c6d

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