show_exceptions_test.rb 1.4 KB
Newer Older
1
# encoding: utf-8
2
require 'isolation/abstract_unit'
3
require 'rack/test'
4 5 6 7

module ApplicationTests
  class ShowExceptionsTest < Test::Unit::TestCase
    include ActiveSupport::Testing::Isolation
8
    include Rack::Test::Methods
9 10 11 12 13 14

    def setup
      build_app
      boot_rails
    end

15 16 17 18
    def teardown
      teardown_app
    end

19
    test "unspecified route when set action_dispatch.show_exceptions to false" do
20
      app.config.action_dispatch.show_exceptions = false
21 22 23 24 25 26 27

      assert_raise(ActionController::RoutingError) do
        get '/foo'
      end
    end

    test "unspecified route when set action_dispatch.show_exceptions to true" do
28
      app.config.action_dispatch.show_exceptions = true
29 30 31 32 33

      assert_nothing_raised(ActionController::RoutingError) do
        get '/foo'
      end
    end
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

    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
59 60
  end
end