aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/initializer/path_test.rb
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-06-26 17:32:05 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-06-26 17:32:05 -0700
commit188a892c5a097ee6d62249d048a6be7d2dfe9649 (patch)
tree6ef8769019e1f294156dd58551ec6656a37d4385 /railties/test/initializer/path_test.rb
parent4153c6b720563e1c43bb96e95f0ff5fbd59d6be7 (diff)
downloadrails-188a892c5a097ee6d62249d048a6be7d2dfe9649.tar.gz
rails-188a892c5a097ee6d62249d048a6be7d2dfe9649.tar.bz2
rails-188a892c5a097ee6d62249d048a6be7d2dfe9649.zip
Starting to replace scattered path configuration settings with the path object
Diffstat (limited to 'railties/test/initializer/path_test.rb')
-rw-r--r--railties/test/initializer/path_test.rb86
1 files changed, 86 insertions, 0 deletions
diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb
new file mode 100644
index 0000000000..37e1eebbc7
--- /dev/null
+++ b/railties/test/initializer/path_test.rb
@@ -0,0 +1,86 @@
+require 'abstract_unit'
+require 'active_support/ruby/shim'
+require 'initializer'
+
+RAILS_ROOT.replace File.join(File.dirname(__FILE__), "root")
+
+module Rails
+ def self.vendor_rails? ; false ; end
+end
+
+# TODO: Can this be reset?
+Rails::Initializer.run do |config|
+ config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record]
+end
+
+class PathsTest < ActiveSupport::TestCase
+ def setup
+ @paths = Rails::Initializer.default.config.paths
+ end
+
+ def root(*path)
+ File.expand_path(File.join(File.dirname(__FILE__), "root", *path))
+ end
+
+ def assert_path(paths, *dir)
+ assert_equal [root(*dir)], paths.paths
+ 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.lib, "lib"
+ assert_path @paths.vendor, "vendor"
+ assert_path @paths.vendor.plugins, "vendor", "plugins"
+ assert_path @paths.cache, "tmp", "cache"
+ assert_path @paths.config, "config"
+ assert_path @paths.config.locales, "config", "locales"
+ assert_path @paths.config.environments, "config", "environments"
+
+ assert_equal Pathname.new(File.dirname(__FILE__)).join("root", "app", "controllers").expand_path,
+ Pathname.new(@paths.app.controllers.to_a.first).expand_path
+ assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path,
+ 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
+
+ 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 "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", "metal"
+ 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", "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
+
+end \ No newline at end of file