aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/dispatcher_test.rb
blob: 7e19bce3b7dd72fdaf1fc1a806932922f449475a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
59
require 'abstract_unit'

# Ensure deprecated dispatcher works
class DeprecatedDispatcherTest < ActiveSupport::TestCase
  class DummyApp
    def call(env)
      [200, {}, 'response']
    end
  end 

  def setup
    ActionDispatch::Callbacks.reset_callbacks(:prepare)
    ActionDispatch::Callbacks.reset_callbacks(:call)
  end

  def test_assert_deprecated_to_prepare
    a = nil

    assert_deprecated do
      ActionController::Dispatcher.to_prepare { a = 1 }
    end

    assert_nil a
    dispatch
    assert_equal 1, a
  end

  def test_assert_deprecated_before_dispatch
    a = nil

    assert_deprecated do
      ActionController::Dispatcher.before_dispatch { a = 1 }
    end

    assert_nil a
    dispatch
    assert_equal 1, a
  end

  def test_assert_deprecated_after_dispatch
    a = nil

    assert_deprecated do
      ActionController::Dispatcher.after_dispatch { a = 1 }
    end

    assert_nil a
    dispatch
    assert_equal 1, a
  end

  private

    def dispatch(cache_classes = true)
      @dispatcher ||= ActionDispatch::Callbacks.new(DummyApp.new, !cache_classes)
      @dispatcher.call({'rack.input' => StringIO.new('')})
    end

end