2009-09-29 19:07:29 -04:00
|
|
|
require "isolation/abstract_unit"
|
2009-06-26 20:32:05 -04:00
|
|
|
|
2010-01-26 07:57:11 -05:00
|
|
|
module ApplicationTests
|
|
|
|
class PathsTest < Test::Unit::TestCase
|
2009-12-28 14:40:34 -05:00
|
|
|
include ActiveSupport::Testing::Isolation
|
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
boot_rails
|
2009-12-31 16:11:54 -05:00
|
|
|
FileUtils.rm_rf("#{app_path}/config/environments")
|
2010-01-22 10:24:44 -05:00
|
|
|
app_file "config/environments/development.rb", ""
|
2009-12-28 14:40:34 -05:00
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.root = "#{app_path}"
|
2010-03-04 15:12:04 -05:00
|
|
|
config.after_initialize do |app|
|
2010-03-04 19:12:34 -05:00
|
|
|
app.config.session_store nil
|
2009-12-28 14:40:34 -05:00
|
|
|
end
|
|
|
|
RUBY
|
2009-12-31 13:36:24 -05:00
|
|
|
use_frameworks [:action_controller, :action_view, :action_mailer, :active_record]
|
2009-12-28 14:40:34 -05:00
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
@paths = Rails.application.config.paths
|
|
|
|
end
|
|
|
|
|
2011-06-06 08:54:05 -04:00
|
|
|
def teardown
|
|
|
|
teardown_app
|
|
|
|
end
|
|
|
|
|
2009-12-28 14:40:34 -05:00
|
|
|
def root(*path)
|
|
|
|
app_path(*path).to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_path(paths, *dir)
|
2010-10-06 11:18:59 -04:00
|
|
|
assert_equal [root(*dir)], paths.expanded
|
2009-12-28 14:40:34 -05:00
|
|
|
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-----"
|
|
|
|
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-----"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "booting up Rails yields a valid paths object" do
|
2010-10-06 11:18:59 -04:00
|
|
|
assert_path @paths["app/models"], "app/models"
|
|
|
|
assert_path @paths["app/helpers"], "app/helpers"
|
|
|
|
assert_path @paths["app/views"], "app/views"
|
|
|
|
assert_path @paths["lib"], "lib"
|
|
|
|
assert_path @paths["vendor"], "vendor"
|
|
|
|
assert_path @paths["tmp"], "tmp"
|
|
|
|
assert_path @paths["config"], "config"
|
|
|
|
assert_path @paths["config/locales"], "config/locales/en.yml"
|
|
|
|
assert_path @paths["config/environment"], "config/environment.rb"
|
|
|
|
assert_path @paths["config/environments"], "config/environments/development.rb"
|
|
|
|
|
|
|
|
assert_equal root("app", "controllers"), @paths["app/controllers"].expanded.first
|
2009-12-28 14:40:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "booting up Rails yields a list of paths that are eager" do
|
2010-03-06 13:19:26 -05:00
|
|
|
eager_load = @paths.eager_load
|
|
|
|
assert eager_load.include?(root("app/controllers"))
|
|
|
|
assert eager_load.include?(root("app/helpers"))
|
|
|
|
assert eager_load.include?(root("app/models"))
|
2009-12-28 14:40:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "environments has a glob equal to the current environment" do
|
2011-05-24 21:52:38 -04:00
|
|
|
assert_equal "#{Rails.env}.rb", @paths["config/environments"].glob
|
2009-12-28 14:40:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "load path includes each of the paths in config.paths as long as the directories exist" do
|
|
|
|
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"
|
|
|
|
|
2010-04-05 06:30:59 -04:00
|
|
|
assert_not_in_load_path "app", "views"
|
2009-12-28 14:40:34 -05:00
|
|
|
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
|
2009-06-26 20:32:05 -04:00
|
|
|
end
|
2009-12-28 14:40:34 -05:00
|
|
|
end
|