Skip to content

Commit

Permalink
Added restful post request tests. Had to stringify param values for s…
Browse files Browse the repository at this point in the history
…ome reason
  • Loading branch information
gus committed Jun 2, 2010
1 parent 8231c6d commit 3b8c23d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/riot/action_controller/http_methods.rb
Expand Up @@ -12,6 +12,7 @@ def delete(uri, params={}); raise Exception, "DELETE isn't ready yet"; end
private
def perform_request(request_method, uri, params)
http_reset
params = params.inject({}) { |acc,(key,val)| acc[key] = val.to_s; acc }

This comment has been minimized.

Copy link
@onedesign

onedesign Jul 18, 2010

Hey buddy! It seems like this line prevents you from using nested params in your tests. i.e. the following will fail:

 put "/admin/sites/#{a_site.identifier}", { :site => { :name => 'Hey Gabba Gabba' } }

because params will be squashed to:

 { :site => "name" }

What's the deal with this line, anyway? I wasn't sure why it existed.

Cheers,
Dan.

This comment has been minimized.

Copy link
@gus

gus Jul 18, 2010

Author Member

Seems like I was trying to to_s all the values which must have been necessary for something. Boogers.

@env = ::Rack::MockRequest.env_for(uri, {:params => params, :method => request_method})
@env['action_dispatch.show_exceptions'] = false
@app.call(@env)
Expand Down
25 changes: 25 additions & 0 deletions test/action_controller/restful_post_request_test.rb
@@ -0,0 +1,25 @@
require 'teststrap'

context "RESTful POST request on resource" do

context GremlinsController do
setup { post("/gremlins", :id => 2) }

asserts("request method") { request.request_method }.equals(:post)
asserts("controller name") { controller.controller_name }.equals("gremlins")
asserts("action name") { controller.action_name }.equals("create")
asserts("id param") { controller.params["id"] }.equals("2")
asserts("response body") { response.body }.equals("makin' money")
end # on a top level resource

context PartiesController do
setup { post("/gremlins/2/parties", "id" => 3) }

asserts("request method") { request.request_method }.equals(:post)
asserts("controller name") { controller.controller_name }.equals("parties")
asserts("action name") { controller.action_name }.equals("create")
asserts("gremlin_id param") { controller.params["gremlin_id"] }.equals("2")
asserts("id param") { controller.params["id"] }.equals("3")
asserts("response body") { response.body }.equals("give this monkey what he wants")
end # on a nested resource
end # RESTful POST request
4 changes: 4 additions & 0 deletions test/rails_root/app/controllers/gremlins_controller.rb
Expand Up @@ -6,4 +6,8 @@ def index
def show
render :text => "show me the money"
end

def create
render :text => "makin' money"
end
end
5 changes: 5 additions & 0 deletions test/rails_root/app/controllers/parties_controller.rb
Expand Up @@ -2,4 +2,9 @@ class PartiesController < ActionController::Base
def show
render :text => "woot"
end

def create
puts params.inspect
render :text => "give this monkey what he wants"
end
end

0 comments on commit 3b8c23d

Please sign in to comment.