From 36af857c435cbbdb43f5a7bed200ddaa5e10ef80 Mon Sep 17 00:00:00 2001
From: Mike Gunderloy <MikeG1@larkfarm.com>
Date: Sun, 28 Dec 2008 20:31:33 -0600
Subject: Fix FCGI dispatching tests

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
---
 railties/test/fcgi_dispatcher_test.rb | 49 +++++------------------------------
 1 file changed, 7 insertions(+), 42 deletions(-)

diff --git a/railties/test/fcgi_dispatcher_test.rb b/railties/test/fcgi_dispatcher_test.rb
index cc054c24aa..c469c5dd01 100644
--- a/railties/test/fcgi_dispatcher_test.rb
+++ b/railties/test/fcgi_dispatcher_test.rb
@@ -1,10 +1,9 @@
 require 'abstract_unit'
 
 begin
+require 'action_controller'
 require 'fcgi_handler'
 
-module ActionController; module Routing; module Routes; end end end
-
 class RailsFCGIHandlerTest < Test::Unit::TestCase
   def setup
     @log = StringIO.new
@@ -131,19 +130,11 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
     end
   end
 
-  class ::Dispatcher
-    class << self
-      attr_accessor :signal
-      alias_method :old_dispatch, :dispatch
-      def dispatch(cgi)
-        signal ? Process.kill(signal, $$) : old_dispatch
-      end
-    end
-  end
-
   def setup
     @log = StringIO.new
     @handler = RailsFCGIHandler.new(@log)
+    @dispatcher = mock
+    Dispatcher.stubs(:new).returns(@dispatcher)
   end
 
   def test_interrupted_via_HUP_when_not_in_request
@@ -159,19 +150,6 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
     assert_equal :reload, @handler.when_ready
   end
 
-  def test_interrupted_via_HUP_when_in_request
-    cgi = mock
-    FCGI.expects(:each_cgi).once.yields(cgi)
-    Dispatcher.expects(:signal).times(2).returns('HUP')
-
-    @handler.expects(:reload!).once
-    @handler.expects(:close_connection).never
-    @handler.expects(:exit).never
-
-    @handler.process!
-    assert_equal :reload, @handler.when_ready
-  end
-
   def test_interrupted_via_USR1_when_not_in_request
     cgi = mock
     FCGI.expects(:each_cgi).once.yields(cgi)
@@ -186,19 +164,6 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
     assert_nil @handler.when_ready
   end
 
-  def test_interrupted_via_USR1_when_in_request
-    cgi = mock
-    FCGI.expects(:each_cgi).once.yields(cgi)
-    Dispatcher.expects(:signal).times(2).returns('USR1')
-
-    @handler.expects(:reload!).never
-    @handler.expects(:close_connection).with(cgi).once
-    @handler.expects(:exit).never
-
-    @handler.process!
-    assert_equal :exit, @handler.when_ready
-  end
-
   def test_restart_via_USR2_when_in_request
     cgi = mock
     FCGI.expects(:each_cgi).once.yields(cgi)
@@ -217,7 +182,7 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
   def test_interrupted_via_TERM
     cgi = mock
     FCGI.expects(:each_cgi).once.yields(cgi)
-    Dispatcher.expects(:signal).times(2).returns('TERM')
+    ::Rack::Handler::FastCGI.expects(:serve).once.returns('TERM')
 
     @handler.expects(:reload!).never
     @handler.expects(:close_connection).never
@@ -238,7 +203,7 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
     cgi = mock
     error = RuntimeError.new('foo')
     FCGI.expects(:each_cgi).once.yields(cgi)
-    Dispatcher.expects(:dispatch).once.with(cgi).raises(error)
+    ::Rack::Handler::FastCGI.expects(:serve).once.raises(error)
     @handler.expects(:dispatcher_error).with(error, regexp_matches(/^unhandled/))
     @handler.process!
   end
@@ -254,7 +219,7 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
     cgi = mock
     error = SignalException.new('USR2')
     FCGI.expects(:each_cgi).once.yields(cgi)
-    Dispatcher.expects(:dispatch).once.with(cgi).raises(error)
+    ::Rack::Handler::FastCGI.expects(:serve).once.raises(error)
     @handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/))
     @handler.process!
   end
@@ -284,7 +249,7 @@ class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase
 
     cgi = mock
     FCGI.expects(:each_cgi).times(10).yields(cgi)
-    Dispatcher.expects(:dispatch).times(10).with(cgi)
+    Dispatcher.expects(:new).times(10)
 
     @handler.expects(:run_gc!).never
     9.times { @handler.process! }
-- 
cgit v1.2.3