Permalink
Browse files

Rewrite FCGI handler test

  • Loading branch information...
1 parent 7de5f69 commit 20d6938453f439531a13e2ef1fd0905edf56294c @josh josh committed Oct 5, 2009
View
4 railties/lib/rails/fcgi_handler.rb
@@ -216,7 +216,9 @@ def mark_features!
def restore!
$".replace @features
- Dispatcher.reset_application!
+ # TODO: Reloading the application should be the "Application"s
+ # responsibility
+ ActionDispatch::Callbacks.new(lambda {}, true)
ActionController::Routing::Routes.reload
end
View
12 railties/test/abstract_unit.rb
@@ -25,15 +25,3 @@
else
RAILS_ROOT = File.dirname(__FILE__)
end
-
-def uses_gem(gem_name, test_name, version = '> 0')
- begin
- require gem_name.to_s
- rescue LoadError
- gem gem_name.to_s, version
- require gem_name.to_s
- end
- yield
-rescue LoadError
- $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
-end
View
64 railties/test/fcgi_dispatcher_test.rb → .../test/application/fcgi_dispatcher_test.rb
@@ -1,18 +1,25 @@
-require 'abstract_unit'
+require 'isolation/abstract_unit'
+require 'mocha'
-uses_gem "fcgi", "0.8.7" do
+begin
-require 'action_controller'
-require 'rails/fcgi_handler'
-
-module Rails
- def self.application
- ActionController::Routing::Routes
- end
+begin
+ require 'fcgi'
+rescue LoadError
+ gem 'fcgi', '0.8.7'
+ require 'fcgi'
end
class RailsFCGIHandlerTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
def setup
+ build_app
+ boot_rails
+
+ require "#{rails_root}/config/environment"
+ require 'rails/fcgi_handler'
+
@log = StringIO.new
@handler = RailsFCGIHandler.new(@log)
end
@@ -87,7 +94,6 @@ def test_reload
assert_nil @handler.when_ready
end
-
def test_reload_runs_gc_when_gc_request_period_set
@handler.expects(:run_gc!)
@handler.expects(:restore!)
@@ -111,7 +117,6 @@ def test_restart!
def test_restore!
$".expects(:replace)
- Dispatcher.expects(:reset_application!)
ActionController::Routing::Routes.expects(:reload)
@handler.send(:restore!)
end
@@ -127,17 +132,24 @@ def test_uninterrupted_processing
end
end
-
class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
- class ::RailsFCGIHandler
- attr_accessor :signal
- alias_method :old_gc_countdown, :gc_countdown
- def gc_countdown
- signal ? Process.kill(signal, $$) : old_gc_countdown
- end
- end
+ include ActiveSupport::Testing::Isolation
def setup
+ build_app
+ boot_rails
+
+ require "#{rails_root}/config/environment"
+ require 'rails/fcgi_handler'
+
+ ::RailsFCGIHandler.class_eval do
+ attr_accessor :signal
+ alias_method :old_gc_countdown, :gc_countdown
+ def gc_countdown
+ signal ? Process.kill(signal, $$) : old_gc_countdown
+ end
+ end
+
@log = StringIO.new
@handler = RailsFCGIHandler.new(@log)
@dispatcher = mock
@@ -232,9 +244,16 @@ def test_signal_exception_in_dispatcher
end
end
-
class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
def setup
+ build_app
+ boot_rails
+
+ require "#{rails_root}/config/environment"
+ require 'rails/fcgi_handler'
+
@log = StringIO.new
end
@@ -265,4 +284,7 @@ def test_periodic_gc
assert_nil @handler.when_ready
end
end
-end # uses_gem "fcgi"
+
+rescue LoadError
+ $stderr.puts 'Skipping fcgi tests. `gem install fcgi` and try again.'
+end

0 comments on commit 20d6938

Please sign in to comment.