From 3900f4007ee6463b8936af23c04017a900673866 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 2 May 2009 14:23:44 -0500 Subject: Deprecate assert_redirect_to's partial hash matching --- actionpack/test/controller/action_pack_assertions_test.rb | 8 +++++--- actionpack/test/controller/redirect_test.rb | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 711640f9a9..60957a2f0e 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -514,9 +514,11 @@ class ActionPackHeaderTest < ActionController::TestCase end def test_rendering_xml_respects_content_type - @response.headers['type'] = 'application/pdf' - process :hello_xml_world - assert_equal('application/pdf; charset=utf-8', @response.headers['Content-Type']) + pending do + @response.headers['type'] = 'application/pdf' + process :hello_xml_world + assert_equal('application/pdf; charset=utf-8', @response.headers['Content-Type']) + end end def test_render_text_with_custom_content_type diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index 91e21db854..9ad63a1c60 100644 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -234,8 +234,10 @@ class RedirectTest < ActionController::TestCase end def test_redirect_with_partial_params - get :module_redirect - assert_redirected_to :action => 'hello_world' + pending do + get :module_redirect + assert_redirected_to :action => 'hello_world' + end end def test_redirect_to_nil -- cgit v1.2.3 From a8b75c480fc9774252f5976dcf1a614079822e56 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 2 May 2009 14:57:40 -0500 Subject: Functional test runner finalizes response just like the integration test runner. In both runners, the @response object will now behave the same. Some functional tests will need to be updated if they are relying on preprocessed data on the response. --- actionpack/test/controller/cookie_test.rb | 17 ++++++++--------- actionpack/test/controller/render_test.rb | 22 +++++++++++----------- actionpack/test/controller/send_file_test.rb | 8 ++++---- actionpack/test/controller/test_test.rb | 4 +++- 4 files changed, 26 insertions(+), 25 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index c861982698..0f22714071 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -54,39 +54,38 @@ class CookieTest < ActionController::TestCase def test_setting_cookie get :authenticate - assert_equal ["user_name=david; path=/"], @response.headers["Set-Cookie"] + assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"] assert_equal({"user_name" => "david"}, @response.cookies) end def test_setting_with_escapable_characters get :set_with_with_escapable_characters - assert_equal ["that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/"], @response.headers["Set-Cookie"] + assert_equal "that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/", @response.headers["Set-Cookie"] assert_equal({"that & guy" => "foo & bar => baz"}, @response.cookies) end def test_setting_cookie_for_fourteen_days get :authenticate_for_fourteen_days - assert_equal ["user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"], @response.headers["Set-Cookie"] + assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", @response.headers["Set-Cookie"] assert_equal({"user_name" => "david"}, @response.cookies) end def test_setting_cookie_for_fourteen_days_with_symbols get :authenticate_for_fourteen_days_with_symbols - assert_equal ["user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"], @response.headers["Set-Cookie"] + assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", @response.headers["Set-Cookie"] assert_equal({"user_name" => "david"}, @response.cookies) end def test_setting_cookie_with_http_only get :authenticate_with_http_only - assert_equal ["user_name=david; path=/; HttpOnly"], @response.headers["Set-Cookie"] + assert_equal "user_name=david; path=/; HttpOnly", @response.headers["Set-Cookie"] assert_equal({"user_name" => "david"}, @response.cookies) end def test_multiple_cookies get :set_multiple_cookies assert_equal 2, @response.cookies.size - assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", @response.headers["Set-Cookie"][0] - assert_equal "login=XJ-122; path=/", @response.headers["Set-Cookie"][1] + assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT\nlogin=XJ-122; path=/", @response.headers["Set-Cookie"] assert_equal({"login" => "XJ-122", "user_name" => "david"}, @response.cookies) end @@ -96,7 +95,7 @@ class CookieTest < ActionController::TestCase def test_expiring_cookie get :logout - assert_equal ["user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"], @response.headers["Set-Cookie"] + assert_equal "user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT", @response.headers["Set-Cookie"] assert_equal({"user_name" => nil}, @response.cookies) end @@ -117,6 +116,6 @@ class CookieTest < ActionController::TestCase def test_delete_cookie_with_path get :delete_cookie_with_path - assert_equal ["user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT"], @response.headers["Set-Cookie"] + assert_equal "user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT", @response.headers["Set-Cookie"] end end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 023bf0eeaa..dd2dd7a502 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -1293,15 +1293,15 @@ class RenderTest < ActionController::TestCase def test_head_with_symbolic_status get :head_with_symbolic_status, :status => "ok" - assert_equal "200 OK", @response.status + assert_equal 200, @response.status assert_response :ok get :head_with_symbolic_status, :status => "not_found" - assert_equal "404 Not Found", @response.status + assert_equal 404, @response.status assert_response :not_found get :head_with_symbolic_status, :status => "no_content" - assert_equal "204 No Content", @response.status + assert_equal 204, @response.status assert !@response.headers.include?('Content-Length') assert_response :no_content @@ -1322,7 +1322,7 @@ class RenderTest < ActionController::TestCase def test_head_with_string_status get :head_with_string_status, :status => "404 Eat Dirt" assert_equal 404, @response.response_code - assert_equal "Eat Dirt", @response.message + assert_equal "Not Found", @response.message assert_response :not_found end @@ -1590,7 +1590,7 @@ class EtagRenderTest < ActionController::TestCase def test_render_against_etag_request_should_304_when_match @request.if_none_match = etag_for("hello david") get :render_hello_world_from_variable - assert_equal "304 Not Modified", @response.status + assert_equal 304, @response.status assert @response.body.empty? end @@ -1603,13 +1603,13 @@ class EtagRenderTest < ActionController::TestCase def test_render_against_etag_request_should_200_when_no_match @request.if_none_match = etag_for("hello somewhere else") get :render_hello_world_from_variable - assert_equal "200 OK", @response.status + assert_equal 200, @response.status assert !@response.body.empty? end def test_render_should_not_set_etag_when_last_modified_has_been_specified get :render_hello_world_with_last_modified_set - assert_equal "200 OK", @response.status + assert_equal 200, @response.status assert_not_nil @response.last_modified assert_nil @response.etag assert @response.body.present? @@ -1623,11 +1623,11 @@ class EtagRenderTest < ActionController::TestCase @request.if_none_match = expected_etag get :render_hello_world_from_variable - assert_equal "304 Not Modified", @response.status + assert_equal 304, @response.status @request.if_none_match = "\"diftag\"" get :render_hello_world_from_variable - assert_equal "200 OK", @response.status + assert_equal 200, @response.status end def render_with_404_shouldnt_have_etag @@ -1695,7 +1695,7 @@ class LastModifiedRenderTest < ActionController::TestCase def test_request_not_modified @request.if_modified_since = @last_modified get :conditional_hello - assert_equal "304 Not Modified", @response.status + assert_equal 304, @response.status assert @response.body.blank?, @response.body assert_equal @last_modified, @response.headers['Last-Modified'] end @@ -1710,7 +1710,7 @@ class LastModifiedRenderTest < ActionController::TestCase def test_request_modified @request.if_modified_since = 'Thu, 16 Jul 2008 00:00:00 GMT' get :conditional_hello - assert_equal "200 OK", @response.status + assert_equal 200, @response.status assert !@response.body.blank? assert_equal @last_modified, @response.headers['Last-Modified'] end diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index 2e14a0a32c..6007ebef7a 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -44,12 +44,12 @@ class SendFileTest < ActionController::TestCase response = nil assert_nothing_raised { response = process('file') } assert_not_nil response - assert_kind_of Proc, response.body_parts + assert_kind_of Array, response.body_parts require 'stringio' output = StringIO.new output.binmode - assert_nothing_raised { response.body_parts.call(response, output) } + assert_nothing_raised { response.body_parts.each { |part| output << part.to_s } } assert_equal file_data, output.string end @@ -149,13 +149,13 @@ class SendFileTest < ActionController::TestCase define_method "test_send_#{method}_status" do @controller.options = { :stream => false, :status => 500 } assert_nothing_raised { assert_not_nil process(method) } - assert_equal '500 Internal Server Error', @response.status + assert_equal 500, @response.status end define_method "test_default_send_#{method}_status" do @controller.options = { :stream => false } assert_nothing_raised { assert_not_nil process(method) } - assert_equal ActionController::DEFAULT_RENDER_STATUS_CODE, @response.status + assert_equal 200, @response.status end end end diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index 919f9815ec..9e88188b9a 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -614,7 +614,9 @@ XML def test_binary_content_works_with_send_file get :test_send_file - assert_nothing_raised(NoMethodError) { @response.binary_content } + assert_deprecated do + assert_nothing_raised(NoMethodError) { @response.binary_content } + end end protected -- cgit v1.2.3 From f32cf44870549c6cc5b6e6c84cffc1facf6ec38e Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 2 May 2009 15:29:18 -0500 Subject: Switch functional tests to run through the rack interface instead of process --- actionpack/test/controller/caching_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 10b904481d..6b9d1056a3 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -111,7 +111,7 @@ class PageCachingTest < ActionController::TestCase end def test_should_cache_ok_at_custom_path - @request.stubs(:path).returns("/index.html") + @request.request_uri = "/index.html" get :ok assert_response :ok assert File.exist?("#{FILE_STORE_PATH}/index.html") -- cgit v1.2.3 From 24affdc88c4a4af03ce1ec5b23c3def18b90effe Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 2 May 2009 15:37:29 -0500 Subject: Deprecate Controller.process interface --- actionpack/test/controller/filters_test.rb | 2 +- actionpack/test/controller/helper_test.rb | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 9e74538310..5876f55420 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -603,7 +603,7 @@ class FilterTest < Test::Unit::TestCase %w(foo bar baz).each do |action| request = ActionController::TestRequest.new request.query_parameters[:choose] = action - response = DynamicDispatchController.process(request, ActionController::TestResponse.new) + response = Rack::MockResponse.new(*DynamicDispatchController.call(request.env)) assert_equal action, response.body end end diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index 58addc123d..e72bce1791 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -102,19 +102,19 @@ class HelperTest < Test::Unit::TestCase end def test_helper_for_nested_controller - request = ActionController::TestRequest.new - response = ActionController::TestResponse.new + request = ActionController::TestRequest.new request.action = 'render_hello_world' - assert_equal 'hello: Iz guuut!', Fun::GamesController.process(request, response).body + response = Rack::MockResponse.new(*Fun::GamesController.call(request.env)) + assert_equal 'hello: Iz guuut!', response.body end def test_helper_for_acronym_controller - request = ActionController::TestRequest.new - response = ActionController::TestResponse.new + request = ActionController::TestRequest.new request.action = 'test' - assert_equal 'test: baz', Fun::PdfController.process(request, response).body + response = Rack::MockResponse.new(*Fun::PdfController.call(request.env)) + assert_equal 'test: baz', response.body end def test_all_helpers @@ -211,14 +211,16 @@ class IsolatedHelpersTest < Test::Unit::TestCase end def test_helper_in_a - assert_raise(ActionView::TemplateError) { A.process(@request, @response) } + assert_raise(ActionView::TemplateError) { A.call(@request.env) } end def test_helper_in_b - assert_equal 'B', B.process(@request, @response).body + response = Rack::MockResponse.new(*B.call(@request.env)) + assert_equal 'B', response.body end def test_helper_in_c - assert_equal 'C', C.process(@request, @response).body + response = Rack::MockResponse.new(*C.call(@request.env)) + assert_equal 'C', response.body end end -- cgit v1.2.3 From 11af089cee0a0e744e267d32becfe2c66a586d31 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 2 May 2009 23:02:22 -0500 Subject: Extract ActionController rescue templates into Rescue and ShowExceptions middleware. This commit breaks all exception catching plugins like ExceptionNotifier. These plugins should be rewritten as middleware instead overriding Controller#rescue_action_in_public. --- .../test/controller/action_pack_assertions_test.rb | 2 +- actionpack/test/controller/base_test.rb | 9 +- actionpack/test/controller/caching_test.rb | 3 + .../deprecation/deprecated_base_methods_test.rb | 6 - actionpack/test/controller/dispatcher_test.rb | 13 - actionpack/test/controller/filters_test.rb | 5 + actionpack/test/controller/layout_test.rb | 3 +- actionpack/test/controller/rescue_test.rb | 346 +++------------------ 8 files changed, 61 insertions(+), 326 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 60957a2f0e..484d3c5ce7 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -489,7 +489,7 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase get :index assert_response :success flunk 'Expected non-success response' - rescue ActiveSupport::TestCase::Assertion => e + rescue RuntimeError => e assert e.message.include?('FAIL') end diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index f4517d06c4..0c54d61426 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -27,6 +27,7 @@ class EmptyController < ActionController::Base end class NonEmptyController < ActionController::Base def public_action + render :nothing => true end hide_action :hidden_action @@ -51,6 +52,7 @@ end class DefaultUrlOptionsController < ActionController::Base def default_url_options_action + render :nothing => true end def default_url_options(options = nil) @@ -151,11 +153,8 @@ class PerformActionTest < ActionController::TestCase def test_get_on_hidden_should_fail use_controller NonEmptyController - get :hidden_action - assert_response 404 - - get :another_hidden_action - assert_response 404 + assert_raise(ActionController::UnknownAction) { get :hidden_action } + assert_raise(ActionController::UnknownAction) { get :another_hidden_action } end def test_namespaced_action_should_log_module_name diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 6b9d1056a3..560c09509b 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -149,6 +149,9 @@ class PageCachingTest < ActionController::TestCase end class ActionCachingTestController < ActionController::Base + rescue_from(Exception) { head 500 } + rescue_from(ActiveRecord::RecordNotFound) { head :not_found } + caches_action :index, :redirected, :forbidden, :if => Proc.new { |c| !c.request.format.json? }, :expires_in => 1.hour caches_action :show, :cache_path => 'http://test.host/custom/show' caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" } diff --git a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb index dd69a63020..0c02afea36 100644 --- a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb +++ b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb @@ -15,12 +15,6 @@ class DeprecatedBaseMethodsTest < ActionController::TestCase tests Target - def test_log_error_silences_deprecation_warnings - get :raises_name_error - rescue => e - assert_not_deprecated { @controller.send :log_error, e } - end - if defined? Test::Unit::Error def test_assertion_failed_error_silences_deprecation_warnings get :raises_name_error diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index c3bd113b86..b315232a7b 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -45,19 +45,6 @@ class DispatcherTest < Test::Unit::TestCase def log_failsafe_exception(status, exception); end end - def test_failsafe_response - Dispatcher.any_instance.expects(:_call).raises('b00m') - ActionDispatch::Failsafe.any_instance.expects(:log_failsafe_exception) - - assert_nothing_raised do - assert_equal [ - 500, - {"Content-Type" => "text/html"}, - ["

