aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-02-22 23:52:02 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-02-22 23:52:02 +0100
commit21b80f8144f8f05a105b2989c79d3ed2f2d0d4cd (patch)
treebfec5946303ceb582674904c5f9927e9b4020272 /railties
parent91ab75373f13054485f5d804d7e2c80d466ff5e0 (diff)
parent441e4e22352c8805a882f6a661ab3982dd7eda12 (diff)
downloadrails-21b80f8144f8f05a105b2989c79d3ed2f2d0d4cd.tar.gz
rails-21b80f8144f8f05a105b2989c79d3ed2f2d0d4cd.tar.bz2
rails-21b80f8144f8f05a105b2989c79d3ed2f2d0d4cd.zip
Merge commit 'mainstream/master'
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/console_app.rb3
-rw-r--r--railties/lib/initializer.rb14
-rw-r--r--railties/lib/rails/plugin/loader.rb50
-rw-r--r--railties/lib/tasks/gems.rake4
-rw-r--r--railties/test/initializer_test.rb5
-rw-r--r--railties/test/plugin_loader_test.rb9
6 files changed, 47 insertions, 38 deletions
diff --git a/railties/lib/console_app.rb b/railties/lib/console_app.rb
index a35c96c957..d7cd57564f 100644
--- a/railties/lib/console_app.rb
+++ b/railties/lib/console_app.rb
@@ -24,7 +24,6 @@ end
#reloads the environment
def reload!
puts "Reloading..."
- dispatcher = ActionController::Dispatcher.new($stdout)
- dispatcher.reload_application
+ Dispatcher.reload_application
true
end
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index a8b951ae58..a31ae9422e 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -167,6 +167,10 @@ module Rails
load_gems
check_gem_dependencies
+ # bail out if gems are missing - note that check_gem_dependencies will have
+ # already called abort() unless $gems_rake_task is set
+ return unless gems_dependencies_loaded
+
load_application_initializers
# the framework is now fully initialized
@@ -302,7 +306,7 @@ module Rails
if unloaded_gems.size > 0
@gems_dependencies_loaded = false
# don't print if the gems rake tasks are being run
- unless $rails_rake_task
+ unless $gems_rake_task
abort <<-end_error
Missing these required gems:
#{unloaded_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "}
@@ -479,8 +483,8 @@ Run `rake gems:install` to install the missing gems.
def initialize_framework_views
if configuration.frameworks.include?(:action_view)
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?
+ ActionMailer::Base.template_root = view_path if configuration.frameworks.include?(:action_mailer) && ActionMailer::Base.view_paths.blank?
+ ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.blank?
end
end
@@ -492,7 +496,7 @@ Run `rake gems:install` to install the missing gems.
ActionController::Routing.controller_paths += configuration.controller_paths
ActionController::Routing::Routes.add_configuration_file(configuration.routes_configuration_file)
- ActionController::Routing::Routes.reload
+ ActionController::Routing::Routes.reload!
end
# Sets the dependency loading mechanism based on the value of
@@ -583,7 +587,7 @@ Run `rake gems:install` to install the missing gems.
return unless configuration.frameworks.include?(:action_controller)
require 'dispatcher' unless defined?(::Dispatcher)
Dispatcher.define_dispatcher_callbacks(configuration.cache_classes)
- Dispatcher.new(Rails.logger).send :run_callbacks, :prepare_dispatch
+ Dispatcher.run_prepare_callbacks
end
def disable_dependency_loading
diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb
index bc0184c43d..7f85bb8966 100644
--- a/railties/lib/rails/plugin/loader.rb
+++ b/railties/lib/rails/plugin/loader.rb
@@ -16,7 +16,7 @@ module Rails
def initialize(initializer)
@initializer = initializer
end
-
+
# Returns the plugins to be loaded, in the order they should be loaded.
def plugins
@plugins ||= all_plugins.select { |plugin| should_load?(plugin) }.sort { |p1, p2| order_plugins(p1, p2) }
@@ -32,9 +32,9 @@ module Rails
@all_plugins ||= locate_plugins
@all_plugins
end
-
+
def load_plugins
- plugins.each do |plugin|
+ plugins.each do |plugin|
plugin.load(initializer)
register_plugin_as_loaded(plugin)
end
@@ -43,12 +43,12 @@ module Rails
ensure_all_registered_plugins_are_loaded!
end
-
+
# Adds the load paths for every plugin into the $LOAD_PATH. Plugin load paths are
# added *after* the application's <tt>lib</tt> directory, to ensure that an application
# can always override code within a plugin.
#
- # Plugin load paths are also added to Dependencies.load_paths, and Dependencies.load_once_paths.
+ # Plugin load paths are also added to Dependencies.load_paths, and Dependencies.load_once_paths.
def add_plugin_load_paths
plugins.each do |plugin|
plugin.load_paths.each do |path|
@@ -56,7 +56,7 @@ module Rails
ActiveSupport::Dependencies.load_paths << path
- unless Rails.configuration.reload_plugins?
+ unless configuration.reload_plugins?
ActiveSupport::Dependencies.load_once_paths << path
end
end
@@ -64,8 +64,8 @@ module Rails
$LOAD_PATH.uniq!
end
-
-
+
+
protected
def configure_engines
if engines.any?
@@ -74,20 +74,22 @@ module Rails
add_engine_view_paths
end
end
-
+
def add_engine_routing_configurations
engines.select(&:routed?).collect(&:routing_file).each do |routing_file|
ActionController::Routing::Routes.add_configuration_file(routing_file)
end
end
-
+
def add_engine_controller_paths
ActionController::Routing.controller_paths += engines.collect(&:controller_path)
end
-
+
def add_engine_view_paths
# reverse it such that the last engine can overwrite view paths from the first, like with routes
- ActionController::Base.view_paths += ActionView::PathSet.new(engines.collect(&:view_path).reverse)
+ paths = ActionView::PathSet.new(engines.collect(&:view_path).reverse)
+ ActionController::Base.view_paths.concat(paths)
+ ActionMailer::Base.view_paths.concat(paths) if configuration.frameworks.include?(:action_mailer)
end
# The locate_plugins method uses each class in config.plugin_locators to
@@ -106,7 +108,7 @@ module Rails
def configuration
initializer.configuration
end
-
+
def should_load?(plugin)
# uses Plugin#name and Plugin#valid?
enabled?(plugin) && plugin.valid?
@@ -120,21 +122,21 @@ module Rails
plugin_a <=> plugin_b
else
effective_order_of(plugin_a) <=> effective_order_of(plugin_b)
- end
+ end
end
end
-
+
def effective_order_of(plugin)
if explicitly_enabled?(plugin)
- registered_plugin_names.index(plugin.name)
+ registered_plugin_names.index(plugin.name)
else
registered_plugin_names.index('all')
- end
+ end
end
def application_lib_index
$LOAD_PATH.index(File.join(RAILS_ROOT, 'lib')) || 0
- end
+ end
def enabled?(plugin)
!explicit_plugin_loading_order? || registered?(plugin)
@@ -155,23 +157,23 @@ module Rails
def explicitly_registered?(plugin)
explicit_plugin_loading_order? && registered_plugin_names.include?(plugin.name)
end
-
+
def registered_plugins_names_plugin?(plugin)
registered_plugin_names.include?(plugin.name) || registered_plugin_names.include?('all')
end
-
+
# The plugins that have been explicitly listed with config.plugins. If this list is nil
- # then it means the client does not care which plugins or in what order they are loaded,
+ # then it means the client does not care which plugins or in what order they are loaded,
# so we load all in alphabetical order. If it is an empty array, we load no plugins, if it is
# non empty, we load the named plugins in the order specified.
def registered_plugin_names
configuration.plugins ? configuration.plugins.map(&:to_s) : nil
end
-
+
def loaded?(plugin_name)
initializer.loaded_plugins.detect { |plugin| plugin.name == plugin_name.to_s }
end
-
+
def ensure_all_registered_plugins_are_loaded!
if explicit_plugin_loading_order?
if configuration.plugins.detect {|plugin| plugin != :all && !loaded?(plugin) }
@@ -180,7 +182,7 @@ module Rails
end
end
end
-
+
end
end
end \ No newline at end of file
diff --git a/railties/lib/tasks/gems.rake b/railties/lib/tasks/gems.rake
index e6731ab78c..d538e52ca6 100644
--- a/railties/lib/tasks/gems.rake
+++ b/railties/lib/tasks/gems.rake
@@ -17,13 +17,13 @@ end
namespace :gems do
task :base do
- $rails_rake_task = true
+ $gems_rake_task = true
Rake::Task[:environment].invoke
end
desc "Build any native extensions for unpacked gems"
task :build do
- $rails_rake_task = true
+ $gems_rake_task = true
require 'rails/gem_builder'
Dir[File.join(Rails::GemDependency.unpacked_path, '*')].each do |gem_dir|
spec_file = File.join(gem_dir, '.specification')
diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb
index 2ab4101eaf..eb9ec750da 100644
--- a/railties/test/initializer_test.rb
+++ b/railties/test/initializer_test.rb
@@ -182,6 +182,7 @@ require File.dirname(__FILE__) + '/plugin_test_helper'
class InitializerPluginLoadingTests < Test::Unit::TestCase
def setup
@configuration = Rails::Configuration.new
+ @configuration.frameworks -= [:action_mailer]
@configuration.plugin_paths << plugin_fixture_root_path
@initializer = Rails::Initializer.new(@configuration)
@valid_plugin_path = plugin_fixture_path('default/stubby')
@@ -310,8 +311,8 @@ class InitializerSetupI18nTests < Test::Unit::TestCase
Rails::Initializer.run(:initialize_i18n, config)
assert_equal [
- File.expand_path("./test/../../activesupport/lib/active_support/locale/en.yml"),
- File.expand_path("./test/../../actionpack/lib/action_view/locale/en.yml"),
+ File.expand_path(File.dirname(__FILE__) + "/../../activesupport/lib/active_support/locale/en.yml"),
+ File.expand_path(File.dirname(__FILE__) + "/../../actionpack/lib/action_view/locale/en.yml"),
"my/test/locale.yml",
"my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /^\./ ? File.expand_path(path) : path }
end
diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb
index 59491fe99e..e802b1ace7 100644
--- a/railties/test/plugin_loader_test.rb
+++ b/railties/test/plugin_loader_test.rb
@@ -1,7 +1,9 @@
require 'plugin_test_helper'
$:.unshift File.dirname(__FILE__) + "/../../actionpack/lib"
+$:.unshift File.dirname(__FILE__) + "/../../actionmailer/lib"
require 'action_controller'
+require 'action_mailer'
# Mocks out the configuration
module Rails
@@ -125,14 +127,15 @@ class TestPluginLoader < Test::Unit::TestCase
end
end
- def test_engine_controllers_should_have_their_view_path_set_when_loaded
+ def test_engine_controllers_and_action_mailers_should_have_their_view_path_set_when_loaded
only_load_the_following_plugins!([ :engine ])
@loader.send :add_engine_view_paths
- assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views').sub(/\A\.\//, '') ], ActionController::Base.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') ], ActionMailer::Base.view_paths
end
-
+
def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths
only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]