Permalink
Browse files

Killed the out of place alias and made sure you can use the different…

… HTTP methods within the same testaction

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@80 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 4e1eaa2 commit c8d68dfed3c83f3b5c32dc58d797254b219744b9 @dhh dhh committed Dec 8, 2004
@@ -190,7 +190,7 @@ def delete() @attributes = {} end
class Test::Unit::TestCase #:nodoc:
private
# execute the request and set/volley the response
- def get(action, parameters = nil, session = nil)
+ def process(action, parameters = nil, session = nil)
@request.env['REQUEST_METHOD'] ||= "GET"
@request.action = action.to_s
@request.parameters.update(parameters) unless parameters.nil?
@@ -199,14 +199,13 @@ def get(action, parameters = nil, session = nil)
end
# execute the request simulating a specific http method and set/volley the response
- %w( post put delete head ).each do |method|
+ %w( get post put delete head ).each do |method|
class_eval <<-EOV
def #{method}(action, parameters = nil, session = nil)
- @request.env['REQUEST_METHOD'] ||= "#{method.upcase}"
- get(action, parameters, session)
+ @request.env['REQUEST_METHOD'] = "#{method.upcase}"
+ process(action, parameters, session)
end
-EOV
+ EOV
end
- alias :process :get
end
@@ -111,6 +111,18 @@ def test_post
post :raise_on_get
assert_equal @response.body, 'request method: POST'
end
+
+ # test the get/post switch within one test action
+ def test_get_post_switch
+ post :raise_on_get
+ assert_equal @response.body, 'request method: POST'
+ get :raise_on_post
+ assert_equal @response.body, 'request method: GET'
+ post :raise_on_get
+ assert_equal @response.body, 'request method: POST'
+ get :raise_on_post
+ assert_equal @response.body, 'request method: GET'
+ end
# test the assertion of goodies in the template
def test_assert_template_has

0 comments on commit c8d68df

Please sign in to comment.