aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2007-10-04 04:16:06 +0000
committerMichael Koziarski <michael@koziarski.com>2007-10-04 04:16:06 +0000
commit41bfedeac273d83585d3cdb2f181ae1978d31adb (patch)
tree5c52597365f433acf9f1395388b754302733fb3b /railties
parentb1968708e12972515fdc8eefdcaff95edbebc76b (diff)
downloadrails-41bfedeac273d83585d3cdb2f181ae1978d31adb.tar.gz
rails-41bfedeac273d83585d3cdb2f181ae1978d31adb.tar.bz2
rails-41bfedeac273d83585d3cdb2f181ae1978d31adb.zip
Tidy up framework initialization code to ensure that it doesn't add folders to the load path that it doesn't intend to require.
Work around mongrel swallowing LoadErrors to ensure that users get more helpful errors if active_resource is required but not missing. [mislav] Closes #9743 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7738 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/initializer.rb21
-rw-r--r--railties/test/initializer_test.rb53
2 files changed, 64 insertions, 10 deletions
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index c2862ee443..0256ba96b2 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -152,6 +152,9 @@ module Rails
# ActionPack, ActionMailer, and ActiveResource) are loaded.
def require_frameworks
configuration.frameworks.each { |framework| require(framework.to_s) }
+ rescue LoadError => e
+ # re-raise because Mongrel would swallow it
+ raise e.to_s
end
# Add the load paths used by support functions such as the info controller
@@ -545,16 +548,14 @@ module Rails
end
def framework_paths
- # TODO: Don't include dirs for frameworks that are not used
- %w(
- railties
- railties/lib
- actionpack/lib
- activesupport/lib
- activerecord/lib
- activeresource/lib
- actionmailer/lib
- ).map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
+ paths = %w(railties railties/lib activesupport/lib)
+ paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view
+
+ [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
+ paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework
+ end
+
+ paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
end
private
diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb
index adb02ed472..5707a63258 100644
--- a/railties/test/initializer_test.rb
+++ b/railties/test/initializer_test.rb
@@ -82,3 +82,56 @@ class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit::
end
end
+
+uses_mocha 'framework paths' do
+ class ConfigurationFrameworkPathsTests < Test::Unit::TestCase
+ def setup
+ @config = Rails::Configuration.new
+ @config.frameworks.clear
+
+ File.stubs(:directory?).returns(true)
+ @config.stubs(:framework_root_path).returns('')
+ end
+
+ def test_minimal
+ expected = %w(
+ /railties
+ /railties/lib
+ /activesupport/lib
+ )
+ assert_equal expected, @config.framework_paths
+ end
+
+ def test_actioncontroller_or_actionview_add_actionpack
+ @config.frameworks << :action_controller
+ assert_framework_path '/actionpack/lib'
+
+ @config.frameworks = [:action_view]
+ assert_framework_path '/actionpack/lib'
+ end
+
+ def test_paths_for_ar_ares_and_mailer
+ [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
+ @config.frameworks = [framework]
+ assert_framework_path "/#{framework.to_s.gsub('_', '')}/lib"
+ end
+ end
+
+ def test_unknown_framework_raises_error
+ @config.frameworks << :action_foo
+ initializer = Rails::Initializer.new @config
+ initializer.expects(:require).raises(LoadError)
+
+ assert_raise RuntimeError do
+ initializer.send :require_frameworks
+ end
+ end
+
+ protected
+
+ def assert_framework_path(path)
+ assert @config.framework_paths.include?(path),
+ "<#{path.inspect}> not found among <#{@config.framework_paths.inspect}>"
+ end
+ end
+end