Got tests working once again.

This commit is contained in:
José Valim 2010-01-22 16:24:44 +01:00
parent 02c5137ead
commit 4ae7936727
7 changed files with 40 additions and 48 deletions

View File

@ -2,8 +2,6 @@ require 'fileutils'
module Rails
class Application < Engine
include Initializable
class << self
alias :configure :class_eval
delegate :initialize!, :load_tasks, :load_generators, :root, :to => :instance
@ -122,7 +120,7 @@ module Rails
app.call(env)
end
initializer :add_builtin_route do |app|
initializer :add_builtin_route, :before => :build_middleware_stack do |app|
if Rails.env.development?
app.route_configuration_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb')
end

View File

@ -81,15 +81,13 @@ module Rails
def paths
@paths ||= begin
paths = Rails::Application::Root.new(@root)
paths.app "app", :load_path => true
paths.app_glob "app/*", :load_path => true, :eager_load => true
paths.app.controllers "app/controllers", :eager_load => true
paths.app.metals "app/metal"
paths.app "app", :eager_load => true, :glob => "*"
paths.app.controllers "app/controllers", :eager_load => true
paths.app.metals "app/metal", :eager_load => true
paths.app.views "app/views"
paths.lib "lib", :load_path => true
paths.config "config"
paths.config.environment "config/environments/#{Rails.env}.rb"
paths.config.environments "config/environments", :glob => "#{Rails.env}.rb"
paths.config.environment "config/environments", :glob => "#{Rails.env}.rb"
paths.config.initializers "config/initializers"
paths.config.locales "config/locales"
paths.config.routes "config/routes.rb"
@ -112,10 +110,6 @@ module Rails
def load_paths
@load_paths ||= paths.load_paths
end
def controller_paths
paths.app.controllers.to_a.uniq
end
end
class Configuration < Engine::Configuration
@ -142,7 +136,7 @@ module Rails
def paths
@paths ||= begin
paths = super
paths.app.controllers << builtin_directories
paths.app.controllers.concat(builtin_directories)
paths.config.database "config/database.yml"
paths.log "log/#{Rails.env}.log"
paths.tmp "tmp"
@ -238,6 +232,18 @@ module Rails
paths.config.log.to_a.first
end
def controller_paths=(value)
ActiveSupport::Deprecation.warn "config.controller_paths= is deprecated, " <<
"please do config.paths.app.controllers= instead", caller
paths.app.controllers = value
end
def controller_paths
ActiveSupport::Deprecation.warn "config.controller_paths is deprecated, " <<
"please do config.paths.app.controllers instead", caller
paths.app.controllers.to_a.uniq
end
def cache_store
@cache_store ||= begin
if File.exist?("#{root}/tmp/cache/")

View File

@ -50,7 +50,9 @@ module Rails
# Add configured load paths to ruby load paths and remove duplicates.
initializer :set_load_path, :before => :container do
config.paths.add_to_load_path
expand_load_path(config.load_paths).reverse_each do |path|
$LOAD_PATH.unshift(path) if File.directory?(path)
end
$LOAD_PATH.uniq!
end

View File

@ -39,6 +39,7 @@ module Rails
all_paths.map { |path| path.paths if path.eager_load? }.compact.flatten.uniq
end
# TODO Discover why do we need to call uniq! here
def all_paths
@all_paths.uniq!
@all_paths
@ -48,12 +49,6 @@ module Rails
all_paths.map { |path| path.paths if path.load_path? }.compact.flatten.uniq
end
def add_to_load_path
load_paths.reverse_each do |path|
$LOAD_PATH.unshift(path) if File.directory?(path)
end
end
def push(*)
raise "Application root can only have one physical path"
end
@ -74,7 +69,7 @@ module Rails
@children = {}
@root = root
@paths = paths.flatten
@glob = @options[:glob] || "**/*.rb"
@glob = @options.delete(:glob)
@load_once = @options[:load_once]
@eager_load = @options[:eager_load]
@ -128,10 +123,13 @@ module Rails
def paths
raise "You need to set a path root" unless @root.path
@paths.map do |path|
path.index('/') == 0 ? path : File.expand_path(File.join(@root.path, path))
result = @paths.map do |p|
path = File.expand_path(p, @root.path)
@glob ? Dir[File.join(path, @glob)] : path
end
result.flatten!
result.uniq!
result
end
alias to_a paths

