Permalink
Browse files

Built out PUT support

  • Loading branch information...
1 parent 3b8c23d commit 10481709ee794f45f5142b436c6dcf22d9c173a7 @gus gus committed Jun 3, 2010
@@ -6,8 +6,8 @@ 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 put(uri, params={}); perform_request("PUT", 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
private
def perform_request(request_method, uri, params)
@@ -15,7 +15,7 @@
asserts("request method") { request.request_method }.equals(:post)
asserts("action name") { action_name }.equals("create")
asserts("response status") { response.status }.equals(200)
- asserts("response body") { response.body }.equals { "created bar #{controller.params.inspect}" }
+ asserts("response body") { response.body }.equals { "created #{controller.params.inspect}" }
context "response headers" do
setup { response.headers.keys }
@@ -33,7 +33,7 @@
asserts("response status") { response.status }.equals(200)
asserts("response body") { response.body }.equals do
- "created bar #{controller.params.inspect}"
+ "created #{controller.params.inspect}"
end
asserts("params") { controller.params }.includes("momma")
@@ -0,0 +1,45 @@
+require 'teststrap'
+
+context RoomsController do
+
+ asserts("PUTs unknown action for existing controller") do
+ put "/rooms/blah"
+ end.raises(AbstractController::ActionNotFound, "The action 'blah' could not be found")
+
+ context "for a PUT request" do
+ helper(:action_name) { env['action_dispatch.request.path_parameters'][:action] }
+
+ context "without parameters" do
+ setup { put "/rooms/update" }
+
+ asserts("request method") { request.request_method }.equals(:put)
+ asserts("action name") { action_name }.equals("update")
+ asserts("response status") { response.status }.equals(200)
+ asserts("response body") { response.body }.equals { "updated #{controller.params.inspect}" }
+
+ context "response headers" do
+ setup { response.headers.keys }
+ asserts_topic.includes("Content-Type")
+ asserts_topic.includes("ETag")
+ asserts_topic.includes("Cache-Control")
+ end # response headers
+ end # without parameters
+
+ context "with parameters" do
+ setup { put "/rooms/update", {:momma => "loves you", "love_you_too" => "mom"} }
+
+ asserts("request method") { request.request_method }.equals(:put)
+ asserts("action name") { action_name }.equals("update")
+ asserts("response status") { response.status }.equals(200)
+
+ asserts("response body") { response.body }.equals do
+ "updated #{controller.params.inspect}"
+ end
+
+ asserts("params") { controller.params }.includes("momma")
+ asserts("params") { controller.params }.includes("love_you_too")
+ end # with parameters
+
+ end # for a PUT request
+
+end # RoomsController
@@ -0,0 +1,28 @@
+require 'teststrap'
+
+context "RESTful PUT request on resource" do
+
+ context GremlinsController do
+ setup { put("/gremlins/2") }
+
+ asserts("request method") { request.request_method }.equals(:put)
+ asserts("controller name") { controller.controller_name }.equals("gremlins")
+ asserts("action name") { controller.action_name }.equals("update")
+ asserts("id param") { controller.params["id"] }.equals("2")
+ asserts("response body") { response.body }.equals("savin' money")
+ end # on a top level resource
+
+ context PartiesController do
+ setup { put("/gremlins/2/parties/3", "foo" => "bar") }
+
+ asserts("request method") { request.request_method }.equals(:put)
+ asserts("controller name") { controller.controller_name }.equals("parties")
+ asserts("action name") { controller.action_name }.equals("update")
+
+ asserts("gremlin_id param") { controller.params["gremlin_id"] }.equals("2")
+ asserts("id param") { controller.params["id"] }.equals("3")
+ asserts("foo param") { controller.params["foo"] }.equals("bar")
+
+ asserts("response body") { response.body }.equals("i'll put that over here")
+ end # on a nested resource
+end # RESTful PUT request
@@ -10,4 +10,8 @@ def show
def create
render :text => "makin' money"
end
+
+ def update
+ render :text => "savin' money"
+ end
end
@@ -4,7 +4,10 @@ def show
end
def create
- puts params.inspect
render :text => "give this monkey what he wants"
end
+
+ def update
+ render :text => "i'll put that over here"
+ end
end
@@ -4,7 +4,11 @@ def index
end
def create
- render :text => "created bar #{params.inspect}"
+ render :text => "created #{params.inspect}"
+ end
+
+ def update
+ render :text => "updated #{params.inspect}"
end
def echo_params

0 comments on commit 1048170

Please sign in to comment.