aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/lib/fixture_template.rb66
-rw-r--r--actionpack/test/new_base/render_file_test.rb2
-rw-r--r--actionpack/test/template/compiled_templates_test.rb3
3 files changed, 16 insertions, 55 deletions
diff --git a/actionpack/test/lib/fixture_template.rb b/actionpack/test/lib/fixture_template.rb
index 9a9abb691d..0a365b3a7e 100644
--- a/actionpack/test/lib/fixture_template.rb
+++ b/actionpack/test/lib/fixture_template.rb
@@ -1,70 +1,28 @@
module ActionView #:nodoc:
- class FixtureResolver < Resolver
+ class FixtureResolver < PathResolver
def initialize(hash = {}, options = {})
super(options)
@hash = hash
end
- def find_templates(name, details, prefix, partial)
- if regexp = details_to_regexp(name, details, prefix, partial)
- cached(regexp) do
- templates = []
- @hash.select { |k,v| k =~ regexp }.each do |path, source|
- templates << Template.new(source, path, *path_to_details(path))
- end
- templates.sort_by {|t| -t.details.values.compact.size }
- end
- end
- end
-
private
- def formats_regexp
- @formats_regexp ||= begin
- formats = Mime::SET.symbols
- '(?:' + formats.map { |l| "\\.#{Regexp.escape(l.to_s)}" }.join('|') + ')?'
- end
- end
-
- def handler_regexp
- e = TemplateHandlers.extensions.map{|h| "\\.#{Regexp.escape(h.to_s)}"}.join("|")
- "(?:#{e})"
+ def or_extensions(array)
+ "(?:" << array.map {|e| e && Regexp.escape(".#{e}")}.join("|") << ")"
end
- def details_to_regexp(name, details, prefix, partial)
- path = ""
- path << "#{prefix}/" unless prefix.empty?
- path << (partial ? "_#{name}" : name)
-
- extensions = ""
- [:locales, :formats].each do |k|
- # TODO: OMG NO
- if details[k] == [:"*/*"]
- extensions << formats_regexp if k == :formats
- elsif exts = details[k]
- extensions << '(?:' + exts.map {|e| "\\.#{Regexp.escape(e.to_s)}"}.join('|') + ')?'
- else
- extensions << formats_regexp if k == :formats
- end
+ def query(path, exts)
+ query = Regexp.escape(path)
+ exts.each do |ext|
+ query << '(?:' << ext.map {|e| e && Regexp.escape(".#{e}") }.join('|') << ')'
end
- %r'^#{Regexp.escape(path)}#{extensions}#{handler_regexp}$'
- end
-
- # TODO: fix me
- # :api: plugin
- def path_to_details(path)
- # [:erb, :format => :html, :locale => :en, :partial => true/false]
- if m = path.match(%r'(_)?[\w-]+((?:\.[\w-]+)*)\.(\w+)$')
- partial = m[1] == '_'
- details = (m[2]||"").split('.').reject { |e| e.empty? }
- handler = Template.handler_class_for_extension(m[3])
-
- format = Mime[details.last] && details.pop.to_sym
- locale = details.last && details.pop.to_sym
-
- return handler, :format => format, :locale => locale, :partial => partial
+ templates = []
+ @hash.select { |k,v| k =~ /^#{query}$/ }.each do |path, source|
+ templates << Template.new(source, path, *path_to_details(path))
end
+ templates.sort_by {|t| -t.details.values.compact.size }
end
+
end
end \ No newline at end of file
diff --git a/actionpack/test/new_base/render_file_test.rb b/actionpack/test/new_base/render_file_test.rb
index 769949be0c..8d7f49dbc2 100644
--- a/actionpack/test/new_base/render_file_test.rb
+++ b/actionpack/test/new_base/render_file_test.rb
@@ -3,7 +3,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
module RenderFile
class BasicController < ActionController::Base
- self.view_paths = "."
+ self.view_paths = File.dirname(__FILE__)
def index
render :file => File.join(File.dirname(__FILE__), *%w[.. fixtures test hello_world])
diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb
index 7734e6da73..632988bb2e 100644
--- a/actionpack/test/template/compiled_templates_test.rb
+++ b/actionpack/test/template/compiled_templates_test.rb
@@ -14,6 +14,9 @@ class CompiledTemplatesTest < Test::Unit::TestCase
assert_equal "two", render(:file => "test/render_file_with_locals_and_default.erb", :locals => { :secret => "two" })
end
+ # This is broken in 1.8.6 (not supported in Rails 3.0) because the cache uses a Hash
+ # key. Since Ruby 1.8.6 implements Hash#hash using the hash's object_id, it will never
+ # successfully get a cache hit here.
def test_template_changes_are_not_reflected_with_cached_templates
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
modify_template "test/hello_world.erb", "Goodbye world!" do