aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_view/testing/resolvers.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/testing/resolvers.rb b/actionpack/lib/action_view/testing/resolvers.rb
new file mode 100644
index 0000000000..f468e57c26
--- /dev/null
+++ b/actionpack/lib/action_view/testing/resolvers.rb
@@ -0,0 +1,35 @@
+require 'action_view/template/resolver'
+
+module ActionView #:nodoc:
+ # Use FixtureResolver in your tests to simulate the presence of files on the
+ # file system. This is used internally by Rails' own test suite, and is
+ # useful for testing extensions that have no way of knowing what the file
+ # system will look like at runtime.
+ class FixtureResolver < PathResolver
+ attr_reader :hash
+
+ def initialize(hash = {})
+ super()
+ @hash = hash
+ end
+
+ private
+
+ def query(path, exts, formats)
+ query = Regexp.escape(path)
+ exts.each do |ext|
+ query << '(' << ext.map {|e| e && Regexp.escape(".#{e}") }.join('|') << '|)'
+ end
+
+ templates = []
+ @hash.select { |k,v| k =~ /^#{query}$/ }.each do |path, source|
+ handler, format = extract_handler_and_format(path, formats)
+ templates << Template.new(source, path, handler,
+ :virtual_path => path, :format => format)
+ end
+
+ templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size }
+ end
+ end
+end
+