Created
December 25, 2008 17:52
-
-
Save lifo/39926 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb | |
index dddad17..acfb10c 100644 | |
--- a/actionpack/lib/action_controller/test_process.rb | |
+++ b/actionpack/lib/action_controller/test_process.rb | |
@@ -388,20 +388,33 @@ module ActionController #:nodoc: | |
module TestProcess | |
def self.included(base) | |
- # execute the request simulating a specific HTTP method and set/volley the response | |
- # TODO: this should be un-DRY'ed for the sake of API documentation. | |
- %w( get post put delete head ).each do |method| | |
- base.class_eval <<-EOV, __FILE__, __LINE__ | |
- def #{method}(action, parameters = nil, session = nil, flash = nil) | |
- @request.env['REQUEST_METHOD'] = "#{method.upcase}" if defined?(@request) | |
- process(action, parameters, session, flash) | |
- end | |
- EOV | |
+ # Executes a request simulating GET HTTP method and set/volley the response | |
+ def get(action, parameters = nil, session = nil, flash = nil) | |
+ process(action, parameters, session, flash, "GET") | |
+ end | |
+ | |
+ # Executes a request simulating POST HTTP method and set/volley the response | |
+ def post(action, parameters = nil, session = nil, flash = nil) | |
+ process(action, parameters, session, flash, "POST") | |
+ end | |
+ | |
+ # Executes a request simulating PUT HTTP method and set/volley the response | |
+ def put(action, parameters = nil, session = nil, flash = nil) | |
+ process(action, parameters, session, flash, "PUT") | |
+ end | |
+ | |
+ # Executes a request simulating DELETE HTTP method and set/volley the response | |
+ def delete(action, parameters = nil, session = nil, flash = nil) | |
+ process(action, parameters, session, flash, "DELETE") | |
+ end | |
+ | |
+ # Executes a request simulating HEAD HTTP method and set/volley the response | |
+ def head(action, parameters = nil, session = nil, flash = nil) | |
+ process(action, parameters, session, flash, "HEAD") | |
end | |
end | |
- # execute the request and set/volley the response | |
- def process(action, parameters = nil, session = nil, flash = nil) | |
+ def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET') | |
# Sanity check for required instance variables so we can give an | |
# understandable error message. | |
%w(@controller @request @response).each do |iv_name| | |
@@ -414,7 +427,7 @@ module ActionController #:nodoc: | |
@response.recycle! | |
@html_document = nil | |
- @request.env['REQUEST_METHOD'] ||= "GET" | |
+ @request.env['REQUEST_METHOD'] = http_method | |
@request.action = action.to_s | |
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb | |
index e24bb00..7f8e47b 100644 | |
--- a/actionpack/test/controller/caching_test.rb | |
+++ b/actionpack/test/controller/caching_test.rb | |
@@ -121,8 +121,7 @@ class PageCachingTest < ActionController::TestCase | |
[:get, :post, :put, :delete].each do |method| | |
unless method == :get and status == :ok | |
define_method "test_shouldnt_cache_#{method}_with_#{status}_status" do | |
- @request.env['REQUEST_METHOD'] = method.to_s.upcase | |
- process status | |
+ send(method, status) | |
assert_response status | |
assert_page_not_cached status, "#{method} with #{status} status shouldn't have been cached" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment