aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2009-10-08 18:12:28 -0700
committerCarl Lerche <carllerche@mac.com>2009-10-14 11:47:37 -0700
commitff8be66f249d49e82c8e1d04cb8cfbbc128deabe (patch)
tree6063bd4d1ff6353eb4cb6ef516c65ee5ce22b283
parent5ffb877d3a5d7fd2266b58495de435dd9c33d4e1 (diff)
downloadrails-ff8be66f249d49e82c8e1d04cb8cfbbc128deabe.tar.gz
rails-ff8be66f249d49e82c8e1d04cb8cfbbc128deabe.tar.bz2
rails-ff8be66f249d49e82c8e1d04cb8cfbbc128deabe.zip
Finish porting over the initializers to the app object and fix all the tests
-rw-r--r--activesupport/lib/active_support/testing/isolation.rb2
-rw-r--r--railties/Rakefile1
-rw-r--r--railties/lib/rails/configuration.rb173
-rw-r--r--railties/test/application/configuration_test.rb17
-rw-r--r--railties/test/application/generators_test.rb2
-rw-r--r--railties/test/generators/generators_test_helper.rb9
6 files changed, 109 insertions, 95 deletions
diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb
index bec303f6ab..c75b59c284 100644
--- a/activesupport/lib/active_support/testing/isolation.rb
+++ b/activesupport/lib/active_support/testing/isolation.rb
@@ -1,5 +1,3 @@
-require 'active_support/core_ext/load_error'
-
module ActiveSupport
module Testing
class ProxyTestResult
diff --git a/railties/Rakefile b/railties/Rakefile
index 23f9603b65..0ba5ca10c2 100644
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -28,6 +28,7 @@ task :default => :test
task :test do
dir = ENV["TEST_DIR"] || "**"
Dir["test/#{dir}/*_test.rb"].all? do |file|
+ next true if file.include?("fixtures")
ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
system(ruby, '-Itest', "-I#{File.dirname(__FILE__)}/../activesupport/lib", file)
end or raise "Failures"
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index 4a70a4800e..b5ac0e3ddc 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -1,6 +1,9 @@
+require 'rails/plugin/loader'
+require 'rails/plugin/locator'
+
module Rails
class Configuration
- attr_accessor :cache_classes, :load_paths, :eager_load_paths, :framework_paths,
+ attr_accessor :cache_classes, :load_paths,
:load_once_paths, :gems_dependencies_loaded, :after_initialize_blocks,
:frameworks, :framework_root_path, :root_path, :plugin_paths, :plugins,
:plugin_loader, :plugin_locators, :gems, :loaded_plugins, :reload_plugins,
@@ -15,29 +18,13 @@ module Rails
def initialize
set_root_path!
- @framework_paths = []
@load_once_paths = []
@after_initialize_blocks = []
@loaded_plugins = []
@dependency_loading = true
- @eager_load_paths = default_eager_load_paths
- @load_paths = default_load_paths
- @plugin_paths = default_plugin_paths
- @frameworks = default_frameworks
- @plugin_loader = default_plugin_loader
- @plugin_locators = default_plugin_locators
- @gems = default_gems
- @i18n = default_i18n
- @log_path = default_log_path
- @log_level = default_log_level
- @cache_store = default_cache_store
- @view_path = default_view_path
- @controller_paths = default_controller_paths
- @routes_configuration_file = default_routes_configuration_file
- @database_configuration_file = default_database_configuration_file
- @serve_static_assets = default_serve_static_assets
-
- for framework in default_frameworks
+ @serve_static_assets = true
+
+ for framework in frameworks
self.send("#{framework}=", Rails::OrderedOptions.new)
end
self.active_support = Rails::OrderedOptions.new
@@ -121,34 +108,38 @@ module Rails
YAML::load(ERB.new(IO.read(database_configuration_file)).result)
end
- def default_routes_configuration_file
- File.join(root_path, 'config', 'routes.rb')
+ def routes_configuration_file
+ @routes_configuration_file ||= File.join(root_path, 'config', 'routes.rb')
end
- def default_controller_paths
- paths = [File.join(root_path, 'app', 'controllers')]
- paths.concat builtin_directories
- paths
+ def controller_paths
+ @controller_paths ||= begin
+ paths = [File.join(root_path, 'app', 'controllers')]
+ paths.concat builtin_directories
+ paths
+ end
end
- def default_cache_store
- if File.exist?("#{root_path}/tmp/cache/")
- [ :file_store, "#{root_path}/tmp/cache/" ]
- else
- :memory_store
+ def cache_store
+ @cache_store ||= begin
+ if File.exist?("#{root_path}/tmp/cache/")
+ [ :file_store, "#{root_path}/tmp/cache/" ]
+ else
+ :memory_store
+ end
end
end
- def default_database_configuration_file
- File.join(root_path, 'config', 'database.yml')
+ def database_configuration_file
+ @database_configuration_file ||= File.join(root_path, 'config', 'database.yml')
end
- def default_view_path
- File.join(root_path, 'app', 'views')
+ def view_path
+ @view_path ||= File.join(root_path, 'app', 'views')
end
- def default_eager_load_paths
- %w(
+ def eager_load_paths
+ @eager_load_paths ||= %w(
app/metal
app/models
app/controllers
@@ -156,28 +147,30 @@ module Rails
).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
end
- def default_load_paths
- paths = []
-
- # Add the old mock paths only if the directories exists
- paths.concat(Dir["#{root_path}/test/mocks/#{RAILS_ENV}"]) if File.exists?("#{root_path}/test/mocks/#{RAILS_ENV}")
-
- # Add the app's controller directory
- paths.concat(Dir["#{root_path}/app/controllers/"])
-
- # Followed by the standard includes.
- paths.concat %w(
- app
- app/metal
- app/models
- app/controllers
- app/helpers
- app/services
- lib
- vendor
- ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
-
- paths.concat builtin_directories
+ def load_paths
+ @load_paths ||= begin
+ paths = []
+
+ # Add the old mock paths only if the directories exists
+ paths.concat(Dir["#{root_path}/test/mocks/#{RAILS_ENV}"]) if File.exists?("#{root_path}/test/mocks/#{RAILS_ENV}")
+
+ # Add the app's controller directory
+ paths.concat(Dir["#{root_path}/app/controllers/"])
+
+ # Followed by the standard includes.
+ paths.concat %w(
+ app
+ app/metal
+ app/models
+ app/controllers
+ app/helpers
+ app/services
+ lib
+ vendor
+ ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
+
+ paths.concat builtin_directories
+ end
end
def builtin_directories
@@ -185,48 +178,48 @@ module Rails
(RAILS_ENV == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
end
- def default_log_path
- File.join(root_path, 'log', "#{RAILS_ENV}.log")
+ def log_path
+ @log_path ||= File.join(root_path, 'log', "#{RAILS_ENV}.log")
end
- def default_log_level
- RAILS_ENV == 'production' ? :info : :debug
+ def log_level
+ @log_level ||= RAILS_ENV == 'production' ? :info : :debug
end
- def default_frameworks
- [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
+ def frameworks
+ @frameworks ||= [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
end
- def default_plugin_paths
- ["#{root_path}/vendor/plugins"]
+ def plugin_paths
+ @plugin_paths ||= ["#{root_path}/vendor/plugins"]
end
- def default_plugin_loader
- require 'rails/plugin/loader'
- Plugin::Loader
+ def plugin_loader
+ @plugin_loader ||= begin
+ Plugin::Loader
+ end
end
- def default_plugin_locators
- require 'rails/plugin/locator'
- locators = []
- locators << Plugin::GemLocator if defined? Gem
- locators << Plugin::FileSystemLocator
+ def plugin_locators
+ @plugin_locators ||= begin
+ locators = []
+ locators << Plugin::GemLocator if defined? Gem
+ locators << Plugin::FileSystemLocator
+ end
end
- def default_i18n
- i18n = Rails::OrderedOptions.new
- i18n.load_path = []
+ def i18n
+ @i18n ||= begin
+ i18n = Rails::OrderedOptions.new
+ i18n.load_path = []
- if File.exist?(File.join(RAILS_ROOT, 'config', 'locales'))
- i18n.load_path << Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')]
- i18n.load_path.flatten!
- end
-
- i18n
- end
+ if File.exist?(File.join(RAILS_ROOT, 'config', 'locales'))
+ i18n.load_path << Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')]
+ i18n.load_path.flatten!
+ end
- def default_serve_static_assets
- true
+ i18n
+ end
end
# Adds a single Gem dependency to the rails application. By default, it will require
@@ -241,11 +234,11 @@ module Rails
#
# config.gem 'qrp', :version => '0.4.1', :lib => false
def gem(name, options = {})
- @gems << Rails::GemDependency.new(name, options)
+ gems << Rails::GemDependency.new(name, options)
end
- def default_gems
- []
+ def gems
+ @gems ||= []
end
def environment_path
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
new file mode 100644
index 0000000000..1bf59c2b8e
--- /dev/null
+++ b/railties/test/application/configuration_test.rb
@@ -0,0 +1,17 @@
+require "isolation/abstract_unit"
+
+module ApplicationTests
+ class InitializerTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+ boot_rails
+ end
+
+ test "the application root is set correctly" do
+ # require "#{app_path}/config/environment"
+ # assert_equal app_path, Rails.application.root
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb
index 0d6eb4147a..0edb29483d 100644
--- a/railties/test/application/generators_test.rb
+++ b/railties/test/application/generators_test.rb
@@ -5,9 +5,9 @@ module ApplicationTests
include ActiveSupport::Testing::Isolation
def setup
- require "rails/generators"
build_app
boot_rails
+ require "rails/generators"
end
test "generators default values" do
diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb
index d917812383..7599bda8a2 100644
--- a/railties/test/generators/generators_test_helper.rb
+++ b/railties/test/generators/generators_test_helper.rb
@@ -8,12 +8,17 @@ else
RAILS_ROOT = fixtures
end
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activemodel/lib"
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activerecord/lib"
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../actionpack/lib"
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
+# TODO: Fix this RAILS_ENV stuff
+RAILS_ENV = 'test'
+require "rails/core"
require 'rails/generators'
require 'rubygems'
-$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activerecord/lib"
-$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../actionpack/lib"
+
require 'active_record'
require 'action_dispatch'