Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make rails configuration's path object's root lazy

  • Loading branch information...
commit d56984c01696348913b298bb65483534035304f0 1 parent 7ec947d
Yehuda Katz + Carl Lerche authored
Showing with 28 additions and 4 deletions.
  1. +7 −4 railties/lib/rails/paths.rb
  2. +21 −0 railties/test/paths_test.rb
View
11 railties/lib/rails/paths.rb
@@ -19,14 +19,15 @@ def method_missing(id, *args)
class Root
include PathParent
- attr_reader :path
+ attr_accessor :path
+
def initialize(path)
- raise unless path.is_a?(String)
+ raise if path.is_a?(Array)
@children = {}
# TODO: Move logic from set_root_path initializer
- @path = File.expand_path(path)
+ @path = path
@root = self
@all_paths = []
end
@@ -123,8 +124,10 @@ def load_path?
end
def paths
+ raise "You need to set a path root" unless @root.path
+
@paths.map do |path|
- path.index('/') == 0 ? path : File.join(@root.path, path)
+ path.index('/') == 0 ? path : File.expand_path(File.join(@root.path, path))
end
end
View
21 railties/test/paths_test.rb
@@ -12,11 +12,32 @@ def setup
assert_equal "/fiz/baz", root.path
end
+ test "the paths object can be initialized with nil" do
+ assert_nothing_raised do
+ Rails::Application::Root.new(nil)
+ end
+ end
+
+ test "a paths object initialized with nil can be updated" do
+ root = Rails::Application::Root.new(nil)
+ root.app = "app"
+ root.path = "/root"
+ assert_equal ["/root/app"], root.app.to_a
+ end
+
test "creating a root level path" do
@root.app = "/foo/bar"
assert_equal ["/foo/bar"], @root.app.to_a
end
+ test "raises exception if root path never set" do
+ root = Rails::Application::Root.new(nil)
+ root.app = "app"
+ assert_raises RuntimeError do
+ root.app.to_a
+ end
+ end
+
test "creating a root level path without assignment" do
@root.app "/foo/bar"
assert_equal ["/foo/bar"], @root.app.to_a
Please sign in to comment.
Something went wrong with that request. Please try again.