2011-11-30 13:51:01 -05:00
|
|
|
# encoding: utf-8
|
2011-02-22 15:02:39 -05:00
|
|
|
require 'isolation/abstract_unit'
|
2011-11-30 13:51:01 -05:00
|
|
|
require 'rack/test'
|
2011-02-22 15:02:39 -05:00
|
|
|
|
|
|
|
module ApplicationTests
|
2011-12-01 14:46:18 -05:00
|
|
|
class MiddlewareExceptionsTest < Test::Unit::TestCase
|
2011-02-22 15:02:39 -05:00
|
|
|
include ActiveSupport::Testing::Isolation
|
2011-11-30 13:51:01 -05:00
|
|
|
include Rack::Test::Methods
|
2011-02-22 15:02:39 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
boot_rails
|
|
|
|
end
|
|
|
|
|
2011-06-06 08:54:05 -04:00
|
|
|
def teardown
|
|
|
|
teardown_app
|
|
|
|
end
|
|
|
|
|
2011-12-01 13:16:19 -05:00
|
|
|
test "show exceptions middleware filter backtrace before logging" do
|
|
|
|
my_middleware = Struct.new(:app) do
|
|
|
|
def call(env)
|
|
|
|
raise "Failure"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
app.config.middleware.use my_middleware
|
|
|
|
|
|
|
|
stringio = StringIO.new
|
|
|
|
Rails.logger = Logger.new(stringio)
|
|
|
|
|
|
|
|
get "/"
|
|
|
|
assert_no_match(/action_dispatch/, stringio.string)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "renders active record exceptions as 404" do
|
|
|
|
my_middleware = Struct.new(:app) do
|
|
|
|
def call(env)
|
|
|
|
raise ActiveRecord::RecordNotFound
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
app.config.middleware.use my_middleware
|
|
|
|
|
|
|
|
get "/"
|
|
|
|
assert_equal 404, last_response.status
|
|
|
|
end
|
|
|
|
|
2011-02-22 15:02:39 -05:00
|
|
|
test "unspecified route when set action_dispatch.show_exceptions to false" do
|
2011-11-30 13:51:01 -05:00
|
|
|
app.config.action_dispatch.show_exceptions = false
|
2011-02-22 15:02:39 -05:00
|
|
|
|
|
|
|
assert_raise(ActionController::RoutingError) do
|
|
|
|
get '/foo'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "unspecified route when set action_dispatch.show_exceptions to true" do
|
2011-11-30 13:51:01 -05:00
|
|
|
app.config.action_dispatch.show_exceptions = true
|
2011-02-22 15:02:39 -05:00
|
|
|
|
|
|
|
assert_nothing_raised(ActionController::RoutingError) do
|
|
|
|
get '/foo'
|
|
|
|
end
|
|
|
|
end
|
2011-11-30 13:51:01 -05:00
|
|
|
|
|
|
|
test "displays diagnostics message when exception raised in template that contains UTF-8" do
|
|
|
|
app.config.action_dispatch.show_exceptions = true
|
|
|
|
|
|
|
|
controller :foo, <<-RUBY
|
|
|
|
class FooController < ActionController::Base
|
|
|
|
def index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
app_file 'app/views/foo/index.html.erb', <<-ERB
|
|
|
|
<% raise 'boooom' %>
|
|
|
|
✓
|
|
|
|
ERB
|
|
|
|
|
|
|
|
app_file 'config/routes.rb', <<-RUBY
|
|
|
|
AppTemplate::Application.routes.draw do
|
|
|
|
match ':controller(/:action)'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
post '/foo', :utf8 => '✓'
|
|
|
|
assert_match(/boooom/, last_response.body)
|
|
|
|
end
|
2011-02-22 15:02:39 -05:00
|
|
|
end
|
|
|
|
end
|