diff options
author | José Valim <jose.valim@gmail.com> | 2009-06-27 21:27:21 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-06-27 21:27:21 +0200 |
commit | 85ff67ce4c0e95de9b855af7f7e7fbab7f7726de (patch) | |
tree | 3eb1914ed2ac7261405df22015fc4b33578bbe3c /railties/test | |
parent | e375819b76ac04bc60fd516b15bbe42c093eb547 (diff) | |
parent | 085db5e128ad4ad8fd042776722c78e194c6d0a4 (diff) | |
download | rails-85ff67ce4c0e95de9b855af7f7e7fbab7f7726de.tar.gz rails-85ff67ce4c0e95de9b855af7f7e7fbab7f7726de.tar.bz2 rails-85ff67ce4c0e95de9b855af7f7e7fbab7f7726de.zip |
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/abstract_unit.rb | 1 | ||||
-rw-r--r-- | railties/test/initializer/path_test.rb | 86 | ||||
-rw-r--r-- | railties/test/initializer/root/app/controllers/.keep | 0 | ||||
-rw-r--r-- | railties/test/initializer/root/app/helpers/.keep | 0 | ||||
-rw-r--r-- | railties/test/initializer/root/app/metal/.keep | 0 | ||||
-rw-r--r-- | railties/test/initializer/root/app/models/.keep | 0 | ||||
-rw-r--r-- | railties/test/initializer/root/app/views/.keep | 0 | ||||
-rw-r--r-- | railties/test/initializer/root/config/database.yml | 4 | ||||
-rw-r--r-- | railties/test/initializer/root/config/environments/.keep | 0 | ||||
-rw-r--r-- | railties/test/initializer/root/config/locales/.keep | 0 | ||||
-rw-r--r-- | railties/test/initializer/root/config/routes.rb | 0 | ||||
-rw-r--r-- | railties/test/initializer/root/lib/.keep | 0 | ||||
-rw-r--r-- | railties/test/initializer/root/tmp/.keep | 0 | ||||
-rw-r--r-- | railties/test/initializer/root/tmp/cache/.keep | 0 | ||||
-rw-r--r-- | railties/test/initializer/root/vendor/.keep | 0 | ||||
-rw-r--r-- | railties/test/paths_test.rb | 119 |
16 files changed, 210 insertions, 0 deletions
diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 0addcb8bf3..cef69e90cb 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -2,6 +2,7 @@ $:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" $:.unshift File.dirname(__FILE__) + "/../../activerecord/lib" $:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" $:.unshift File.dirname(__FILE__) + "/../../actionmailer/lib" +$:.unshift File.dirname(__FILE__) + "/../../activeresource/lib" $:.unshift File.dirname(__FILE__) + "/../lib" $:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" 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 diff --git a/railties/test/initializer/root/app/controllers/.keep b/railties/test/initializer/root/app/controllers/.keep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/railties/test/initializer/root/app/controllers/.keep diff --git a/railties/test/initializer/root/app/helpers/.keep b/railties/test/initializer/root/app/helpers/.keep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/railties/test/initializer/root/app/helpers/.keep diff --git a/railties/test/initializer/root/app/metal/.keep b/railties/test/initializer/root/app/metal/.keep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/railties/test/initializer/root/app/metal/.keep diff --git a/railties/test/initializer/root/app/models/.keep b/railties/test/initializer/root/app/models/.keep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/railties/test/initializer/root/app/models/.keep diff --git a/railties/test/initializer/root/app/views/.keep b/railties/test/initializer/root/app/views/.keep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/railties/test/initializer/root/app/views/.keep diff --git a/railties/test/initializer/root/config/database.yml b/railties/test/initializer/root/config/database.yml new file mode 100644 index 0000000000..ce3356be0c --- /dev/null +++ b/railties/test/initializer/root/config/database.yml @@ -0,0 +1,4 @@ +development: + adapter: sqlite3 + database: db/railties.db + timeout: 5000
\ No newline at end of file diff --git a/railties/test/initializer/root/config/environments/.keep b/railties/test/initializer/root/config/environments/.keep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/railties/test/initializer/root/config/environments/.keep diff --git a/railties/test/initializer/root/config/locales/.keep b/railties/test/initializer/root/config/locales/.keep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/railties/test/initializer/root/config/locales/.keep diff --git a/railties/test/initializer/root/config/routes.rb b/railties/test/initializer/root/config/routes.rb new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/railties/test/initializer/root/config/routes.rb diff --git a/railties/test/initializer/root/lib/.keep b/railties/test/initializer/root/lib/.keep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/railties/test/initializer/root/lib/.keep diff --git a/railties/test/initializer/root/tmp/.keep b/railties/test/initializer/root/tmp/.keep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/railties/test/initializer/root/tmp/.keep diff --git a/railties/test/initializer/root/tmp/cache/.keep b/railties/test/initializer/root/tmp/cache/.keep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/railties/test/initializer/root/tmp/cache/.keep diff --git a/railties/test/initializer/root/vendor/.keep b/railties/test/initializer/root/vendor/.keep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/railties/test/initializer/root/vendor/.keep diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb new file mode 100644 index 0000000000..a1ed43ad6d --- /dev/null +++ b/railties/test/paths_test.rb @@ -0,0 +1,119 @@ +require 'abstract_unit' +require 'rails/paths' + +class PathsTest < ActiveSupport::TestCase + + def setup + @root = Rails::Application::Root.new("/foo/bar") + end + + test "the paths object is initialized with the root path" do + root = Rails::Application::Root.new("/fiz/baz") + assert_equal "/fiz/baz", root.path + end + + test "creating a root level path" do + @root.app = "/foo/bar" + assert_equal ["/foo/bar"], @root.app.to_a + end + + test "relative paths are relative to the paths root" do + @root.app = "app" + assert_equal ["/foo/bar/app"], @root.app.to_a + end + + test "creating a child level path" do + @root.app = "/foo/bar" + @root.app.models = "/foo/bar/baz" + assert_equal ["/foo/bar/baz"], @root.app.models.to_a + end + + test "child level paths are relative from the root" do + @root.app = "/app" + @root.app.models = "baz" + + assert_equal ["/foo/bar/baz"], @root.app.models.to_a + end + + test "adding multiple physical paths as an array" do + @root.app = ["/app", "/app2"] + assert_equal ["/app", "/app2"], @root.app.to_a + end + + test "adding multiple physical paths using #push" do + @root.app = "/app" + @root.app.push "/app2" + assert_equal ["/app", "/app2"], @root.app.to_a + end + + test "adding multiple physical paths using <<" do + @root.app = "/app" + @root.app << "/app2" + assert_equal ["/app", "/app2"], @root.app.to_a + end + + test "adding multiple physical paths using #unshift" do + @root.app = "/app" + @root.app.unshift "/app2" + assert_equal ["/app2", "/app"], @root.app.to_a + end + + test "the root can only have one physical path" do + assert_raise(RuntimeError) { Rails::Application::Root.new(["/fiz", "/biz"]) } + assert_raise(NoMethodError) { @root.push "/biz" } + assert_raise(NoMethodError) { @root.unshift "/biz" } + assert_raise(NoMethodError) { @root << "/biz" } + end + + test "it is possible to add a path that should be loaded only once" do + @root.app = "/app" + @root.app.load_once! + assert @root.app.load_once? + assert @root.load_once.include?(@root.app.paths.first) + end + + test "making a path load_once more than once only includes it once in @root.load_once" do + @root.app = "/app" + @root.app.load_once! + @root.app.load_once! + assert_equal 1, @root.load_once.select {|p| p == @root.app.paths.first }.size + end + + test "it is possible to mark a path as eager" do + @root.app = "/app" + @root.app.eager_load! + assert @root.app.eager_load? + assert @root.eager_load.include?(@root.app.paths.first) + end + + test "making a path eager more than once only includes it once in @root.eager_paths" do + @root.app = "/app" + @root.app.eager_load! + @root.app.eager_load! + assert_equal 1, @root.eager_load.select {|p| p == @root.app.paths.first }.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 + @root.app = "/app" + @root.app.glob = "*.rb" + assert_equal "*.rb", @root.app.glob + end + + test "a path can be added to the load path" do + @root.app = "app" + @root.app.load_path! + @root.app.models = "app/models" + assert_equal ["/foo/bar/app"], @root.load_paths + end + + test "adding a path to the eager paths also adds it to the load path" do + @root.app = "app" + @root.app.eager_load! + assert_equal ["/foo/bar/app"], @root.load_paths + end +end
\ No newline at end of file |