aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2009-12-22 17:03:23 -0800
committerCarlhuda <carlhuda@engineyard.com>2009-12-23 15:16:38 -0800
commitdc677f7665e5ec74b5a313ba656bba19dc0f853d (patch)
tree589200f34212e8944621ce03d7323e9bbd6771eb /railties
parent24e1b5560806be54a931922f109f50800dcbbdf5 (diff)
downloadrails-dc677f7665e5ec74b5a313ba656bba19dc0f853d.tar.gz
rails-dc677f7665e5ec74b5a313ba656bba19dc0f853d.tar.bz2
rails-dc677f7665e5ec74b5a313ba656bba19dc0f853d.zip
tests pass with requiring the frameworks in rails.rb
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails.rb42
-rw-r--r--railties/lib/rails/application.rb58
-rw-r--r--railties/lib/rails/core.rb34
-rw-r--r--railties/test/application/configuration_test.rb41
-rw-r--r--railties/test/application/generators_test.rb30
-rw-r--r--railties/test/application/initializer_test.rb26
-rw-r--r--railties/test/application/load_test.rb2
-rw-r--r--railties/test/isolation/abstract_unit.rb8
8 files changed, 123 insertions, 118 deletions
diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb
index 85aeb4af24..9fb3cd9f94 100644
--- a/railties/lib/rails.rb
+++ b/railties/lib/rails.rb
@@ -1,33 +1,9 @@
-require "pathname"
-
-require 'active_support'
-require 'active_support/core_ext/kernel/reporting'
-require 'active_support/core_ext/logger'
-require 'action_dispatch'
-
-require 'rails/initializable'
-require 'rails/application'
-require 'rails/plugin'
-require 'rails/railties_path'
-require 'rails/version'
-require 'rails/rack'
-require 'rails/paths'
-require 'rails/core'
-require 'rails/configuration'
-require 'rails/deprecation'
-require 'rails/initializer'
-require 'rails/ruby_version_check'
-
-# For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the
-# multibyte safe operations. Plugin authors supporting other encodings
-# should override this behaviour and set the relevant +default_charset+
-# on ActionController::Base.
-#
-# For Ruby 1.9, UTF-8 is the default internal and external encoding.
-if RUBY_VERSION < '1.9'
- $KCODE='u'
-else
- Encoding.default_external = Encoding::UTF_8
-end
-
-RAILS_ENV = (ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development").dup unless defined?(RAILS_ENV)
+require "rails/core"
+
+%w(active_model active_record action_controller action_view action_mailer active_resource).each do |framework|
+ begin
+ require framework
+ require "#{framework}/rails"
+ rescue LoadError
+ end
+end \ No newline at end of file
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index d7a89ba2be..97f72b106b 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -1,3 +1,5 @@
+require "fileutils"
+
module Rails
class Application
include Initializable
@@ -140,13 +142,13 @@ module Rails
$LOAD_PATH.uniq!
end
- # Requires all frameworks specified by the Configuration#frameworks
- # list. By default, all frameworks (Active Record, Active Support,
- # Action Pack, Action Mailer, and Active Resource) are loaded.
- initializer :require_frameworks do
- require 'active_support/all' unless config.active_support.bare
- config.frameworks.each { |framework| require(framework.to_s) }
- end
+ # # Requires all frameworks specified by the Configuration#frameworks
+ # # list. By default, all frameworks (Active Record, Active Support,
+ # # Action Pack, Action Mailer, and Active Resource) are loaded.
+ # initializer :require_frameworks do
+ # require 'active_support/all' unless config.active_support.bare
+ # config.frameworks.each { |framework| require(framework.to_s) }
+ # end
# Set the paths from which Rails will automatically load source files, and
# the load_once paths.
@@ -192,7 +194,7 @@ module Rails
# this sets the database configuration from Configuration#database_configuration
# and then establishes the connection.
initializer :initialize_database do
- if config.frameworks.include?(:active_record)
+ if defined?(ActiveRecord)
ActiveRecord::Base.configurations = config.database_configuration
ActiveRecord::Base.establish_connection
end
@@ -206,7 +208,7 @@ module Rails
end
initializer :initialize_middleware_stack do
- if config.frameworks.include?(:action_controller)
+ if defined?(ActionController)
config.middleware.use(::Rack::Lock, :if => lambda { ActionController::Base.allow_concurrency })
config.middleware.use(::Rack::Runtime)
config.middleware.use(ActionDispatch::ShowExceptions, lambda { ActionController::Base.consider_all_requests_local })
@@ -231,7 +233,7 @@ module Rails
end
initializer :initialize_framework_caches do
- if config.frameworks.include?(:action_controller)
+ if defined?(ActionController)
ActionController::Base.cache_store ||= RAILS_CACHE
end
end
@@ -266,8 +268,12 @@ module Rails
# logger is already set, it is not changed, otherwise it is set to use
# RAILS_DEFAULT_LOGGER.
initializer :initialize_framework_logging do
- for framework in ([ :active_record, :action_controller, :action_mailer ] & config.frameworks)
- framework.to_s.camelize.constantize.const_get("Base").logger ||= Rails.logger
+ for framework in [ :active_record, :action_controller, :action_mailer ]
+ # TODO BEFORE PUSHING: REMOVEZ
+ begin
+ framework.to_s.camelize.constantize.const_get("Base").logger ||= Rails.logger
+ rescue Exception
+ end
end
ActiveSupport::Dependencies.logger ||= Rails.logger
@@ -302,7 +308,7 @@ module Rails
Time.zone_default = zone_default
- if config.frameworks.include?(:active_record)
+ if defined?(ActiveRecord)
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.default_timezone = :utc
end
@@ -326,10 +332,14 @@ module Rails
# on each of the corresponding Base classes.
initializer :initialize_framework_settings do
config.frameworks.each do |framework|
- base_class = framework.to_s.camelize.constantize.const_get("Base")
+ # TODO BEFORE PUSHING: This needs to work differently
+ begin
+ base_class = framework.to_s.camelize.constantize.const_get("Base")
- config.send(framework).each do |setting, value|
- base_class.send("#{setting}=", value)
+ config.send(framework).each do |setting, value|
+ base_class.send("#{setting}=", value)
+ end
+ rescue Exception
end
end
end
@@ -339,16 +349,16 @@ module Rails
# paths have already been set, it is not changed, otherwise it is
# set to use Configuration#view_path.
initializer :initialize_framework_views do
- if config.frameworks.include?(:action_view)
+ if defined?(ActionView)
view_path = ActionView::PathSet.type_cast(config.view_path, config.cache_classes)
- ActionMailer::Base.template_root = view_path if config.frameworks.include?(:action_mailer) && ActionMailer::Base.view_paths.blank?
- ActionController::Base.view_paths = view_path if config.frameworks.include?(:action_controller) && ActionController::Base.view_paths.blank?
+
+ ActionMailer::Base.template_root = view_path if defined?(ActionMailer) && ActionMailer::Base.view_paths.blank?
+ ActionController::Base.view_paths = view_path if defined?(ActionController) && ActionController::Base.view_paths.blank?
end
end
initializer :initialize_metal do
- # TODO: Make Rails and metal work without ActionController
- if config.frameworks.include?(:action_controller)
+ if defined?(ActionController)
Rails::Rack::Metal.requested_metals = config.metals
config.middleware.insert_before(
@@ -375,8 +385,8 @@ module Rails
# # Setup database middleware after initializers have run
initializer :initialize_database_middleware do
- if configuration.frameworks.include?(:active_record)
- if configuration.frameworks.include?(:action_controller) && ActionController::Base.session_store &&
+ if defined?(ActiveRecord)
+ if defined?(ActionController) && ActionController::Base.session_store &&
ActionController::Base.session_store.name == 'ActiveRecord::SessionStore'
configuration.middleware.insert_before :"ActiveRecord::SessionStore", ActiveRecord::ConnectionAdapters::ConnectionManagement
configuration.middleware.insert_before :"ActiveRecord::SessionStore", ActiveRecord::QueryCache
@@ -422,7 +432,7 @@ module Rails
#
# # Observers are loaded after plugins in case Observers or observed models are modified by plugins.
initializer :load_observers do
- if configuration.frameworks.include?(:active_record)
+ if defined?(ActiveRecord)
ActiveRecord::Base.instantiate_observers
end
end
diff --git a/railties/lib/rails/core.rb b/railties/lib/rails/core.rb
index a5e51ad04a..da16c5816c 100644
--- a/railties/lib/rails/core.rb
+++ b/railties/lib/rails/core.rb
@@ -1,3 +1,37 @@
+require "pathname"
+
+require 'active_support'
+require 'active_support/core_ext/kernel/reporting'
+require 'active_support/core_ext/logger'
+require 'action_dispatch'
+
+require 'rails/initializable'
+require 'rails/application'
+require 'rails/plugin'
+require 'rails/railties_path'
+require 'rails/version'
+require 'rails/rack'
+require 'rails/paths'
+require 'rails/core'
+require 'rails/configuration'
+require 'rails/deprecation'
+require 'rails/initializer'
+require 'rails/ruby_version_check'
+
+# For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the
+# multibyte safe operations. Plugin authors supporting other encodings
+# should override this behaviour and set the relevant +default_charset+
+# on ActionController::Base.
+#
+# For Ruby 1.9, UTF-8 is the default internal and external encoding.
+if RUBY_VERSION < '1.9'
+ $KCODE='u'
+else
+ Encoding.default_external = Encoding::UTF_8
+end
+
+RAILS_ENV = (ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development").dup unless defined?(RAILS_ENV)
+
module Rails
# Needs to be duplicated from Active Support since its needed before Active
# Support is available. Here both Options and Hash are namespaced to prevent
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 83e1401993..0f702c7014 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -4,7 +4,16 @@ module ApplicationTests
class InitializerTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
+ def new_app
+ File.expand_path("#{app_path}/../new_app")
+ end
+
+ def copy_app
+ FileUtils.cp_r(app_path, new_app)
+ end
+
def setup
+ FileUtils.rm_rf(new_app) if File.directory?(new_app)
build_app
boot_rails
end
@@ -15,42 +24,36 @@ module ApplicationTests
end
test "the application root can be set" do
- FileUtils.mkdir_p("#{app_path}/hello")
+ copy_app
add_to_config <<-RUBY
- config.frameworks = []
- config.root = '#{app_path}/hello'
+ config.root = '#{new_app}'
RUBY
- require "#{app_path}/config/environment"
- assert_equal Pathname.new("#{app_path}/hello"), Rails.application.root
- end
- test "the application root is detected as where config.ru is located" do
- add_to_config <<-RUBY
- config.frameworks = []
- RUBY
- FileUtils.mv "#{app_path}/config.ru", "#{app_path}/config/config.ru"
+ use_frameworks []
+
require "#{app_path}/config/environment"
- assert_equal Pathname.new("#{app_path}/config"), Rails.application.root
+ assert_equal Pathname.new(new_app), Rails.application.root
end
test "the application root is Dir.pwd if there is no config.ru" do
File.delete("#{app_path}/config.ru")
- add_to_config <<-RUBY
- config.frameworks = []
- RUBY
- Dir.chdir("#{app_path}/app") do
+ use_frameworks []
+
+ Dir.chdir("#{app_path}") do
require "#{app_path}/config/environment"
- assert_equal Pathname.new("#{app_path}/app"), Rails.application.root
+ assert_equal Pathname.new("#{app_path}"), Rails.application.root
end
end
test "config.active_support.bare does not require all of ActiveSupport" do
- add_to_config "config.frameworks = []; config.active_support.bare = true"
+ add_to_config "config.active_support.bare = true"
+
+ use_frameworks []
Dir.chdir("#{app_path}/app") do
require "#{app_path}/config/environment"
- assert_raises(NoMethodError) { 1.day }
+ assert_raises(NoMethodError) { [1,2,3].rand }
end
end
diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb
index 2ed49d1057..7b27c780aa 100644
--- a/railties/test/application/generators_test.rb
+++ b/railties/test/application/generators_test.rb
@@ -7,8 +7,6 @@ module ApplicationTests
def setup
build_app
boot_rails
- require "rails"
- require "rails/generators"
end
def app_const
@@ -16,6 +14,8 @@ module ApplicationTests
end
def with_config
+ require "rails"
+ require "rails/generators"
yield app_const.config
end
@@ -46,14 +46,15 @@ module ApplicationTests
end
test "generators aliases and options on initialization" do
- application = with_config do |c|
- c.frameworks = []
- c.generators.rails :aliases => { :test_framework => "-w" }
- c.generators.orm :datamapper
- c.generators.test_framework :rspec
- end
+ add_to_config <<-RUBY
+ config.generators.rails :aliases => { :test_framework => "-w" }
+ config.generators.orm :datamapper
+ config.generators.test_framework :rspec
+ RUBY
+
+ require "#{app_path}/config/environment"
# Initialize the application
- app_const.initialize!
+ require "rails/generators"
Rails::Generators.configure!
assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
@@ -61,12 +62,13 @@ module ApplicationTests
end
test "generators no color on initialization" do
- with_config do |c|
- c.frameworks = []
- c.generators.colorize_logging = false
- end
+ add_to_config <<-RUBY
+ config.generators.colorize_logging = false
+ RUBY
+
# Initialize the application
- app_const.initialize!
+ require "#{app_path}/config/environment"
+ require "rails/generators"
Rails::Generators.configure!
assert_equal Thor::Base.shell, Thor::Shell::Basic
diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb
index b3eff1deb9..8ed8e11c8f 100644
--- a/railties/test/application/initializer_test.rb
+++ b/railties/test/application/initializer_test.rb
@@ -19,19 +19,6 @@ module ApplicationTests
assert $:.include?("#{app_path}/app/models")
end
- test "adding an unknown framework raises an error" do
- add_to_config <<-RUBY
- config.root = "#{app_path}"
- config.frameworks << :action_foo
- RUBY
-
- require "active_support/core_ext/load_error"
-
- assert_raises MissingSourceFile do
- require "#{app_path}/config/environment"
- end
- end
-
test "eager loading loads parent classes before children" do
app_file "lib/zoo.rb", <<-ZOO
class Zoo ; include ReptileHouse ; end
@@ -180,19 +167,6 @@ module ApplicationTests
assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore)
end
-
- # Pathview test
- test "load view paths doesn't perform anything when action_view not in frameworks" do
- add_to_config <<-RUBY
- config.root = "#{app_path}"
- config.frameworks -= [:action_view]
- RUBY
- require "#{app_path}/config/environment"
-
- assert_equal nil, ActionMailer::Base.template_root
- assert_equal [], ActionController::Base.view_paths
- end
-
test "Rails.root should be a Pathname" do
add_to_config <<-RUBY
config.root = "#{app_path}"
diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb
index e17f1ebdb0..689bc77ecf 100644
--- a/railties/test/application/load_test.rb
+++ b/railties/test/application/load_test.rb
@@ -1,6 +1,4 @@
require "isolation/abstract_unit"
-# require "rails"
-# require 'action_dispatch'
module ApplicationTests
class LoadTest < Test::Unit::TestCase
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index c169c80bea..ee0a812b47 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -153,6 +153,14 @@ module TestHelpers
app_file("app/controllers/#{name}_controller.rb", contents)
end
+ def use_frameworks(arr)
+ to_remove = [:actionmailer,
+ :activemodel,
+ :activerecord,
+ :activeresource] - arr
+ $:.reject! {|path| path =~ %r'/(#{to_remove.join('|')})/' }
+ end
+
def boot_rails
root = File.expand_path('../../../..', __FILE__)
begin