aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-02-19 21:20:15 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-02-19 21:20:15 +0100
commitd8f1ee4b41352b870f617b01099b2877f754d32c (patch)
treedd6bdf1d1ded6aab7bb926109a24e942fc740b73 /railties
parent8ba1fc18e13c03966d411947180022c1730e81ff (diff)
parent7c0e008973e594ebf53607362c1dfbe34b693600 (diff)
downloadrails-d8f1ee4b41352b870f617b01099b2877f754d32c.tar.gz
rails-d8f1ee4b41352b870f617b01099b2877f754d32c.tar.bz2
rails-d8f1ee4b41352b870f617b01099b2877f754d32c.zip
Merge commit 'mainstream/master'
Diffstat (limited to 'railties')
-rw-r--r--railties/environments/production.rb1
-rw-r--r--railties/environments/test.rb1
-rw-r--r--railties/html/500.html3
-rw-r--r--railties/lib/console_app.rb1
-rw-r--r--railties/lib/fcgi_handler.rb22
-rw-r--r--railties/lib/initializer.rb9
-rw-r--r--railties/lib/rails/plugin/loader.rb2
-rw-r--r--railties/lib/rails_generator/generators/applications/app/template_runner.rb10
-rw-r--r--railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb8
-rw-r--r--railties/test/abstract_unit.rb8
-rw-r--r--railties/test/error_page_test.rb40
-rw-r--r--railties/test/fcgi_dispatcher_test.rb69
-rw-r--r--railties/test/generators/rails_template_runner_test.rb16
-rw-r--r--railties/test/initializer_test.rb20
-rw-r--r--railties/test/plugin_loader_test.rb2
15 files changed, 106 insertions, 106 deletions
diff --git a/railties/environments/production.rb b/railties/environments/production.rb
index 1fc9f6b923..27119d2d18 100644
--- a/railties/environments/production.rb
+++ b/railties/environments/production.rb
@@ -7,6 +7,7 @@ config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching = true
+config.action_view.cache_template_loading = true
# See everything in the log (default is :info)
# config.log_level = :debug
diff --git a/railties/environments/test.rb b/railties/environments/test.rb
index 496eb9572b..d6f80a4080 100644
--- a/railties/environments/test.rb
+++ b/railties/environments/test.rb
@@ -12,6 +12,7 @@ config.whiny_nils = true
# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching = false
+config.action_view.cache_template_loading = true
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
diff --git a/railties/html/500.html b/railties/html/500.html
index 74142cb04a..ec3bbf02c4 100644
--- a/railties/html/500.html
+++ b/railties/html/500.html
@@ -25,9 +25,6 @@
<div class="dialog">
<h1>We're sorry, but something went wrong.</h1>
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
- <p><small>(If you're the administrator of this website, then please read
- the log file "<%= "<%s>" % "%=h RAILS_ENV %" %>.log"
- to find out what went wrong.)</small></p>
</div>
</body>
</html>
diff --git a/railties/lib/console_app.rb b/railties/lib/console_app.rb
index 96bf3117c8..a35c96c957 100644
--- a/railties/lib/console_app.rb
+++ b/railties/lib/console_app.rb
@@ -25,7 +25,6 @@ end
def reload!
puts "Reloading..."
dispatcher = ActionController::Dispatcher.new($stdout)
- dispatcher.cleanup_application
dispatcher.reload_application
true
end
diff --git a/railties/lib/fcgi_handler.rb b/railties/lib/fcgi_handler.rb
index 1256ef2286..0cd2dc51c6 100644
--- a/railties/lib/fcgi_handler.rb
+++ b/railties/lib/fcgi_handler.rb
@@ -38,6 +38,8 @@ class RailsFCGIHandler
# Safely install signal handlers.
install_signal_handlers
+ @app = Dispatcher.new
+
# Start error timestamp at 11 seconds ago.
@last_error_on = Time.now - 11
end
@@ -69,36 +71,36 @@ class RailsFCGIHandler
protected
def process_each_request(provider)
- cgi = nil
+ request = nil
catch :exit do
- provider.each_cgi do |cgi|
- process_request(cgi)
+ provider.each do |request|
+ process_request(request)
case when_ready
when :reload
reload!
when :restart
- close_connection(cgi)
+ close_connection(request)
restart!
when :exit
- close_connection(cgi)
+ close_connection(request)
throw :exit
end
end
end
rescue SignalException => signal
raise unless signal.message == 'SIGUSR1'
- close_connection(cgi)
+ close_connection(request)
end
- def process_request(cgi)
+ def process_request(request)
@processing, @when_ready = true, nil
gc_countdown
with_signal_handler 'USR1' do
begin
- ::Rack::Handler::FastCGI.serve(cgi, Dispatcher.new)
+ ::Rack::Handler::FastCGI.serve(request, @app)
rescue SignalException, SystemExit
raise
rescue Exception => error
@@ -231,7 +233,7 @@ class RailsFCGIHandler
end
end
- def close_connection(cgi)
- cgi.instance_variable_get("@request").finish if cgi
+ def close_connection(request)
+ request.finish if request
end
end
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index cfd42544b6..a8b951ae58 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -369,11 +369,8 @@ Run `rake gems:install` to install the missing gems.
def load_view_paths
if configuration.frameworks.include?(:action_view)
- if configuration.cache_classes
- view_path = ActionView::Template::EagerPath.new(configuration.view_path)
- ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller)
- ActionMailer::Base.template_root = view_path if configuration.frameworks.include?(:action_mailer)
- end
+ ActionController::Base.view_paths.load! if configuration.frameworks.include?(:action_controller)
+ ActionMailer::Base.view_paths.load! if configuration.frameworks.include?(:action_mailer)
end
end
@@ -481,7 +478,7 @@ Run `rake gems:install` to install the missing gems.
# set to use Configuration#view_path.
def initialize_framework_views
if configuration.frameworks.include?(:action_view)
- view_path = ActionView::Template::Path.new(configuration.view_path)
+ view_path = ActionView::PathSet.type_cast(configuration.view_path)
ActionMailer::Base.template_root ||= view_path if configuration.frameworks.include?(:action_mailer)
ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty?
end
diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb
index be81bdf4fa..bc0184c43d 100644
--- a/railties/lib/rails/plugin/loader.rb
+++ b/railties/lib/rails/plugin/loader.rb
@@ -175,7 +175,7 @@ module Rails
def ensure_all_registered_plugins_are_loaded!
if explicit_plugin_loading_order?
if configuration.plugins.detect {|plugin| plugin != :all && !loaded?(plugin) }
- missing_plugins = configuration.plugins - (plugins + [:all])
+ missing_plugins = configuration.plugins - (plugins.map{|p| p.name.to_sym} + [:all])
raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence}"
end
end
diff --git a/railties/lib/rails_generator/generators/applications/app/template_runner.rb b/railties/lib/rails_generator/generators/applications/app/template_runner.rb
index 84e36ecc1b..eeb6b17661 100644
--- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb
+++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb
@@ -75,7 +75,7 @@ module Rails
end
elsif options[:git] || options[:svn]
in_root do
- run("script/plugin install #{options[:svn] || options[:git]}", false)
+ run_ruby_script("script/plugin install #{options[:svn] || options[:git]}", false)
end
else
log "! no git or svn provided for #{name}. skipping..."
@@ -220,7 +220,7 @@ module Rails
log 'generating', what
argument = args.map(&:to_s).flatten.join(" ")
- in_root { run("script/generate #{what} #{argument}", false) }
+ in_root { run_ruby_script("script/generate #{what} #{argument}", false) }
end
# Executes a command
@@ -236,6 +236,12 @@ module Rails
`#{command}`
end
+ # Executes a ruby script (taking into account WIN32 platform quirks)
+ def run_ruby_script(command, log_action = true)
+ ruby_command = RUBY_PLATFORM=~ /win32/ ? 'ruby ' : ''
+ run("#{ruby_command}#{command}", log_action)
+ end
+
# Runs the supplied rake task
#
# ==== Example
diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb
index 2d9d635944..cd2fc578bf 100644
--- a/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb
+++ b/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb
@@ -21,23 +21,23 @@ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
end
test "should show <%= file_name %>" do
- get :show, :id => <%= table_name %>(:one).id
+ get :show, :id => <%= table_name %>(:one).to_param
assert_response :success
end
test "should get edit" do
- get :edit, :id => <%= table_name %>(:one).id
+ get :edit, :id => <%= table_name %>(:one).to_param
assert_response :success
end
test "should update <%= file_name %>" do
- put :update, :id => <%= table_name %>(:one).id, :<%= file_name %> => { }
+ put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
end
test "should destroy <%= file_name %>" do
assert_difference('<%= class_name %>.count', -1) do
- delete :destroy, :id => <%= table_name %>(:one).id
+ delete :destroy, :id => <%= table_name %>(:one).to_param
end
assert_redirected_to <%= table_name %>_path
diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb
index 43736ee7ec..a950fc8b7e 100644
--- a/railties/test/abstract_unit.rb
+++ b/railties/test/abstract_unit.rb
@@ -18,3 +18,11 @@ if defined?(RAILS_ROOT)
else
RAILS_ROOT = File.dirname(__FILE__)
end
+
+def uses_gem(gem_name, test_name, version = '> 0')
+ gem gem_name.to_s, version
+ require gem_name.to_s
+ yield
+rescue LoadError
+ $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
+end
diff --git a/railties/test/error_page_test.rb b/railties/test/error_page_test.rb
deleted file mode 100644
index f819e468e8..0000000000
--- a/railties/test/error_page_test.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-require 'abstract_unit'
-require 'action_controller'
-require 'action_controller/test_case'
-
-RAILS_ENV = "test"
-CURRENT_DIR = File.expand_path(File.dirname(__FILE__))
-HTML_DIR = File.expand_path(File.join(CURRENT_DIR, "..", "html"))
-
-module Rails
- def self.public_path
- CURRENT_DIR
- end
-end
-
-class ErrorPageController < ActionController::Base
- def crash
- raise StandardError, "crash!"
- end
-end
-
-ActionController::Routing::Routes.draw do |map|
- map.connect ':controller/:action/:id'
-end
-
-class ErrorPageControllerTest < ActionController::TestCase
- def setup
- ActionController::Base.consider_all_requests_local = false
- rescue_action_in_public!
- end
-
- def test_500_error_page_instructs_system_administrator_to_check_log_file
- template = ERB.new(File.read(File.join(HTML_DIR, "500.html")))
- File.open(File.join(CURRENT_DIR, "500.html"), "w") do |f|
- f.write(template.result)
- end
- get :crash
- expected_log_file = "#{RAILS_ENV}.log"
- assert_not_nil @response.body.index(expected_log_file), @response.body
- end
-end
diff --git a/railties/test/fcgi_dispatcher_test.rb b/railties/test/fcgi_dispatcher_test.rb
index c469c5dd01..c7a7f77118 100644
--- a/railties/test/fcgi_dispatcher_test.rb
+++ b/railties/test/fcgi_dispatcher_test.rb
@@ -1,9 +1,12 @@
require 'abstract_unit'
-begin
+uses_gem "fcgi", "0.8.7" do
+
require 'action_controller'
require 'fcgi_handler'
+Dispatcher.middleware.clear
+
class RailsFCGIHandlerTest < Test::Unit::TestCase
def setup
@log = StringIO.new
@@ -11,14 +14,14 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase
end
def test_process_restart
- cgi = mock
- FCGI.stubs(:each_cgi).yields(cgi)
+ request = mock
+ FCGI.stubs(:each).yields(request)
@handler.expects(:process_request).once
@handler.expects(:dispatcher_error).never
@handler.expects(:when_ready).returns(:restart)
- @handler.expects(:close_connection).with(cgi)
+ @handler.expects(:close_connection).with(request)
@handler.expects(:reload!).never
@handler.expects(:restart!)
@@ -26,14 +29,14 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase
end
def test_process_exit
- cgi = mock
- FCGI.stubs(:each_cgi).yields(cgi)
+ request = mock
+ FCGI.stubs(:each).yields(request)
@handler.expects(:process_request).once
@handler.expects(:dispatcher_error).never
@handler.expects(:when_ready).returns(:exit)
- @handler.expects(:close_connection).with(cgi)
+ @handler.expects(:close_connection).with(request)
@handler.expects(:reload!).never
@handler.expects(:restart!).never
@@ -41,8 +44,8 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase
end
def test_process_with_system_exit_exception
- cgi = mock
- FCGI.stubs(:each_cgi).yields(cgi)
+ request = mock
+ FCGI.stubs(:each).yields(request)
@handler.expects(:process_request).once.raises(SystemExit)
@handler.stubs(:dispatcher_log)
@@ -110,9 +113,9 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase
end
def test_uninterrupted_processing
- cgi = mock
- FCGI.expects(:each_cgi).yields(cgi)
- @handler.expects(:process_request).with(cgi)
+ request = mock
+ FCGI.expects(:each).yields(request)
+ @handler.expects(:process_request).with(request)
@handler.process!
@@ -138,8 +141,8 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
end
def test_interrupted_via_HUP_when_not_in_request
- cgi = mock
- FCGI.expects(:each_cgi).once.yields(cgi)
+ request = mock
+ FCGI.expects(:each).once.yields(request)
@handler.expects(:signal).times(2).returns('HUP')
@handler.expects(:reload!).once
@@ -151,13 +154,13 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
end
def test_interrupted_via_USR1_when_not_in_request
- cgi = mock
- FCGI.expects(:each_cgi).once.yields(cgi)
+ request = mock
+ FCGI.expects(:each).once.yields(request)
@handler.expects(:signal).times(2).returns('USR1')
@handler.expects(:exit_handler).never
@handler.expects(:reload!).never
- @handler.expects(:close_connection).with(cgi).once
+ @handler.expects(:close_connection).with(request).once
@handler.expects(:exit).never
@handler.process!
@@ -165,13 +168,13 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
end
def test_restart_via_USR2_when_in_request
- cgi = mock
- FCGI.expects(:each_cgi).once.yields(cgi)
+ request = mock
+ FCGI.expects(:each).once.yields(request)
@handler.expects(:signal).times(2).returns('USR2')
@handler.expects(:exit_handler).never
@handler.expects(:reload!).never
- @handler.expects(:close_connection).with(cgi).once
+ @handler.expects(:close_connection).with(request).once
@handler.expects(:exit).never
@handler.expects(:restart!).once
@@ -180,8 +183,8 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
end
def test_interrupted_via_TERM
- cgi = mock
- FCGI.expects(:each_cgi).once.yields(cgi)
+ request = mock
+ FCGI.expects(:each).once.yields(request)
::Rack::Handler::FastCGI.expects(:serve).once.returns('TERM')
@handler.expects(:reload!).never
@@ -193,16 +196,16 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
def test_runtime_exception_in_fcgi
error = RuntimeError.new('foo')
- FCGI.expects(:each_cgi).times(2).raises(error)
+ FCGI.expects(:each).times(2).raises(error)
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^retrying/))
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/))
@handler.process!
end
def test_runtime_error_in_dispatcher
- cgi = mock
+ request = mock
error = RuntimeError.new('foo')
- FCGI.expects(:each_cgi).once.yields(cgi)
+ FCGI.expects(:each).once.yields(request)
::Rack::Handler::FastCGI.expects(:serve).once.raises(error)
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^unhandled/))
@handler.process!
@@ -210,15 +213,15 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
def test_signal_exception_in_fcgi
error = SignalException.new('USR2')
- FCGI.expects(:each_cgi).once.raises(error)
+ FCGI.expects(:each).once.raises(error)
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/))
@handler.process!
end
def test_signal_exception_in_dispatcher
- cgi = mock
+ request = mock
error = SignalException.new('USR2')
- FCGI.expects(:each_cgi).once.yields(cgi)
+ FCGI.expects(:each).once.yields(request)
::Rack::Handler::FastCGI.expects(:serve).once.raises(error)
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/))
@handler.process!
@@ -247,9 +250,8 @@ class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase
@handler = RailsFCGIHandler.new(@log, 10)
assert_equal 10, @handler.gc_request_period
- cgi = mock
- FCGI.expects(:each_cgi).times(10).yields(cgi)
- Dispatcher.expects(:new).times(10)
+ request = mock
+ FCGI.expects(:each).times(10).yields(request)
@handler.expects(:run_gc!).never
9.times { @handler.process! }
@@ -259,7 +261,4 @@ class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase
assert_nil @handler.when_ready
end
end
-
-rescue LoadError => e
- raise unless e.message =~ /fcgi/
-end
+end # uses_gem "fcgi"
diff --git a/railties/test/generators/rails_template_runner_test.rb b/railties/test/generators/rails_template_runner_test.rb
index fcc020603d..56afc85eba 100644
--- a/railties/test/generators/rails_template_runner_test.rb
+++ b/railties/test/generators/rails_template_runner_test.rb
@@ -53,12 +53,12 @@ class RailsTemplateRunnerTest < GeneratorTestCase
end
def test_plugin_with_git_option_should_run_plugin_install
- expects_run_with_command("script/plugin install #{@git_plugin_uri}")
+ expects_run_ruby_script_with_command("script/plugin install #{@git_plugin_uri}")
run_template_method(:plugin, 'restful-authentication', :git => @git_plugin_uri)
end
def test_plugin_with_svn_option_should_run_plugin_install
- expects_run_with_command("script/plugin install #{@svn_plugin_uri}")
+ expects_run_ruby_script_with_command("script/plugin install #{@svn_plugin_uri}")
run_template_method(:plugin, 'restful-authentication', :svn => @svn_plugin_uri)
end
@@ -127,7 +127,7 @@ class RailsTemplateRunnerTest < GeneratorTestCase
end
def test_generate_should_run_script_generate_with_argument_and_options
- expects_run_with_command('script/generate model MyModel')
+ expects_run_ruby_script_with_command('script/generate model MyModel')
run_template_method(:generate, 'model', 'MyModel')
end
@@ -162,6 +162,12 @@ class RailsTemplateRunnerTest < GeneratorTestCase
assert_generated_file_with_data 'config/routes.rb', route_command
end
+ def test_run_ruby_script_should_add_ruby_to_command_in_win32_environment
+ ruby_command = RUBY_PLATFORM =~ /win32/ ? 'ruby ' : ''
+ expects_run_with_command("#{ruby_command}script/generate model MyModel")
+ run_template_method(:generate, 'model', 'MyModel')
+ end
+
protected
def run_template_method(method_name, *args, &block)
silence_generator do
@@ -174,6 +180,10 @@ class RailsTemplateRunnerTest < GeneratorTestCase
Rails::TemplateRunner.any_instance.stubs(:run).once.with(command, false)
end
+ def expects_run_ruby_script_with_command(command)
+ Rails::TemplateRunner.any_instance.stubs(:run_ruby_script).once.with(command,false)
+ end
+
def assert_rails_initializer_includes(data, message = nil)
message ||= "Rails::Initializer should include #{data}"
assert_generated_file 'config/environment.rb' do |body|
diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb
index 39372dc5ab..2ab4101eaf 100644
--- a/railties/test/initializer_test.rb
+++ b/railties/test/initializer_test.rb
@@ -238,6 +238,26 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase
end
end
+ def test_load_error_messages_mention_missing_plugins_and_no_others
+ valid_plugin_names = [:stubby, :acts_as_chunky_bacon]
+ invalid_plugin_names = [:non_existant_plugin1, :non_existant_plugin2]
+ only_load_the_following_plugins!( valid_plugin_names + invalid_plugin_names )
+ begin
+ load_plugins!
+ flunk "Expected a LoadError but did not get one"
+ rescue LoadError => e
+ failure_tip = "It's likely someone renamed or deleted plugin fixtures without updating this test"
+ assert_plugins valid_plugin_names, @initializer.loaded_plugins, failure_tip
+ invalid_plugin_names.each do |plugin|
+ assert_match(/#{plugin.to_s}/, e.message, "LoadError message should mention plugin '#{plugin}'")
+ end
+ valid_plugin_names.each do |plugin|
+ assert_no_match(/#{plugin.to_s}/, e.message, "LoadError message should not mention '#{plugin}'")
+ end
+
+ end
+ end
+
def test_should_ensure_all_loaded_plugins_load_paths_are_added_to_the_load_path
only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb
index 23b81ddbf6..59491fe99e 100644
--- a/railties/test/plugin_loader_test.rb
+++ b/railties/test/plugin_loader_test.rb
@@ -130,7 +130,7 @@ class TestPluginLoader < Test::Unit::TestCase
@loader.send :add_engine_view_paths
- assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionController::Base.view_paths
+ assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views').sub(/\A\.\//, '') ], ActionController::Base.view_paths
end
def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths