aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rwxr-xr-xactionpack/lib/action_controller/base.rb16
-rw-r--r--actionpack/lib/action_controller/dispatcher.rb1
-rw-r--r--actionpack/lib/action_controller/layout.rb13
-rw-r--r--actionpack/lib/action_view.rb2
-rw-r--r--actionpack/lib/action_view/base.rb145
-rw-r--r--actionpack/lib/action_view/helpers/cache_helper.rb2
-rw-r--r--actionpack/lib/action_view/template_finder.rb161
-rw-r--r--actionpack/test/controller/mime_responds_test.rb6
-rw-r--r--actionpack/test/controller/new_render_test.rb10
-rw-r--r--actionpack/test/controller/view_paths_test.rb6
-rw-r--r--actionpack/test/template/template_finder_test.rb43
12 files changed, 167 insertions, 240 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 7fbac137c4..e5fd5078d3 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -2,8 +2,6 @@
* Performance: optimize route recognition. Large speedup for apps with many resource routes. #10835 [oleganza]
-* Introduce TemplateFinder to handle view paths and lookups. #10800 [Pratik Naik]
-
* Make render :partial recognise form builders and use the _form partial. #10814 [djanowski]
* Allow users to declare other namespaces when using the atom feed helpers. #10304 [david.calavera]
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 1321b002eb..5d4afc31fe 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -5,7 +5,6 @@ require 'action_controller/routing'
require 'action_controller/resources'
require 'action_controller/url_rewriter'
require 'action_controller/status_codes'
-require 'action_view/template_finder'
require 'drb'
require 'set'
@@ -429,7 +428,6 @@ module ActionController #:nodoc:
def view_paths=(value)
@view_paths = value
- ActionView::TemplateFinder.process_view_paths(value)
end
# Adds a view_path to the front of the view_paths array.
@@ -442,7 +440,6 @@ module ActionController #:nodoc:
def prepend_view_path(path)
@view_paths = superclass.view_paths.dup if @view_paths.nil?
view_paths.unshift(*path)
- ActionView::TemplateFinder.process_view_paths(path)
end
# Adds a view_path to the end of the view_paths array.
@@ -455,7 +452,6 @@ module ActionController #:nodoc:
def append_view_path(path)
@view_paths = superclass.view_paths.dup if @view_paths.nil?
view_paths.push(*path)
- ActionView::TemplateFinder.process_view_paths(path)
end
# Replace sensitive parameter data from the request log.
@@ -646,11 +642,11 @@ module ActionController #:nodoc:
# View load paths for controller.
def view_paths
- @template.finder.view_paths
+ @template.view_paths
end
def view_paths=(value)
- @template.finder.view_paths = value # Mutex needed
+ @template.view_paths = value
end
# Adds a view_path to the front of the view_paths array.
@@ -660,7 +656,7 @@ module ActionController #:nodoc:
# self.prepend_view_path(["views/default", "views/custom"])
#
def prepend_view_path(path)
- @template.finder.prepend_view_path(path) # Mutex needed
+ @template.prepend_view_path(path)
end
# Adds a view_path to the end of the view_paths array.
@@ -670,7 +666,7 @@ module ActionController #:nodoc:
# self.append_view_path(["views/default", "views/custom"])
#
def append_view_path(path)
- @template.finder.append_view_path(path) # Mutex needed
+ @template.append_view_path(path)
end
protected
@@ -1253,7 +1249,7 @@ module ActionController #:nodoc:
end
def template_exists?(template_name = default_template_name)
- @template.finder.file_exists?(template_name)
+ @template.file_exists?(template_name)
end
def template_public?(template_name = default_template_name)
@@ -1261,7 +1257,7 @@ module ActionController #:nodoc:
end
def template_exempt_from_layout?(template_name = default_template_name)
- extension = @template && @template.finder.pick_template_extension(template_name)
+ extension = @template && @template.pick_template_extension(template_name)
name_with_extension = !template_name.include?('.') && extension ? "#{template_name}.#{extension}" : template_name
@@exempt_from_layout.any? { |ext| name_with_extension =~ ext }
end
diff --git a/actionpack/lib/action_controller/dispatcher.rb b/actionpack/lib/action_controller/dispatcher.rb
index f892058f20..6a02f602e4 100644
--- a/actionpack/lib/action_controller/dispatcher.rb
+++ b/actionpack/lib/action_controller/dispatcher.rb
@@ -139,7 +139,6 @@ module ActionController
if unprepared || force
run_callbacks :prepare_dispatch
- ActionView::TemplateFinder.reload! unless ActionView::Base.cache_template_loading
self.unprepared = false
end
end
diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb
index 0fbbfa8b05..a81efc2693 100644
--- a/actionpack/lib/action_controller/layout.rb
+++ b/actionpack/lib/action_controller/layout.rb
@@ -208,6 +208,12 @@ module ActionController #:nodoc:
conditions.inject({}) {|hash, (key, value)| hash.merge(key => [value].flatten.map {|action| action.to_s})}
end
+ def layout_directory_exists_cache
+ @@layout_directory_exists_cache ||= Hash.new do |h, dirname|
+ h[dirname] = File.directory? dirname
+ end
+ end
+
def default_layout_with_format(format, layout)
list = layout_list
if list.grep(%r{layouts/#{layout}\.#{format}(\.[a-z][0-9a-z]*)+$}).empty?
@@ -307,8 +313,13 @@ module ActionController #:nodoc:
end
end
+ # Does a layout directory for this class exist?
+ # we cache this info in a class level hash
def layout_directory?(layout_name)
- @template.finder.find_template_extension_from_handler(File.join('layouts', layout_name))
+ view_paths.find do |path|
+ next unless template_path = Dir[File.join(path, 'layouts', layout_name) + ".*"].first
+ self.class.send!(:layout_directory_exists_cache)[File.dirname(template_path)]
+ end
end
end
end
diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb
index 55aeb25640..bfcfcab0bd 100644
--- a/actionpack/lib/action_view.rb
+++ b/actionpack/lib/action_view.rb
@@ -26,8 +26,6 @@ require 'action_view/template_handlers/builder'
require 'action_view/template_handlers/erb'
require 'action_view/template_handlers/rjs'
-require 'action_view/template_finder'
-
require 'action_view/base'
require 'action_view/partials'
require 'action_view/template_error'
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index bcc6d2ab37..34572e442d 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -150,9 +150,9 @@ module ActionView #:nodoc:
class Base
include ERB::Util
- attr_reader :first_render, :finder
+ attr_reader :first_render
attr_accessor :base_path, :assigns, :template_extension
- attr_accessor :controller
+ attr_accessor :controller, :view_paths
attr_reader :logger, :response, :headers
attr_internal :cookies, :flash, :headers, :params, :request, :response, :session
@@ -204,6 +204,12 @@ module ActionView #:nodoc:
@@template_args = {}
# Count the number of inline templates
@@inline_template_count = 0
+ # Maps template paths without extension to their file extension returned by pick_template_extension.
+ # If for a given path, path.ext1 and path.ext2 exist on the file system, the order of extensions
+ # used by pick_template_extension determines whether ext1 or ext2 will be stored.
+ @@cached_template_extension = {}
+ # Maps template paths / extensions to
+ @@cached_base_paths = {}
# Cache public asset paths
cattr_reader :computed_public_paths
@@ -235,11 +241,10 @@ module ActionView #:nodoc:
# return the rendered template as a string.
def self.register_template_handler(extension, klass)
@@template_handlers[extension.to_sym] = klass
- TemplateFinder.update_extension_cache_for(extension.to_s)
end
def self.template_handler_extensions
- @@template_handlers.keys.map(&:to_s).sort
+ @@template_handler_extensions ||= @@template_handlers.keys.map(&:to_s).sort
end
def self.register_default_template_handler(extension, klass)
@@ -260,11 +265,11 @@ module ActionView #:nodoc:
register_template_handler :rxml, TemplateHandlers::Builder
def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc:
+ @view_paths = view_paths.respond_to?(:find) ? view_paths.dup : [*view_paths].compact
@assigns = assigns_for_first_render
@assigns_added = nil
@controller = controller
- @logger = controller && controller.logger
- @finder = TemplateFinder.new(self, view_paths)
+ @logger = controller && controller.logger
end
# Renders the template present at <tt>template_path</tt>. If <tt>use_full_path</tt> is set to true,
@@ -285,16 +290,16 @@ If you are rendering a subtemplate, you must now use controller-like partial syn
end
@first_render ||= template_path
- template_path_without_extension, template_extension = @finder.path_and_extension(template_path)
+ template_path_without_extension, template_extension = path_and_extension(template_path)
if use_full_path
if template_extension
- template_file_name = @finder.pick_template(template_path_without_extension, template_extension)
+ template_file_name = full_template_path(template_path_without_extension, template_extension)
else
- template_extension = @finder.pick_template_extension(template_path).to_s
+ template_extension = pick_template_extension(template_path).to_s
unless template_extension
- raise ActionViewError, "No template found for #{template_path} in #{@finder.view_paths.inspect}"
+ raise ActionViewError, "No template found for #{template_path} in #{view_paths.inspect}"
end
- template_file_name = @finder.pick_template(template_path, template_extension)
+ template_file_name = full_template_path(template_path, template_extension)
template_extension = template_extension.gsub(/^.+\./, '') # strip off any formats
end
else
@@ -304,7 +309,7 @@ If you are rendering a subtemplate, you must now use controller-like partial syn
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 #{@finder.view_paths.inspect}"
+ raise ActionViewError, "Couldn't find template file for #{template_path} in #{view_paths.inspect}"
end
begin
@@ -314,8 +319,7 @@ If you are rendering a subtemplate, you must now use controller-like partial syn
e.sub_template_of(template_file_name)
raise e
else
- raise TemplateError.new(@finder.find_base_path_for("#{template_path_without_extension}.#{template_extension}") ||
- @finder.view_paths.first, template_file_name, @assigns, template_source, e)
+ raise TemplateError.new(find_base_path_for("#{template_path_without_extension}.#{template_extension}") || view_paths.first, template_file_name, @assigns, template_source, e)
end
end
end
@@ -367,6 +371,45 @@ If you are rendering a subtemplate, you must now use controller-like partial syn
end
end
+ # Gets the full template path with base path for the given template_path and extension.
+ #
+ # full_template_path('users/show', 'html.erb')
+ # # => '~/rails/app/views/users/show.html.erb
+ #
+ def full_template_path(template_path, extension)
+ if @@cache_template_extensions
+ (@@cached_base_paths[template_path] ||= {})[extension.to_s] ||= find_full_template_path(template_path, extension)
+ else
+ find_full_template_path(template_path, extension)
+ end
+ end
+
+ # Gets the extension for an existing template with the given template_path.
+ # Returns the format with the extension if that template exists.
+ #
+ # pick_template_extension('users/show')
+ # # => 'html.erb'
+ #
+ # pick_template_extension('users/legacy')
+ # # => "rhtml"
+ #
+ def pick_template_extension(template_path)#:nodoc:
+ if @@cache_template_extensions
+ (@@cached_template_extension[template_path] ||= {})[template_format] ||= find_template_extension_for(template_path)
+ else
+ find_template_extension_for(template_path)
+ end
+ end
+
+ def file_exists?(template_path)#:nodoc:
+ template_file_name, template_file_extension = path_and_extension(template_path)
+ if template_file_extension
+ template_exists?(template_file_name, template_file_extension)
+ else
+ template_exists?(template_file_name, pick_template_extension(template_path))
+ end
+ end
+
# Returns true is the file may be rendered implicitly.
def file_public?(template_path)#:nodoc:
template_path.split('/').last[0,1] != '_'
@@ -379,12 +422,83 @@ If you are rendering a subtemplate, you must now use controller-like partial syn
@template_format = format.blank? ? :html : format.to_sym
end
+ # Adds a view_path to the front of the view_paths array.
+ # This change affects the current request only.
+ #
+ # @template.prepend_view_path("views/default")
+ # @template.prepend_view_path(["views/default", "views/custom"])
+ #
+ def prepend_view_path(path)
+ @view_paths.unshift(*path)
+ end
+
+ # Adds a view_path to the end of the view_paths array.
+ # This change affects the current request only.
+ #
+ # @template.append_view_path("views/default")
+ # @template.append_view_path(["views/default", "views/custom"])
+ #
+ def append_view_path(path)
+ @view_paths.push(*path)
+ end
+
private
def wrap_content_for_layout(content)
original_content_for_layout = @content_for_layout
@content_for_layout = content
returning(yield) { @content_for_layout = original_content_for_layout }
end
+
+ def find_full_template_path(template_path, extension)
+ file_name = "#{template_path}.#{extension}"
+ base_path = find_base_path_for(file_name)
+ base_path.blank? ? "" : "#{base_path}/#{file_name}"
+ end
+
+ # Asserts the existence of a template.
+ def template_exists?(template_path, extension)
+ file_path = full_template_path(template_path, extension)
+ !file_path.blank? && @@method_names.has_key?(file_path) || File.exist?(file_path)
+ end
+
+ # Splits the path and extension from the given template_path and returns as an array.
+ def path_and_extension(template_path)
+ template_path_without_extension = template_path.sub(/\.(\w+)$/, '')
+ [ template_path_without_extension, $1 ]
+ end
+
+ # 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)) }
+ 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 }
+ end
+
+ # Determines the template's file extension, such as rhtml, rxml, or rjs.
+ def find_template_extension_for(template_path)
+ find_template_extension_from_handler(template_path, true) ||
+ find_template_extension_from_handler(template_path) ||
+ find_template_extension_from_first_render()
+ end
+
+ def find_template_extension_from_handler(template_path, formatted = nil)
+ checked_template_path = formatted ? "#{template_path}.#{template_format}" : template_path
+
+ self.class.template_handler_extensions.each do |extension|
+ if template_exists?(checked_template_path, extension)
+ return formatted ? "#{template_format}.#{extension}" : extension.to_s
+ end
+ end
+ nil
+ end
+
+ # Determine the template extension from the <tt>@first_render</tt> filename
+ def find_template_extension_from_first_render
+ File.basename(@first_render.to_s)[/^[^.]+\.(.+)$/, 1]
+ end
# This method reads a template file.
def read_template_file(template_path, extension)
@@ -489,8 +603,7 @@ If you are rendering a subtemplate, you must now use controller-like partial syn
logger.debug "Backtrace: #{e.backtrace.join("\n")}"
end
- raise TemplateError.new(@finder.extract_base_path_from(file_name) ||
- @finder.view_paths.first, file_name || template, @assigns, template, e)
+ raise TemplateError.new(extract_base_path_from(file_name) || view_paths.first, file_name || template, @assigns, template, e)
end
@@compile_time[render_symbol] = Time.now
diff --git a/actionpack/lib/action_view/helpers/cache_helper.rb b/actionpack/lib/action_view/helpers/cache_helper.rb
index aa85b9fb40..ea505adfa7 100644
--- a/actionpack/lib/action_view/helpers/cache_helper.rb
+++ b/actionpack/lib/action_view/helpers/cache_helper.rb
@@ -32,7 +32,7 @@ module ActionView
# <i>Topics listed alphabetically</i>
# <% end %>
def cache(name = {}, options = nil, &block)
- template_extension = @finder.pick_template_extension(first_render)[/\.?(\w+)$/, 1].to_sym
+ template_extension = find_template_extension_for(first_render)[/\.?(\w+)$/, 1].to_sym
handler = Base.handler_class_for_extension(template_extension)
handler.new(@controller).cache_fragment(block, name, options)
end
diff --git a/actionpack/lib/action_view/template_finder.rb b/actionpack/lib/action_view/template_finder.rb
deleted file mode 100644
index 3d7acec33c..0000000000
--- a/actionpack/lib/action_view/template_finder.rb
+++ /dev/null
@@ -1,161 +0,0 @@
-module ActionView #:nodoc:
- class TemplateFinder #:nodoc:
-
- class InvalidViewPath < StandardError #:nodoc:
- end
-
- cattr_reader :processed_view_paths
- @@processed_view_paths = Hash.new {|hash, key| hash[key] = []}
-
- cattr_reader :file_extension_cache
- @@file_extension_cache = Hash.new {|hash, key|
- hash[key] = Hash.new {|hash, key| hash[key] = []}
- }
-
- class << self #:nodoc:
-
- # This method is not thread safe. Mutex should be used whenever this is accessed from an instance method
- def process_view_paths(*view_paths)
- view_paths.flatten.compact.each do |dir|
- next if @@processed_view_paths.has_key?(dir)
-
- @@processed_view_paths[dir] = []
- Dir.glob("#{dir}/**/*").each do |file|
- unless File.directory?(file)
- @@processed_view_paths[dir] << file.split(dir).last.sub(/^\//, '')
-
- # Build extension cache
- extension = file.split(".").last
- if template_handler_extensions.include?(extension)
- key = file.split(dir).last.sub(/^\//, '').sub(/\.(\w+)$/, '')
- @@file_extension_cache[dir][key] << extension
- end
- end
- end
- end
- end
-
- def update_extension_cache_for(extension)
- @@processed_view_paths.keys.each do |dir|
- Dir.glob("#{dir}/**/*.#{extension}").each do |file|
- key = file.split(dir).last.sub(/^\//, '').sub(/\.(\w+)$/, '')
- @@file_extension_cache[dir][key] << extension
- end
- end
- end
-
- def template_handler_extensions
- ActionView::Base.template_handler_extensions
- end
-
- def reload!
- view_paths = @@processed_view_paths.keys
-
- @@processed_view_paths = Hash.new {|hash, key| hash[key] = []}
- @@file_extension_cache = Hash.new {|hash, key|
- hash[key] = Hash.new {|hash, key| hash[key] = []}
- }
-
- process_view_paths(view_paths)
- end
- end
-
- attr_accessor :view_paths
-
- def initialize(*args)
- @template = args.shift
-
- @view_paths = args.flatten
- @view_paths = @view_paths.respond_to?(:find) ? @view_paths.dup : [*@view_paths].compact
- check_view_paths(@view_paths)
- end
-
- def prepend_view_path(path)
- @view_paths.unshift(*path)
-
- self.class.process_view_paths(path)
- end
-
- def append_view_path(path)
- @view_paths.push(*path)
-
- self.class.process_view_paths(path)
- end
-
- def view_paths=(path)
- @view_paths = path
- self.class.process_view_paths(path)
- end
-
- def pick_template(template_path, extension)
- file_name = "#{template_path}.#{extension}"
- base_path = find_base_path_for(file_name)
- base_path.blank? ? false : "#{base_path}/#{file_name}"
- end
- alias_method :template_exists?, :pick_template
-
- def file_exists?(template_path)
- template_file_name, template_file_extension = path_and_extension(template_path)
- if template_file_extension
- template_exists?(template_file_name, template_file_extension)
- else
- template_exists?(template_file_name, pick_template_extension(template_path))
- end
- end
-
- def find_base_path_for(template_file_name)
- @view_paths.find { |path| processed_view_paths[path].include?(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 }
- end
-
- # Gets the extension for an existing template with the given template_path.
- # Returns the format with the extension if that template exists.
- #
- # pick_template_extension('users/show')
- # # => 'html.erb'
- #
- # pick_template_extension('users/legacy')
- # # => "rhtml"
- #
- def pick_template_extension(template_path)
- find_template_extension_from_handler(template_path) || find_template_extension_from_first_render
- end
-
- def find_template_extension_from_handler(template_path)
- formatted_template_path = "#{template_path}.#{@template.template_format}"
-
- view_paths.each do |path|
- if (extensions = @@file_extension_cache[path][formatted_template_path]).any?
- return "#{@template.template_format}.#{extensions.first}"
- elsif (extensions = @@file_extension_cache[path][template_path]).any?
- return extensions.first.to_s
- end
- end
- nil
- end
-
- # Splits the path and extension from the given template_path and returns as an array.
- def path_and_extension(template_path)
- template_path_without_extension = template_path.sub(/\.(\w+)$/, '')
- [ template_path_without_extension, $1 ]
- end
-
- # Determine the template extension from the <tt>@first_render</tt> filename
- def find_template_extension_from_first_render
- File.basename(@template.first_render.to_s)[/^[^.]+\.(.+)$/, 1]
- end
-
- private
-
- def check_view_paths(view_paths)
- view_paths.each do |path|
- raise(InvalidViewPath, "Unprocessed view path found in #{view_paths.inspect}") unless processed_view_paths.has_key?(path)
- end
- end
-
- end
-end
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index febdbd0993..ce89b9dbbb 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -437,7 +437,11 @@ class MimeControllerTest < Test::Unit::TestCase
end
class AbstractPostController < ActionController::Base
- self.view_paths = File.dirname(__FILE__) + "/../fixtures/post_test/"
+ class << self
+ def view_paths
+ [ File.dirname(__FILE__) + "/../fixtures/post_test/" ]
+ end
+ end
end
# For testing layouts which are set automatically
diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb
index 4a9b0e9ddf..eb19b2e391 100644
--- a/actionpack/test/controller/new_render_test.rb
+++ b/actionpack/test/controller/new_render_test.rb
@@ -78,6 +78,11 @@ class NewRenderTestController < ActionController::Base
@secret = 'in the sauce'
render :file => 'test/render_file_with_ivar', :use_full_path => true
end
+
+ def render_file_not_using_full_path_with_relative_path
+ @secret = 'in the sauce'
+ render :file => 'test/../test/render_file_with_ivar', :use_full_path => true
+ end
def render_file_not_using_full_path_with_dot_in_path
@secret = 'in the sauce'
@@ -483,6 +488,11 @@ class NewRenderTest < Test::Unit::TestCase
assert_equal "The secret is in the sauce\n", @response.body
end
+ def test_render_file_not_using_full_path_with_relative_path
+ get :render_file_not_using_full_path_with_relative_path
+ assert_equal "The secret is in the sauce\n", @response.body
+ end
+
def test_render_file_not_using_full_path_with_dot_in_path
get :render_file_not_using_full_path_with_dot_in_path
assert_equal "The secret is in the sauce\n", @response.body
diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb
index 0516da32d8..b1ca400779 100644
--- a/actionpack/test/controller/view_paths_test.rb
+++ b/actionpack/test/controller/view_paths_test.rb
@@ -16,7 +16,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase
def hello_world_at_request_time() render(:action => 'hello_world') end
private
def add_view_path
- prepend_view_path "#{LOAD_PATH_ROOT}/override"
+ self.class.view_paths.unshift "#{LOAD_PATH_ROOT}/override"
end
end
@@ -27,6 +27,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase
def setup
TestController.view_paths = nil
+ ActionView::Base.cache_template_extensions = false
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@@ -44,6 +45,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase
def teardown
ActiveSupport::Deprecation.behavior = @old_behavior
+ ActionView::Base.cache_template_extensions = true
end
def test_template_load_path_was_set_correctly
@@ -97,7 +99,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase
end
def test_view_paths_override
- TestController.prepend_view_path "#{LOAD_PATH_ROOT}/override"
+ TestController.view_paths.unshift "#{LOAD_PATH_ROOT}/override"
get :hello_world
assert_response :success
assert_equal "Hello overridden world!", @response.body
diff --git a/actionpack/test/template/template_finder_test.rb b/actionpack/test/template/template_finder_test.rb
deleted file mode 100644
index c1da5be0f4..0000000000
--- a/actionpack/test/template/template_finder_test.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-require 'abstract_unit'
-
-class TemplateFinderTest < Test::Unit::TestCase
-
- LOAD_PATH_ROOT = File.join(File.dirname(__FILE__), '..', 'fixtures')
-
- def setup
- ActionView::TemplateFinder.process_view_paths(LOAD_PATH_ROOT)
- ActionView::Base::register_template_handler :mab, Class.new(ActionView::TemplateHandler)
- @template = ActionView::Base.new
- @finder = ActionView::TemplateFinder.new(@template, LOAD_PATH_ROOT)
- end
-
- def test_should_raise_exception_for_unprocessed_view_path
- assert_raises ActionView::TemplateFinder::InvalidViewPath do
- ActionView::TemplateFinder.new(@template, File.dirname(__FILE__))
- end
- end
-
- def test_should_cache_file_extension_properly
- assert_equal ["builder", "erb", "rhtml", "rjs", "rxml", "mab"].sort,
- ActionView::TemplateFinder.file_extension_cache[LOAD_PATH_ROOT].values.flatten.uniq.sort
-
- assert_equal Dir.glob("#{LOAD_PATH_ROOT}/**/*.{erb,rjs,rjs,builder,rxml,mab}").size,
- ActionView::TemplateFinder.file_extension_cache[LOAD_PATH_ROOT].keys.size
- end
-
- def test_should_cache_dir_content_properly
- assert ActionView::TemplateFinder.processed_view_paths[LOAD_PATH_ROOT]
- assert_equal Dir.glob("#{LOAD_PATH_ROOT}/**/*").find_all {|f| !File.directory?(f) }.size,
- ActionView::TemplateFinder.processed_view_paths[LOAD_PATH_ROOT].size
- end
-
- uses_mocha 'Template finder tests' do
-
- def test_should_update_extension_cache_when_template_handler_is_registered
- ActionView::TemplateFinder.expects(:update_extension_cache_for).with("funky")
- ActionView::Base::register_template_handler :funky, Class.new(ActionView::TemplateHandler)
- end
-
- end
-
-end