From a544d7aa372a080b77940571a3a169496045670e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 7 Dec 2004 11:10:46 +0000 Subject: Added all the HTTP methods as alternatives to the generic "process" for functional testing #276 [Tobias Luetke] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@58 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../test/controller/action_pack_assertions_test.rb | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'actionpack/test/controller/action_pack_assertions_test.rb') diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 6d727be5a2..489373d5c3 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -54,6 +54,18 @@ class ActionPackAssertionsController < ActionController::Base session['xmas'] = 'turkey' render_text "ho ho ho" end + + # raises exception on get requests + def raise_on_get + raise "get" if @request.get? + render_text "request method: #{@request.env['REQUEST_METHOD']}" + end + + # raises exception on post requests + def raise_on_post + raise "post" if @request.post? + render_text "request method: #{@request.env['REQUEST_METHOD']}" + end # 911 def rescue_action(e) raise; end @@ -70,7 +82,7 @@ ActionPackAssertionsController.template_root = File.dirname(__FILE__) + "/../fix # a test case to exercise the new capabilities TestRequest & TestResponse -class ActionPackAssertionsControllerTest < Test::Unit::TestCase +class ActionPackAssertionsControllerTest < Test::Unit::TestCase # let's get this party started def setup @controller = ActionPackAssertionsController.new @@ -85,6 +97,20 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase assert_session_has 'xmas' assert_session_has_no 'halloween' end + + # test the get method, make sure the request really was a get + def test_get + assert_raise(RuntimeError) { get :raise_on_get } + get :raise_on_post + assert_equal @response.body, 'request method: GET' + end + + # test the get method, make sure the request really was a get + def test_post + assert_raise(RuntimeError) { post :raise_on_post } + post :raise_on_get + assert_equal @response.body, 'request method: POST' + end # test the assertion of goodies in the template def test_assert_template_has -- cgit v1.2.3