aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-05-04 19:23:34 -0300
committerEmilio Tagua <miloops@gmail.com>2009-05-04 19:23:34 -0300
commitd3042ef80c4406c90ff1e120059a99784d8ae79f (patch)
treea779b4fced3fd546d7c7c855fee41f3d996afba0 /actionpack/test/dispatch
parentd522b7ccf61a71b4c66ddf39368513d1fd9cd577 (diff)
parenteb201e64c0b68aee6d0715d44cf48178204c4133 (diff)
downloadrails-d3042ef80c4406c90ff1e120059a99784d8ae79f.tar.gz
rails-d3042ef80c4406c90ff1e120059a99784d8ae79f.tar.bz2
rails-d3042ef80c4406c90ff1e120059a99784d8ae79f.zip
Merge commit 'rails/master'
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r--actionpack/test/dispatch/show_exceptions_test.rb103
-rw-r--r--actionpack/test/dispatch/test_request_test.rb2
2 files changed, 104 insertions, 1 deletions
diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb
new file mode 100644
index 0000000000..f8f562e7c1
--- /dev/null
+++ b/actionpack/test/dispatch/show_exceptions_test.rb
@@ -0,0 +1,103 @@
+require 'abstract_unit'
+
+module ActionDispatch
+ class ShowExceptions
+ private
+ def public_path
+ "#{FIXTURE_LOAD_PATH}/public"
+ end
+ end
+end
+
+class ShowExceptionsTest < ActionController::IntegrationTest
+ Boomer = lambda do |env|
+ req = ActionDispatch::Request.new(env)
+ case req.path
+ when "/not_found"
+ raise ActionController::UnknownAction
+ when "/method_not_allowed"
+ raise ActionController::MethodNotAllowed
+ when "/not_implemented"
+ raise ActionController::NotImplemented
+ when "/unprocessable_entity"
+ raise ActionController::InvalidAuthenticityToken
+ else
+ raise "puke!"
+ end
+ end
+
+ ProductionApp = ActionDispatch::ShowExceptions.new(Boomer, false)
+ DevelopmentApp = ActionDispatch::ShowExceptions.new(Boomer, true)
+
+ test "rescue in public from a remote ip" do
+ @integration_session = open_session(ProductionApp)
+ self.remote_addr = '208.77.188.166'
+
+ get "/"
+ assert_response 500
+ assert_equal "500 error fixture\n", body
+
+ get "/not_found"
+ assert_response 404
+ assert_equal "404 error fixture\n", body
+
+ get "/method_not_allowed"
+ assert_response 405
+ assert_equal "", body
+ end
+
+ test "rescue locally from a local request" do
+ @integration_session = open_session(ProductionApp)
+ self.remote_addr = '127.0.0.1'
+
+ get "/"
+ assert_response 500
+ assert_match /puke/, body
+
+ get "/not_found"
+ assert_response 404
+ assert_match /ActionController::UnknownAction/, body
+
+ get "/method_not_allowed"
+ assert_response 405
+ assert_match /ActionController::MethodNotAllowed/, body
+ end
+
+ test "localize public rescue message" do
+ # Change locale
+ old_locale = I18n.locale
+ I18n.locale = :da
+
+ begin
+ @integration_session = open_session(ProductionApp)
+ self.remote_addr = '208.77.188.166'
+
+ get "/"
+ assert_response 500
+ assert_equal "500 localized error fixture\n", body
+
+ get "/not_found"
+ assert_response 404
+ assert_equal "404 error fixture\n", body
+ ensure
+ I18n.locale = old_locale
+ end
+ end
+
+ test "always rescue locally in development mode" do
+ @integration_session = open_session(DevelopmentApp)
+ self.remote_addr = '208.77.188.166'
+
+ get "/"
+ assert_response 500
+ assert_match /puke/, body
+
+ get "/not_found"
+ assert_response 404
+ assert_match /ActionController::UnknownAction/, body
+
+ get "/method_not_allowed"
+ assert_response 405
+ assert_match /ActionController::MethodNotAllowed/, body
+ end
+end
diff --git a/actionpack/test/dispatch/test_request_test.rb b/actionpack/test/dispatch/test_request_test.rb
index 19b5e2988b..5da02b2ea6 100644
--- a/actionpack/test/dispatch/test_request_test.rb
+++ b/actionpack/test/dispatch/test_request_test.rb
@@ -40,6 +40,6 @@ class TestRequestTest < ActiveSupport::TestCase
req.cookies["login"] = "XJ-122"
assert_equal({"user_name" => "david", "login" => "XJ-122"}, req.cookies)
- assert_equal "login=XJ-122; user_name=david;", req.env["HTTP_COOKIE"]
+ assert_equal %w(login=XJ-122 user_name=david), req.env["HTTP_COOKIE"].split(/; ?/).sort
end
end