-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
99 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,101 +1,103 @@ | |||
require "isolation/abstract_unit" | require "isolation/abstract_unit" | ||
|
|
||
class PathsTest < Test::Unit::TestCase | module InitializerTests | ||
include ActiveSupport::Testing::Isolation | class PathTest < Test::Unit::TestCase | ||
|
include ActiveSupport::Testing::Isolation | ||
def setup |
|
||
build_app | def setup | ||
boot_rails | build_app | ||
require "rails" | boot_rails | ||
add_to_config <<-RUBY | require "rails" | ||
config.root = "#{app_path}" | add_to_config <<-RUBY | ||
config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record] | config.root = "#{app_path}" | ||
config.after_initialize do | config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record] | ||
ActionController::Base.session_store = nil | config.after_initialize do | ||
end | ActionController::Base.session_store = nil | ||
RUBY | end | ||
require "#{app_path}/config/environment" | RUBY | ||
@paths = Rails.application.config.paths | require "#{app_path}/config/environment" | ||
end | @paths = Rails.application.config.paths | ||
|
end | ||
def root(*path) |
|
||
app_path(*path).to_s | def root(*path) | ||
end | app_path(*path).to_s | ||
|
end | ||
def assert_path(paths, *dir) |
|
||
assert_equal [root(*dir)], paths.paths | def assert_path(paths, *dir) | ||
end | assert_equal [root(*dir)], paths.paths | ||
|
end | ||
def assert_in_load_path(*path) |
|
||
assert $:.any? { |p| File.expand_path(p) == root(*path) }, "Load path does not include '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" | def assert_in_load_path(*path) | ||
end | assert $:.any? { |p| File.expand_path(p) == root(*path) }, "Load path does not include '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" | ||
|
end | ||
def assert_not_in_load_path(*path) |
|
||
assert !$:.any? { |p| File.expand_path(p) == root(*path) }, "Load path includes '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" | def assert_not_in_load_path(*path) | ||
end | assert !$:.any? { |p| File.expand_path(p) == root(*path) }, "Load path includes '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" | ||
|
end | ||
test "booting up Rails yields a valid paths object" do |
|
||
assert_path @paths.app, "app" | test "booting up Rails yields a valid paths object" do | ||
assert_path @paths.app.metals, "app", "metal" | assert_path @paths.app, "app" | ||
assert_path @paths.app.models, "app", "models" | assert_path @paths.app.metals, "app", "metal" | ||
assert_path @paths.app.helpers, "app", "helpers" | assert_path @paths.app.models, "app", "models" | ||
assert_path @paths.app.services, "app", "services" | assert_path @paths.app.helpers, "app", "helpers" | ||
assert_path @paths.lib, "lib" | assert_path @paths.app.services, "app", "services" | ||
assert_path @paths.vendor, "vendor" | assert_path @paths.lib, "lib" | ||
assert_path @paths.vendor.plugins, "vendor", "plugins" | assert_path @paths.vendor, "vendor" | ||
assert_path @paths.tmp, "tmp" | assert_path @paths.vendor.plugins, "vendor", "plugins" | ||
assert_path @paths.tmp.cache, "tmp", "cache" | assert_path @paths.tmp, "tmp" | ||
assert_path @paths.config, "config" | assert_path @paths.tmp.cache, "tmp", "cache" | ||
assert_path @paths.config.locales, "config", "locales" | assert_path @paths.config, "config" | ||
assert_path @paths.config.environments, "config", "environments" | assert_path @paths.config.locales, "config", "locales" | ||
|
assert_path @paths.config.environments, "config", "environments" | ||
assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first |
|
||
assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path, | assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first | ||
Pathname.new(@paths.app.controllers.to_a[1]).expand_path | assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path, | ||
end | Pathname.new(@paths.app.controllers.to_a[1]).expand_path | ||
end | |||
|
|||
test "booting up Rails yields a list of paths that are eager" do | |||
assert @paths.app.models.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 | |||
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" | |||
assert_not_in_load_path "tmp" | |||
assert_not_in_load_path "tmp", "cache" | |||
end | |||
|
|||
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/ } | |||
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/ } | |||
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/ } | |||
end | |||
|
|
||
test "booting up Rails yields a list of paths that are eager" do | |||
assert @paths.app.models.eager_load? | |||
assert @paths.app.controllers.eager_load? | |||
assert @paths.app.helpers.eager_load? | |||
assert @paths.app.metals.eager_load? | |||
end | end | ||
|
end | ||
test "environments has a glob equal to the current environment" do | |||
assert_equal "#{RAILS_ENV}.rb", @paths.config.environments.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" | |||
assert_not_in_load_path "tmp" | |||
assert_not_in_load_path "tmp", "cache" | |||
end | |||
|
|||
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/ } | |||
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/ } | |||
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/ } | |||
end | |||
|
|||
end |