View File

@ -34,9 +34,9 @@ module ApplicationTests
add_to_config <<-RUBY
config.root = '#{new_app}'
RUBY
use_frameworks []
require "#{app_path}/config/environment"
assert_equal Pathname.new(new_app), Rails.application.root
end

View File

@ -8,6 +8,7 @@ module InitializerTests
build_app
boot_rails
FileUtils.rm_rf("#{app_path}/config/environments")
app_file "config/environments/development.rb", ""
add_to_config <<-RUBY
config.root = "#{app_path}"
config.after_initialize do
@ -36,11 +37,8 @@ module InitializerTests
end
test "booting up Rails yields a valid paths object" do
assert_path @paths.app, "app"
assert_path @paths.app.metals, "app", "metal"
assert_path @paths.app.models, "app", "models"
assert_path @paths.app.helpers, "app", "helpers"
assert_path @paths.app.services, "app", "services"
assert_path @paths.app.views, "app", "views"
assert_path @paths.lib, "lib"
assert_path @paths.vendor, "vendor"
assert_path @paths.vendor.plugins, "vendor", "plugins"
@ -48,7 +46,7 @@ module InitializerTests
assert_path @paths.tmp.cache, "tmp", "cache"
assert_path @paths.config, "config"
assert_path @paths.config.locales, "config", "locales"
assert_path @paths.config.environments, "config", "environments"
assert_path @paths.config.environment, "config", "environments", "development.rb"
assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first
assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path,
@ -56,27 +54,22 @@ module InitializerTests
end
test "booting up Rails yields a list of paths that are eager" do
assert @paths.app.models.eager_load?
assert @paths.app.eager_load?
assert @paths.app.controllers.eager_load?
assert @paths.app.helpers.eager_load?
assert @paths.app.metals.eager_load?
end
test "environments has a glob equal to the current environment" do
assert_equal "#{Rails.env}.rb", @paths.config.environments.glob
assert_equal "#{Rails.env}.rb", @paths.config.environment.glob
end
test "load path includes each of the paths in config.paths as long as the directories exist" do
assert_in_load_path "app"
assert_in_load_path "app", "controllers"
assert_in_load_path "app", "models"
assert_in_load_path "app", "helpers"
assert_in_load_path "lib"
assert_in_load_path "vendor"
assert_not_in_load_path "app", "views"
assert_not_in_load_path "app", "metal"
assert_not_in_load_path "app", "services"
assert_not_in_load_path "config"
assert_not_in_load_path "config", "locales"
assert_not_in_load_path "config", "environments"
@ -86,17 +79,17 @@ module InitializerTests
test "controller paths include builtin in development mode" do
Rails.env.replace "development"
assert Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
assert Rails::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
end
test "controller paths does not have builtin_directories in test mode" do
Rails.env.replace "test"
assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
assert !Rails::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
end
test "controller paths does not have builtin_directories in production mode" do
Rails.env.replace "production"
assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
assert !Rails::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
end
end

View File

@ -193,12 +193,7 @@ class PathsTest < ActiveSupport::TestCase
assert_equal 2, @root.eager_load.size
end
test "a path should have a glob that defaults to **/*.rb" do
@root.app = "/app"
assert_equal "**/*.rb", @root.app.glob
end
test "it should be possible to override a path's default glob" do
test "it should be possible to add a path's default glob" do
@root.app = "/app"
@root.app.glob = "*.rb"
assert_equal "*.rb", @root.app.glob