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 +++++++++++++++++++++++++ actionpack/test/abstract_unit.rb | 2 +- actionpack/test/controller/layout_test.rb | 2 -- actionpack/test/lib/fixture_template.rb | 29 -------------------- 4 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 actionpack/lib/action_view/testing/resolvers.rb delete mode 100644 actionpack/test/lib/fixture_template.rb 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 + diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index f3ff258016..89ba0990f1 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -16,8 +16,8 @@ require 'test/unit' require 'abstract_controller' require 'action_controller' require 'action_view' +require 'action_view/testing/resolvers' require 'action_dispatch' -require 'fixture_template' require 'active_support/dependencies' require 'active_model' diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index 48be7571ea..165c61ffad 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -10,8 +10,6 @@ ActionView::Template::register_template_handler :mab, ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/layout_tests/' ] -require "fixture_template" - class LayoutTest < ActionController::Base def self.controller_path; 'views' end def self._implied_layout_name; to_s.underscore.gsub(/_controller$/, '') ; end diff --git a/actionpack/test/lib/fixture_template.rb b/actionpack/test/lib/fixture_template.rb deleted file mode 100644 index b49ccd39ca..0000000000 --- a/actionpack/test/lib/fixture_template.rb +++ /dev/null @@ -1,29 +0,0 @@ -module ActionView #:nodoc: - 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 \ No newline at end of file -- cgit v1.2.3