1 require 'abstract_unit'
4 class ReloaderTests < ActiveSupport::TestCase
5 Reloader = ActionController::Reloader
6 Dispatcher = ActionController::Dispatcher
22 @on_close.call if @on_close
30 def test_it_reloads_the_application_before_yielding
31 Dispatcher.expects(:reload_application)
32 Reloader.run(@lock) do
33 [200, { "Content-Type" => "text/html" }, [""]]
37 def test_it_locks_before_yielding
39 Dispatcher.expects(:reload_application)
42 [200, { "Content-Type" => "text/html" }, [""]]
47 def test_it_unlocks_upon_calling_close_on_body
49 Dispatcher.expects(:reload_application)
50 headers, status, body = Reloader.run(lock) do
51 [200, { "Content-Type" => "text/html" }, [""]]
57 def test_it_unlocks_if_app_object_raises_exception
59 Dispatcher.expects(:reload_application)
60 assert_raise(RuntimeError) do
68 def test_returned_body_object_always_responds_to_close
69 status, headers, body = Reloader.run(@lock) do
70 [200, { "Content-Type" => "text/html" }, [""]]
72 assert body.respond_to?(:close)
75 def test_returned_body_object_behaves_like_underlying_object
76 status, headers, body = Reloader.run(@lock) do
80 [200, { "Content-Type" => "text/html" }, b]
82 assert_equal 2, body.size
83 assert_equal "hello", body[0]
84 assert_equal "world", body[1]
85 assert_equal "foo", body.foo
86 assert_equal "bar", body.bar
89 def test_it_calls_close_on_underlying_object_when_close_is_called_on_body
91 status, headers, body = Reloader.run(@lock) do
95 [200, { "Content-Type" => "text/html" }, b]
101 def test_returned_body_object_responds_to_all_methods_supported_by_underlying_object
102 status, headers, body = Reloader.run(@lock) do
103 [200, { "Content-Type" => "text/html" }, MyBody.new]
105 assert body.respond_to?(:size)
106 assert body.respond_to?(:each)
107 assert body.respond_to?(:foo)
108 assert body.respond_to?(:bar)
111 def test_it_doesnt_clean_up_the_application_after_call
112 Dispatcher.expects(:cleanup_application).never
113 status, headers, body = Reloader.run(@lock) do
114 [200, { "Content-Type" => "text/html" }, MyBody.new]
118 def test_it_cleans_up_the_application_when_close_is_called_on_body
119 Dispatcher.expects(:cleanup_application)
120 status, headers, body = Reloader.run(@lock) do
121 [200, { "Content-Type" => "text/html" }, MyBody.new]