aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-02-04 22:27:45 +0000
committerRick Olson <technoweenie@gmail.com>2007-02-04 22:27:45 +0000
commit92195e68a02715d29ef9d4b3bf66409c014f7174 (patch)
treebe9288b47df99e88a97416fd8707466fd8d549d1
parent517bf0814e95922d8675b20abc70fa0536044bbe (diff)
downloadrails-92195e68a02715d29ef9d4b3bf66409c014f7174.tar.gz
rails-92195e68a02715d29ef9d4b3bf66409c014f7174.tar.bz2
rails-92195e68a02715d29ef9d4b3bf66409c014f7174.zip
Fix issue with deprecation messing up #template_root= usage. Add #prepend_view_path and #append_view_path to allow modification of a copy of the
superclass' view_paths. [Rick] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6125 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/CHANGELOG3
-rwxr-xr-xactionpack/lib/action_controller/base.rb22
-rw-r--r--actionpack/lib/action_controller/components.rb4
-rw-r--r--actionpack/test/controller/view_paths_test.rb5
-rw-r--r--actionwebservice/test/scaffolded_controller_test.rb2
5 files changed, 28 insertions, 8 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index af521f33a7..7d957b56a8 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,8 @@
*SVN*
+* Fix issue with deprecation messing up #template_root= usage. Add #prepend_view_path and #append_view_path to allow modification of a copy of the
+superclass' view_paths. [Rick]
+
* Allow Controllers to have multiple view_paths instead of a single template_root. Closes #2754 [John Long]
* Add much-needed html-scanner tests. Fixed CDATA parsing bug. [Rick]
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 62dba3bc43..3c855a9346 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -356,9 +356,9 @@ module ActionController #:nodoc:
# Deprecated. Use view_paths instead.
def template_root=(path)
- view_paths.unshift(path)
+ prepend_view_path path
+ template_root
end
- deprecate :template_root= => :view_paths
# Deprecated. Use view_paths instead.
def template_root
@@ -374,7 +374,7 @@ module ActionController #:nodoc:
def view_paths=(value)
@@view_paths[name] = value
end
-
+
# View load paths for controller.
def view_paths
if paths = @@view_paths[name]
@@ -388,6 +388,22 @@ module ActionController #:nodoc:
end
end
+ # Adds a view_path to the front of the view_paths array.
+ # If the current class has no view paths, copy them from
+ # the superclass
+ def prepend_view_path(path)
+ self.view_paths = view_paths.dup if view_paths.frozen?
+ view_paths.unshift(path)
+ end
+
+ # Adds a view_path to the end of the view_paths array.
+ # If the current class has no view paths, copy them from
+ # the superclass
+ def append_view_path(path)
+ self.view_paths = view_paths.dup if view_paths.frozen?
+ view_paths << path
+ end
+
# Replace sensitive paramater data from the request log.
# Filters paramaters that have any of the arguments as a substring.
# Looks in all subhashes of the param hash for keys to filter.
diff --git a/actionpack/lib/action_controller/components.rb b/actionpack/lib/action_controller/components.rb
index 5d5a48ebcc..e09b4ddd5f 100644
--- a/actionpack/lib/action_controller/components.rb
+++ b/actionpack/lib/action_controller/components.rb
@@ -77,8 +77,8 @@ module ActionController #:nodoc:
def uses_component_template_root
path_of_calling_controller = File.dirname(caller[1].split(/:\d+:/, 2).first)
path_of_controller_root = path_of_calling_controller.sub(/#{Regexp.escape(File.dirname(controller_path))}$/, "")
-
- self.template_root = path_of_controller_root
+ prepend_view_path path_of_controller_root
+ view_paths.first
end
deprecate :uses_component_template_root => 'Components are deprecated and will be removed in Rails 2.0.'
diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb
index 9184ab1793..6c07c40c0a 100644
--- a/actionpack/test/controller/view_paths_test.rb
+++ b/actionpack/test/controller/view_paths_test.rb
@@ -46,10 +46,11 @@ class ViewLoadPathsTest < Test::Unit::TestCase
def test_template_root_deprecated
assert_deprecated(/template_root.*view_paths/) do
- TestController.template_root = LOAD_PATH_ROOT
+ TestController.template_root = 'foo/bar'
end
assert_deprecated(/template_root.*view_paths/) do
- assert_equal LOAD_PATH_ROOT, TestController.template_root
+ assert_equal 'foo/bar', TestController.template_root
+ assert_equal ['foo/bar', LOAD_PATH_ROOT], TestController.view_paths
end
end
diff --git a/actionwebservice/test/scaffolded_controller_test.rb b/actionwebservice/test/scaffolded_controller_test.rb
index 09c40a865e..67e74a95ec 100644
--- a/actionwebservice/test/scaffolded_controller_test.rb
+++ b/actionwebservice/test/scaffolded_controller_test.rb
@@ -5,7 +5,7 @@ ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
end
-ActionController::Base.template_root = '.'
+ActionController::Base.view_load_paths = [ '.' ]
class ScaffoldPerson < ActionWebService::Struct
member :id, :int