aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-06-15 23:52:37 +0000
committerRick Olson <technoweenie@gmail.com>2007-06-15 23:52:37 +0000
commit7f517348db260fb0794a3644f761ac91fe540472 (patch)
treece43b8e4da29effdabb8d10578bdef72022a80ce /actionpack
parent9d4225f1298bebacc04cc0055b180c6b2926c024 (diff)
downloadrails-7f517348db260fb0794a3644f761ac91fe540472.tar.gz
rails-7f517348db260fb0794a3644f761ac91fe540472.tar.bz2
rails-7f517348db260fb0794a3644f761ac91fe540472.zip
Make ActionView#view_paths an attr_accessor for real this time. Also, don't perform an unnecessary #compact on the @view_paths array in #initialize. Closes #8582 [dasil003, julik, rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7034 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/base.rb14
-rw-r--r--actionpack/test/controller/view_paths_test.rb15
3 files changed, 23 insertions, 8 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index caef1a2770..85d0a6f541 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Make ActionView#view_paths an attr_accessor for real this time. Also, don't perform an unnecessary #compact on the @view_paths array in #initialize. Closes #8582 [dasil003, julik, rick]
+
* Tolerate missing content type on multipart file uploads. Fix for Safari 3. [Jeremy Kemper]
* Deprecation: remove pagination. Install the classic_pagination plugin for forward compatibility, or move to the superior will_paginate plugin. #8157 [Josh Peek]
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 61d4bd7ad2..63ec0021b0 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -154,9 +154,9 @@ module ActionView #:nodoc:
attr_reader :first_render
attr_accessor :base_path, :assigns, :template_extension
- attr_accessor :controller
+ attr_accessor :controller, :view_paths
- attr_reader :logger, :response, :headers, :view_paths
+ attr_reader :logger, :response, :headers
attr_internal :cookies, :flash, :headers, :params, :request, :response, :session
attr_writer :template_format
@@ -248,7 +248,7 @@ module ActionView #:nodoc:
end
def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc:
- @view_paths = [*view_paths].compact
+ @view_paths = view_paths.respond_to?(:find) ? view_paths : [*view_paths].compact
@assigns = assigns_for_first_render
@assigns_added = nil
@controller = controller
@@ -267,7 +267,7 @@ module ActionView #:nodoc:
else
template_extension = pick_template_extension(template_path).to_s
unless template_extension
- raise ActionViewError, "No #{template_handler_preferences.to_sentence} template found for #{template_path} in #{@view_paths.inspect}"
+ raise ActionViewError, "No #{template_handler_preferences.to_sentence} template found for #{template_path} in #{view_paths.inspect}"
end
template_file_name = full_template_path(template_path, template_extension)
template_extension = template_extension.gsub(/^\w+\./, '') # strip off any formats
@@ -279,7 +279,7 @@ module ActionView #:nodoc:
template_source = nil # Don't read the source until we know that it is required
if template_file_name.blank?
- raise ActionViewError, "Couldn't find template file for #{template_path} in #{@view_paths.inspect}"
+ raise ActionViewError, "Couldn't find template file for #{template_path} in #{view_paths.inspect}"
end
begin
@@ -453,12 +453,12 @@ module ActionView #:nodoc:
# Returns the view path that contains the given relative template path.
def find_base_path_for(template_file_name)
- @view_paths.find { |p| File.file?(File.join(p, template_file_name)) }
+ view_paths.find { |p| File.file?(File.join(p, template_file_name)) }
end
# Returns the view path that the full path resides in.
def extract_base_path_from(full_path)
- @view_paths.find { |p| full_path[0..p.size - 1] == p }
+ view_paths.find { |p| full_path[0..p.size - 1] == p }
end
# Determines the template's file extension, such as rhtml, rxml, or rjs.
diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb
index 6c07c40c0a..d6d6dac4f3 100644
--- a/actionpack/test/controller/view_paths_test.rb
+++ b/actionpack/test/controller/view_paths_test.rb
@@ -7,8 +7,15 @@ class ViewLoadPathsTest < Test::Unit::TestCase
class TestController < ActionController::Base
def self.controller_path() "test" end
def rescue_action(e) raise end
-
+
+ before_filter :add_view_path, :only => :hello_world_at_request_time
+
def hello_world() end
+ def hello_world_at_request_time() render(:action => 'hello_world') end
+ private
+ def add_view_path
+ self.class.view_paths.unshift "#{LOAD_PATH_ROOT}/override"
+ end
end
def setup
@@ -44,6 +51,12 @@ class ViewLoadPathsTest < Test::Unit::TestCase
assert_equal "Hello overridden world!", @response.body
end
+ def test_view_paths_override_at_request_time
+ get :hello_world_at_request_time
+ assert_response :success
+ assert_equal "Hello overridden world!", @response.body
+ end
+
def test_template_root_deprecated
assert_deprecated(/template_root.*view_paths/) do
TestController.template_root = 'foo/bar'