Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Built out DELETE support

  • Loading branch information...
commit fba7c80a87a2207a6bf49ca00bb646a5d74fba86 1 parent 1048170
@gus gus authored
View
3  lib/riot/action_controller/http_methods.rb
@@ -7,8 +7,7 @@ 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 delete(uri, params={}); raise Exception, "DELETE isn't ready yet"; end
+ def delete(uri, params={}); perform_request("DELETE", uri, params); end
private
def perform_request(request_method, uri, params)
http_reset
View
45 test/action_controller/delete_request_test.rb
@@ -0,0 +1,45 @@
+require 'teststrap'
+
+context RoomsController do
+
+ asserts("DELETEs unknown action for existing controller") do
+ delete "/rooms/blah"
+ end.raises(AbstractController::ActionNotFound, "The action 'blah' could not be found")
+
+ context "for a DELETE request" do
+ helper(:action_name) { env['action_dispatch.request.path_parameters'][:action] }
+
+ context "without parameters" do
+ setup { delete "/rooms/destroy" }
+
+ asserts("request method") { request.request_method }.equals(:delete)
+ asserts("action name") { action_name }.equals("destroy")
+ asserts("response status") { response.status }.equals(200)
+ asserts("response body") { response.body }.equals { "destroyed #{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 { delete "/rooms/destroy", {:momma => "loves you", "love_you_too" => "mom"} }
+
+ asserts("request method") { request.request_method }.equals(:delete)
+ asserts("action name") { action_name }.equals("destroy")
+ asserts("response status") { response.status }.equals(200)
+
+ asserts("response body") { response.body }.equals do
+ "destroyed #{controller.params.inspect}"
+ end
+
+ asserts("params") { controller.params }.includes("momma")
+ asserts("params") { controller.params }.includes("love_you_too")
+ end # with parameters
+
+ end # for a DELETE request
+
+end # RoomsController
View
28 test/action_controller/restful_delete_request_test.rb
@@ -0,0 +1,28 @@
+require 'teststrap'
+
+context "RESTful DELETE request on resource" do
+
+ context GremlinsController do
+ setup { delete("/gremlins/2") }
+
+ asserts("request method") { request.request_method }.equals(:delete)
+ asserts("controller name") { controller.controller_name }.equals("gremlins")
+ asserts("action name") { controller.action_name }.equals("destroy")
+ asserts("id param") { controller.params["id"] }.equals("2")
+ asserts("response body") { response.body }.equals("spendin' money")
+ end # on a top level resource
+
+ context PartiesController do
+ setup { delete("/gremlins/2/parties/3", "foo" => "bar") }
+
+ asserts("request method") { request.request_method }.equals(:delete)
+ asserts("controller name") { controller.controller_name }.equals("parties")
+ asserts("action name") { controller.action_name }.equals("destroy")
+
+ 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("all gone")
+ end # on a nested resource
+end # RESTful DELETE request
View
4 test/rails_root/app/controllers/gremlins_controller.rb
@@ -14,4 +14,8 @@ def create
def update
render :text => "savin' money"
end
+
+ def destroy
+ render :text => "spendin' money"
+ end
end
View
4 test/rails_root/app/controllers/parties_controller.rb
@@ -10,4 +10,8 @@ def create
def update
render :text => "i'll put that over here"
end
+
+ def destroy
+ render :text => "all gone"
+ end
end
View
4 test/rails_root/app/controllers/rooms_controller.rb
@@ -11,6 +11,10 @@ def update
render :text => "updated #{params.inspect}"
end
+ def destroy
+ render :text => "destroyed #{params.inspect}"
+ end
+
def echo_params
serialized_params = (params.keys - ["action"]).sort.map {|k| "#{k}=#{params[k]}" }.join(",")
render :text => serialized_params
Please sign in to comment.
Something went wrong with that request. Please try again.