aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-10-05 10:36:05 -0500
committerJoshua Peek <josh@joshpeek.com>2009-10-05 10:36:05 -0500
commit20d6938453f439531a13e2ef1fd0905edf56294c (patch)
treeb83f1668b18cff04fc856f32132e81b704876f50
parent7de5f69cc6bc9a946afd3a0fa0ec785f9fb94fb5 (diff)
downloadrails-20d6938453f439531a13e2ef1fd0905edf56294c.tar.gz
rails-20d6938453f439531a13e2ef1fd0905edf56294c.tar.bz2
rails-20d6938453f439531a13e2ef1fd0905edf56294c.zip
Rewrite FCGI handler test
-rw-r--r--railties/lib/rails/fcgi_handler.rb4
-rw-r--r--railties/test/abstract_unit.rb12
-rw-r--r--railties/test/application/fcgi_dispatcher_test.rb (renamed from railties/test/fcgi_dispatcher_test.rb)64
3 files changed, 46 insertions, 34 deletions
diff --git a/railties/lib/rails/fcgi_handler.rb b/railties/lib/rails/fcgi_handler.rb
index ef6f3b094c..77dce5f325 100644
--- a/railties/lib/rails/fcgi_handler.rb
+++ b/railties/lib/rails/fcgi_handler.rb
@@ -216,7 +216,9 @@ class RailsFCGIHandler
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
diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb
index 50c427dc64..6c6af0b2bf 100644
--- a/railties/test/abstract_unit.rb
+++ b/railties/test/abstract_unit.rb
@@ -25,15 +25,3 @@ if defined?(RAILS_ROOT)
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
diff --git a/railties/test/fcgi_dispatcher_test.rb b/railties/test/application/fcgi_dispatcher_test.rb
index 4d77a321a0..b8ab9f8996 100644
--- a/railties/test/fcgi_dispatcher_test.rb
+++ b/railties/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 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase
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 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase
def test_restore!
$".expects(:replace)
- Dispatcher.expects(:reset_application!)
ActionController::Routing::Routes.expects(:reload)
@handler.send(:restore!)
end
@@ -127,17 +132,24 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase
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 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
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 @@ class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase
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