aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Mulder <nicholas.mulder@gmail.com>2012-06-29 10:47:44 -0400
committerNicholas Mulder <nicholas.mulder@gmail.com>2012-06-30 16:59:07 -0400
commit0f4d005501c4230fcdf8d64d530639f5bcda6086 (patch)
tree91725fda9b494861553d8739fa05e3c70ca8e2c6
parent0470ddcf0301e537d5151d62177eadba5eae182d (diff)
downloadrails-0f4d005501c4230fcdf8d64d530639f5bcda6086.tar.gz
rails-0f4d005501c4230fcdf8d64d530639f5bcda6086.tar.bz2
rails-0f4d005501c4230fcdf8d64d530639f5bcda6086.zip
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"
-rw-r--r--railties/lib/rails/paths.rb3
-rw-r--r--railties/test/paths_test.rb7
2 files changed, 9 insertions, 1 deletions
diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb
index 6cd9c7bc95..316ecca87b 100644
--- a/railties/lib/rails/paths.rb
+++ b/railties/lib/rails/paths.rb
@@ -51,7 +51,8 @@ module Rails
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={})
diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb
index 5d6b6f9f72..2b38f0975d 100644
--- a/railties/test/paths_test.rb
+++ b/railties/test/paths_test.rb
@@ -200,6 +200,13 @@ class PathsTest < ActiveSupport::TestCase
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!