500 Internal Server Error

"] - ], dispatch - end - end - def test_prepare_callbacks a = b = c = nil Dispatcher.to_prepare { |*args| a = b = c = 1 } diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 5876f55420..5fd3eb0446 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -169,6 +169,7 @@ class FilterTest < Test::Unit::TestCase end def public + render :text => 'ok' end end @@ -177,6 +178,10 @@ class FilterTest < Test::Unit::TestCase before_filter :find_record before_filter :ensure_login + def index + render :text => 'ok' + end + private def find_record @ran_filter ||= [] diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index da3f7b0cb8..5b7d40d16d 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -205,8 +205,7 @@ end class LayoutExceptionRaised < ActionController::TestCase def test_exception_raised_when_layout_file_not_found @controller = SetsNonExistentLayoutFile.new - get :hello - assert_kind_of ActionView::MissingTemplate, @controller.template.instance_eval { @exception } + assert_raise(ActionView::MissingTemplate) { get :hello } end end diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 894420a910..f745926b20 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -138,213 +138,88 @@ class RescueController < ActionController::Base end end -class RescueControllerTest < ActionController::TestCase - FIXTURE_PUBLIC = "#{File.dirname(__FILE__)}/../fixtures".freeze - - def setup - super - set_all_requests_local - populate_exception_object - end - - def set_all_requests_local - RescueController.consider_all_requests_local = true - @request.remote_addr = '1.2.3.4' - @request.host = 'example.com' - end - - def populate_exception_object - begin - raise 'foo' - rescue => @exception - end - end - - def test_rescue_exceptions_raised_by_filters - with_rails_root FIXTURE_PUBLIC do - with_all_requests_local false do - get :before_filter_raises - end - end +class ExceptionInheritanceRescueController < ActionController::Base - assert_response :internal_server_error + class ParentException < StandardError end - def test_rescue_action_locally_if_all_requests_local - @controller.expects(:local_request?).never - @controller.expects(:rescue_action_locally).with(@exception) - @controller.expects(:rescue_action_in_public).never - - with_all_requests_local do - @controller.send :rescue_action, @exception - end + class ChildException < ParentException end - def test_rescue_action_locally_if_remote_addr_is_localhost - @controller.expects(:local_request?).returns(true) - @controller.expects(:rescue_action_locally).with(@exception) - @controller.expects(:rescue_action_in_public).never - - with_all_requests_local false do - @controller.send :rescue_action, @exception - end + class GrandchildException < ChildException end - def test_rescue_action_in_public_otherwise - @controller.expects(:local_request?).returns(false) - @controller.expects(:rescue_action_locally).never - @controller.expects(:rescue_action_in_public).with(@exception) + rescue_from ChildException, :with => lambda { head :ok } + rescue_from ParentException, :with => lambda { head :created } + rescue_from GrandchildException, :with => lambda { head :no_content } - with_all_requests_local false do - @controller.send :rescue_action, @exception - end + def raise_parent_exception + raise ParentException end - def test_rescue_action_in_public_with_localized_error_file - # Change locale - old_locale = I18n.locale - I18n.locale = :da - - with_rails_root FIXTURE_PUBLIC do - with_all_requests_local false do - get :raises - end - end - - assert_response :internal_server_error - body = File.read("#{FIXTURE_PUBLIC}/public/500.da.html") - assert_equal body, @response.body - ensure - I18n.locale = old_locale + def raise_child_exception + raise ChildException end - def test_rescue_action_in_public_with_error_file - with_rails_root FIXTURE_PUBLIC do - with_all_requests_local false do - get :raises - end - end - - assert_response :internal_server_error - body = File.read("#{FIXTURE_PUBLIC}/public/500.html") - assert_equal body, @response.body + def raise_grandchild_exception + raise GrandchildException end +end - def test_rescue_action_in_public_without_error_file - with_rails_root '/tmp' do - with_all_requests_local false do - get :raises - end - end - - assert_response :internal_server_error - assert_equal ' ', @response.body +class ExceptionInheritanceRescueControllerTest < ActionController::TestCase + def test_bottom_first + get :raise_grandchild_exception + assert_response :no_content end - def test_rescue_unknown_action_in_public_with_error_file - with_rails_root FIXTURE_PUBLIC do - with_all_requests_local false do - get :foobar_doesnt_exist - end - end - - assert_response :not_found - body = File.read("#{FIXTURE_PUBLIC}/public/404.html") - assert_equal body, @response.body + def test_inheritance_works + get :raise_child_exception + assert_response :created end +end - def test_rescue_unknown_action_in_public_without_error_file - with_rails_root '/tmp' do - with_all_requests_local false do - get :foobar_doesnt_exist - end - end - - assert_response :not_found - assert_equal ' ', @response.body +class ControllerInheritanceRescueController < ExceptionInheritanceRescueController + class FirstExceptionInChildController < StandardError end - def test_rescue_missing_template_in_public - with_rails_root FIXTURE_PUBLIC do - with_all_requests_local true do - get :missing_template - end - end - - assert_response :internal_server_error - assert @response.body.include?('missing_template'), "Response should include the template name." + class SecondExceptionInChildController < StandardError end - def test_rescue_action_locally - get :raises - assert_response :internal_server_error - assert_template 'diagnostics.erb' - assert @response.body.include?('RescueController#raises'), "Response should include controller and action." - assert @response.body.include?("don't panic"), "Response should include exception message." - end + rescue_from FirstExceptionInChildController, 'SecondExceptionInChildController', :with => lambda { head :gone } - def test_local_request_when_remote_addr_is_localhost - @controller.expects(:request).returns(@request).at_least_once - with_remote_addr '127.0.0.1' do - assert @controller.send(:local_request?) - end + def raise_first_exception_in_child_controller + raise FirstExceptionInChildController end - def test_local_request_when_remote_addr_isnt_locahost - @controller.expects(:request).returns(@request) - with_remote_addr '1.2.3.4' do - assert !@controller.send(:local_request?) - end + def raise_second_exception_in_child_controller + raise SecondExceptionInChildController end +end - def test_rescue_responses - responses = ActionController::Base.rescue_responses - - assert_equal ActionController::Rescue::DEFAULT_RESCUE_RESPONSE, responses.default - assert_equal ActionController::Rescue::DEFAULT_RESCUE_RESPONSE, responses[Exception.new] - - assert_equal :not_found, responses[ActionController::RoutingError.name] - assert_equal :not_found, responses[ActionController::UnknownAction.name] - assert_equal :not_found, responses['ActiveRecord::RecordNotFound'] - assert_equal :conflict, responses['ActiveRecord::StaleObjectError'] - assert_equal :unprocessable_entity, responses['ActiveRecord::RecordInvalid'] - assert_equal :unprocessable_entity, responses['ActiveRecord::RecordNotSaved'] - assert_equal :method_not_allowed, responses['ActionController::MethodNotAllowed'] - assert_equal :not_implemented, responses['ActionController::NotImplemented'] +class ControllerInheritanceRescueControllerTest < ActionController::TestCase + def test_first_exception_in_child_controller + get :raise_first_exception_in_child_controller + assert_response :gone end - def test_rescue_templates - templates = ActionController::Base.rescue_templates - - assert_equal ActionController::Rescue::DEFAULT_RESCUE_TEMPLATE, templates.default - assert_equal ActionController::Rescue::DEFAULT_RESCUE_TEMPLATE, templates[Exception.new] - - assert_equal 'missing_template', templates[ActionView::MissingTemplate.name] - assert_equal 'routing_error', templates[ActionController::RoutingError.name] - assert_equal 'unknown_action', templates[ActionController::UnknownAction.name] - assert_equal 'template_error', templates[ActionView::TemplateError.name] + def test_second_exception_in_child_controller + get :raise_second_exception_in_child_controller + assert_response :gone end - def test_not_implemented - with_all_requests_local false do - with_rails_public_path(".") do - head :not_implemented - end - end - assert_response :not_implemented - assert_equal "GET, PUT", @response.headers['Allow'] + def test_exception_in_parent_controller + get :raise_parent_exception + assert_response :created end +end - def test_method_not_allowed - with_all_requests_local false do - with_rails_public_path(".") do - get :method_not_allowed - end - end - assert_response :method_not_allowed - assert_equal "GET, HEAD, PUT", @response.headers['Allow'] +class ApplicationController < ActionController::Base + rescue_from ActionController::RoutingError do + render :text => 'no way' end +end +class RescueControllerTest < ActionController::TestCase def test_rescue_handler get :not_authorized assert_response :forbidden @@ -399,133 +274,6 @@ class RescueControllerTest < ActionController::TestCase get :resource_unavailable_raise_as_string assert_equal "RescueController::ResourceUnavailableToRescueAsString", @response.body end - - protected - def with_all_requests_local(local = true) - old_local, ActionController::Base.consider_all_requests_local = - ActionController::Base.consider_all_requests_local, local - yield - ensure - ActionController::Base.consider_all_requests_local = old_local - end - - def with_remote_addr(addr) - old_remote_addr, @request.remote_addr = @request.remote_addr, addr - yield - ensure - @request.remote_addr = old_remote_addr - end - - def with_rails_public_path(rails_root) - old_rails = Object.const_get(:Rails) rescue nil - mod = Object.const_set(:Rails, Module.new) - (class << mod; self; end).instance_eval do - define_method(:public_path) { "#{rails_root}/public" } - end - yield - ensure - Object.module_eval { remove_const(:Rails) } if defined?(Rails) - Object.const_set(:Rails, old_rails) if old_rails - end - - def with_rails_root(path = nil,&block) - old_rails_root = RAILS_ROOT if defined?(RAILS_ROOT) - if path - silence_warnings { Object.const_set(:RAILS_ROOT, path) } - else - Object.remove_const(:RAILS_ROOT) rescue nil - end - - with_rails_public_path(path, &block) - - ensure - if old_rails_root - silence_warnings { Object.const_set(:RAILS_ROOT, old_rails_root) } - else - Object.remove_const(:RAILS_ROOT) rescue nil - end - end -end - -class ExceptionInheritanceRescueController < ActionController::Base - - class ParentException < StandardError - end - - class ChildException < ParentException - end - - class GrandchildException < ChildException - end - - rescue_from ChildException, :with => lambda { head :ok } - rescue_from ParentException, :with => lambda { head :created } - rescue_from GrandchildException, :with => lambda { head :no_content } - - def raise_parent_exception - raise ParentException - end - - def raise_child_exception - raise ChildException - end - - def raise_grandchild_exception - raise GrandchildException - end -end - -class ExceptionInheritanceRescueControllerTest < ActionController::TestCase - def test_bottom_first - get :raise_grandchild_exception - assert_response :no_content - end - - def test_inheritance_works - get :raise_child_exception - assert_response :created - end -end - -class ControllerInheritanceRescueController < ExceptionInheritanceRescueController - class FirstExceptionInChildController < StandardError - end - - class SecondExceptionInChildController < StandardError - end - - rescue_from FirstExceptionInChildController, 'SecondExceptionInChildController', :with => lambda { head :gone } - - def raise_first_exception_in_child_controller - raise FirstExceptionInChildController - end - - def raise_second_exception_in_child_controller - raise SecondExceptionInChildController - end -end - -class ControllerInheritanceRescueControllerTest < ActionController::TestCase - def test_first_exception_in_child_controller - get :raise_first_exception_in_child_controller - assert_response :gone - end - - def test_second_exception_in_child_controller - get :raise_second_exception_in_child_controller - assert_response :gone - end - - def test_exception_in_parent_controller - get :raise_parent_exception - assert_response :created - end -end - -class ApplicationController < ActionController::Base - rescue_from ActionController::RoutingError do - render :text => 'no way' - end end class RescueTest < ActionController::IntegrationTest -- cgit v1.2.3 From d4402c5554a0d3202fc22eb38c5c1a8c4b9afd93 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 4 May 2009 20:26:43 -0500 Subject: assert_redirect_to's partial hash matching was deprecated in 2-3 stable 7f1f16c01 --- actionpack/test/controller/redirect_test.rb | 7 ------- 1 file changed, 7 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index 9ad63a1c60..13247f2d08 100644 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -233,13 +233,6 @@ class RedirectTest < ActionController::TestCase assert_redirected_to Workshop.new(5, true) end - def test_redirect_with_partial_params - pending do - get :module_redirect - assert_redirected_to :action => 'hello_world' - end - end - def test_redirect_to_nil assert_raise(ActionController::ActionControllerError) do get :redirect_to_nil -- cgit v1.2.3