提交 0f4d0055 编写于 作者: N Nicholas Mulder

Persist glob when replacing a path

When Rails::Paths::Root's []= is used to replace a path it should persist the previous path's glob. Without passing the glob along we get gnarly bugs when trying to wire up things like engines.

    module FooEngine
      class Engine < ::Rails::Engine
        isolate_namespace FooEngine

        config.paths['config/initializers'] = "lib/foo_engine/initializers"
      end
    end

    ## Example of behaviour before this commit.
    #
    # Before the initializer override:
    >> FooEngine::Engine.config.paths["config/initializers"].glob
    => "**/*.rb"

    # After the initializer override:
    >> FooEngine::Engine.config.paths["config/initializers"].glob
    => nil

    ## Example of behaviour after this commit.
    #
    # Before the initializer override:
    >> FooEngine::Engine.config.paths["config/initializers"].glob
    => "**/*.rb"

    # After the initializer override:
    >> FooEngine::Engine.config.paths["config/initializers"].glob
    => "**/*.rb"
上级 0470ddcf
......@@ -51,7 +51,8 @@ def initialize(path)
end
def []=(path, value)
add(path, :with => value)
glob = self[path] ? self[path].glob : nil
add(path, :with => value, :glob => glob)
end
def add(path, options={})
......
......@@ -200,6 +200,13 @@ def setup
assert_equal "*.rb", @root["app"].glob
end
test "it should be possible to replace a path and persist the original paths glob" do
@root.add "app", :glob => "*.rb"
@root["app"] = "app2"
assert_equal ["/foo/bar/app2"], @root["app"].paths
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!
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册