Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added restful post request tests. Had to stringify param values for s…
…ome reason
- Loading branch information
Showing
4 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
gus
Author
Member
|
||
@env = ::Rack::MockRequest.env_for(uri, {:params => params, :method => request_method}) | ||
@env['action_dispatch.show_exceptions'] = false | ||
@app.call(@env) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,8 @@ def index | |
def show | ||
render :text => "show me the money" | ||
end | ||
|
||
def create | ||
render :text => "makin' money" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hey buddy! It seems like this line prevents you from using nested params in your tests. i.e. the following will fail:
because params will be squashed to:
What's the deal with this line, anyway? I wasn't sure why it existed.
Cheers,
Dan.