From 91125f9927ffbe1a16494910ae0e8228a4400439 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Sun, 2 May 2010 09:20:17 -0500 Subject: move FixtureResolver to a file that is accessible outside Rails' own tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#4522 state:resolved] Signed-off-by: José Valim --- actionpack/lib/action_view/testing/resolvers.rb | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 actionpack/lib/action_view/testing/resolvers.rb (limited to 'actionpack/lib') 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 + -- cgit v1.2.3