Skip to content

Commit

Permalink
You can now use request_to with a post body:
Browse files Browse the repository at this point in the history
e.g. request_to("/", :post, {:post_body => 'deferred'})
In r.match('/').defer_to { |request, params| }, request.raw_post will equal 'deferred'.
Useful for testing complex routes.

Signed-off-by: Michael S. Klishin <michael@novemberain.com>
  • Loading branch information
mlangenberg authored and michaelklishin committed Sep 13, 2008
1 parent 644ab28 commit 79f233a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/merb-core/test/helpers/route_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def request_to(path, method = :get, env = {})
env[:request_method] ||= method.to_s.upcase
env[:request_uri] = path

check_request_for_route(fake_request(env))
check_request_for_route(build_request({}, env))
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/public/test/route_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def post; end
describe Merb::Test::RouteHelper do
before(:each) do
Merb::Router.prepare do |r|
r.match("/").defer_to do |request, params|
{ :controller => 'test_controller', :action => request.raw_post } unless request.raw_post.blank?
end
r.match("/", :method => :get).to(:controller => "test_controller", :action => "get").name(:getter)
r.match("/", :method => :post).to(:controller => "test_controller", :action => "post")
r.match("/:id").to(:controller => "test_controller", :action => "get").name(:with_id)
Expand Down Expand Up @@ -67,5 +70,9 @@ def post; end
it "should contain any parameters in the result" do
request_to("/123")[:id].should == "123"
end

it "should play nice with raw_post in deferred routing" do
request_to("/", :post, {:post_body => 'deferred'})[:action].should == 'deferred'
end
end
end

0 comments on commit 79f233a

Please sign in to comment.