From c6d6b28bb4e105fd0ae7a0ef3c7df4bc416bd397 Mon Sep 17 00:00:00 2001 From: lest Date: Tue, 22 Nov 2011 11:24:05 +0300 Subject: refactor show exceptions tests --- actionpack/test/controller/show_exceptions_test.rb | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 actionpack/test/controller/show_exceptions_test.rb (limited to 'actionpack/test/controller/show_exceptions_test.rb') diff --git a/actionpack/test/controller/show_exceptions_test.rb b/actionpack/test/controller/show_exceptions_test.rb new file mode 100644 index 0000000000..c328a42e89 --- /dev/null +++ b/actionpack/test/controller/show_exceptions_test.rb @@ -0,0 +1,59 @@ +require 'abstract_unit' + +module ShowExceptions + class ShowExceptionsController < ActionController::Metal + use ActionDispatch::ShowExceptions + + def boom + raise 'boom!' + end + end + + class ShowExceptionsTest < ActionDispatch::IntegrationTest + test 'show error page from a remote ip' do + @app = ShowExceptionsController.action(:boom) + self.remote_addr = '208.77.188.166' + get '/' + assert_equal "500 error fixture\n", body + end + + test 'show diagnostics from a local ip' do + @app = ShowExceptionsController.action(:boom) + ['127.0.0.1', '127.0.0.127', '::1', '0:0:0:0:0:0:0:1', '0:0:0:0:0:0:0:1%0'].each do |ip_address| + self.remote_addr = ip_address + get '/' + assert_match /boom/, body + end + end + + test 'show diagnostics from a remote ip when consider_all_requests_local is true' do + Rails.stubs(:application).returns stub(:config => stub(:consider_all_requests_local => true)) + @app = ShowExceptionsController.action(:boom) + self.remote_addr = '208.77.188.166' + get '/' + assert_match /boom/, body + end + end + + class ShowExceptionsOverridenController < ShowExceptionsController + private + + def show_detailed_exceptions? + params['detailed'] == '1' + end + end + + class ShowExceptionsOverridenTest < ActionDispatch::IntegrationTest + test 'show error page' do + @app = ShowExceptionsOverridenController.action(:boom) + get '/', {'detailed' => '0'} + assert_equal "500 error fixture\n", body + end + + test 'show diagnostics message' do + @app = ShowExceptionsOverridenController.action(:boom) + get '/', {'detailed' => '1'} + assert_match /boom/, body + end + end +end -- cgit v1.2.3 From 5bcd119b8d9bb6d88c949956de1ce13c2673b877 Mon Sep 17 00:00:00 2001 From: lest Date: Tue, 22 Nov 2011 13:34:13 +0300 Subject: move show_detailed_exceptions? to Rescue module --- actionpack/test/controller/show_exceptions_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test/controller/show_exceptions_test.rb') diff --git a/actionpack/test/controller/show_exceptions_test.rb b/actionpack/test/controller/show_exceptions_test.rb index c328a42e89..39245e9574 100644 --- a/actionpack/test/controller/show_exceptions_test.rb +++ b/actionpack/test/controller/show_exceptions_test.rb @@ -1,7 +1,7 @@ require 'abstract_unit' module ShowExceptions - class ShowExceptionsController < ActionController::Metal + class ShowExceptionsController < ActionController::Base use ActionDispatch::ShowExceptions def boom @@ -27,7 +27,7 @@ module ShowExceptions end test 'show diagnostics from a remote ip when consider_all_requests_local is true' do - Rails.stubs(:application).returns stub(:config => stub(:consider_all_requests_local => true)) + ShowExceptionsController.any_instance.stubs(:consider_all_requests_local).returns(true) @app = ShowExceptionsController.action(:boom) self.remote_addr = '208.77.188.166' get '/' -- cgit v1.2.3 From 453f5534b4a8517c6fd39702fc98f0c6f1d5fd9e Mon Sep 17 00:00:00 2001 From: kennyj Date: Thu, 24 Nov 2011 00:10:34 +0900 Subject: Warnings removed. (ambiguous first argument) --- actionpack/test/controller/show_exceptions_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/test/controller/show_exceptions_test.rb') diff --git a/actionpack/test/controller/show_exceptions_test.rb b/actionpack/test/controller/show_exceptions_test.rb index 39245e9574..74067cb895 100644 --- a/actionpack/test/controller/show_exceptions_test.rb +++ b/actionpack/test/controller/show_exceptions_test.rb @@ -22,7 +22,7 @@ module ShowExceptions ['127.0.0.1', '127.0.0.127', '::1', '0:0:0:0:0:0:0:1', '0:0:0:0:0:0:0:1%0'].each do |ip_address| self.remote_addr = ip_address get '/' - assert_match /boom/, body + assert_match(/boom/, body) end end @@ -31,7 +31,7 @@ module ShowExceptions @app = ShowExceptionsController.action(:boom) self.remote_addr = '208.77.188.166' get '/' - assert_match /boom/, body + assert_match(/boom/, body) end end @@ -53,7 +53,7 @@ module ShowExceptions test 'show diagnostics message' do @app = ShowExceptionsOverridenController.action(:boom) get '/', {'detailed' => '1'} - assert_match /boom/, body + assert_match(/boom/, body) end end end -- cgit v1.2.3