2009-01-06 18:35:46 -05:00
|
|
|
require 'active_support/test_case'
|
|
|
|
|
2008-04-19 14:06:57 -04:00
|
|
|
module ActionView
|
2008-12-11 12:06:35 -05:00
|
|
|
class Base
|
|
|
|
alias_method :initialize_without_template_tracking, :initialize
|
|
|
|
def initialize(*args)
|
|
|
|
@_rendered = { :template => nil, :partials => Hash.new(0) }
|
|
|
|
initialize_without_template_tracking(*args)
|
|
|
|
end
|
2009-01-22 17:18:10 -05:00
|
|
|
|
|
|
|
alias_method :_render_template_without_template_tracking, :_render_template
|
|
|
|
def _render_template(template, local_assigns = {})
|
|
|
|
if template.respond_to?(:path) && !template.is_a?(InlineTemplate)
|
|
|
|
@_rendered[:partials][template] += 1 if template.is_a?(RenderablePartial)
|
|
|
|
@_rendered[:template] ||= template
|
2008-12-11 12:06:35 -05:00
|
|
|
end
|
2009-01-22 17:18:10 -05:00
|
|
|
_render_template_without_template_tracking(template, local_assigns)
|
|
|
|
end
|
2008-12-11 12:06:35 -05:00
|
|
|
end
|
|
|
|
|
2008-04-19 14:06:57 -04:00
|
|
|
class TestCase < ActiveSupport::TestCase
|
2008-11-07 15:42:34 -05:00
|
|
|
include ActionController::TestCase::Assertions
|
2009-01-07 16:23:10 -05:00
|
|
|
include ActionController::TestProcess
|
2008-11-07 15:42:34 -05:00
|
|
|
|
2008-04-19 14:06:57 -04:00
|
|
|
class_inheritable_accessor :helper_class
|
|
|
|
@@helper_class = nil
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def tests(helper_class)
|
|
|
|
self.helper_class = helper_class
|
|
|
|
end
|
|
|
|
|
|
|
|
def helper_class
|
|
|
|
if current_helper_class = read_inheritable_attribute(:helper_class)
|
|
|
|
current_helper_class
|
|
|
|
else
|
|
|
|
self.helper_class = determine_default_helper_class(name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def determine_default_helper_class(name)
|
|
|
|
name.sub(/Test$/, '').constantize
|
|
|
|
rescue NameError
|
2008-05-26 04:38:56 -04:00
|
|
|
nil
|
2008-04-19 14:06:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-08-25 22:24:48 -04:00
|
|
|
include ActionView::Helpers
|
2008-04-19 14:06:57 -04:00
|
|
|
include ActionController::PolymorphicRoutes
|
|
|
|
include ActionController::RecordIdentifier
|
|
|
|
|
|
|
|
setup :setup_with_helper_class
|
|
|
|
|
|
|
|
def setup_with_helper_class
|
2008-05-26 04:38:56 -04:00
|
|
|
if helper_class && !self.class.ancestors.include?(helper_class)
|
|
|
|
self.class.send(:include, helper_class)
|
|
|
|
end
|
2008-06-08 23:05:39 -04:00
|
|
|
|
|
|
|
self.output_buffer = ''
|
2008-04-19 14:06:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class TestController < ActionController::Base
|
2008-12-15 12:47:39 -05:00
|
|
|
attr_accessor :request, :response, :params
|
2008-04-19 14:06:57 -04:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
@request = ActionController::TestRequest.new
|
|
|
|
@response = ActionController::TestResponse.new
|
2008-12-15 12:47:39 -05:00
|
|
|
|
|
|
|
@params = {}
|
|
|
|
send(:initialize_current_url)
|
2008-04-19 14:06:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-08 23:05:39 -04:00
|
|
|
protected
|
|
|
|
attr_accessor :output_buffer
|
|
|
|
|
2008-04-19 14:06:57 -04:00
|
|
|
private
|
|
|
|
def method_missing(selector, *args)
|
|
|
|
controller = TestController.new
|
2008-08-31 16:15:26 -04:00
|
|
|
return controller.__send__(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
|
2008-04-19 14:06:57 -04:00
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|