aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/testing/resolvers.rb
diff options
context:
space:
mode:
authorDavid Chelimsky <dchelimsky@gmail.com>2010-05-02 09:20:17 -0500
committerJosé Valim <jose.valim@gmail.com>2010-05-02 22:45:54 +0200
commit91125f9927ffbe1a16494910ae0e8228a4400439 (patch)
tree1af9a8f241007153e6c35bd3cc41489dccd043c7 /actionpack/lib/action_view/testing/resolvers.rb
parenta76c7e68d5e39f5962d9cb85c98e6a8e96f8b3af (diff)
downloadrails-91125f9927ffbe1a16494910ae0e8228a4400439.tar.gz
rails-91125f9927ffbe1a16494910ae0e8228a4400439.tar.bz2
rails-91125f9927ffbe1a16494910ae0e8228a4400439.zip
move FixtureResolver to a file that is accessible outside Rails' own tests
[#4522 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/lib/action_view/testing/resolvers.rb')
-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
+