2008-04-20 02:06:57 +08:00
|
|
|
module ActionView
|
2008-12-12 01:06:35 +08: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
|
|
|
|
end
|
|
|
|
|
|
|
|
module Renderable
|
|
|
|
alias_method :render_without_template_tracking, :render
|
|
|
|
def render(view, local_assigns = {})
|
|
|
|
if respond_to?(:path) && !is_a?(InlineTemplate)
|
|
|
|
rendered = view.instance_variable_get(:@_rendered)
|
|
|
|
rendered[:partials][self] += 1 if is_a?(RenderablePartial)
|
|
|
|
rendered[:template] ||= self
|
|
|
|
end
|
|
|
|
render_without_template_tracking(view, local_assigns)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-04-20 02:06:57 +08:00
|
|
|
class TestCase < ActiveSupport::TestCase
|
2008-11-08 04:42:34 +08:00
|
|
|
include ActionController::TestCase::Assertions
|
|
|
|
|
2008-04-20 02:06:57 +08: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 16:38:56 +08:00
|
|
|
nil
|
2008-04-20 02:06:57 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-08-26 10:24:48 +08:00
|
|
|
include ActionView::Helpers
|
2008-04-20 02:06:57 +08:00
|
|
|
include ActionController::PolymorphicRoutes
|
|
|
|
include ActionController::RecordIdentifier
|
|
|
|
|
|
|
|
setup :setup_with_helper_class
|
|
|
|
|
|
|
|
def setup_with_helper_class
|
2008-05-26 16:38:56 +08:00
|
|
|
if helper_class && !self.class.ancestors.include?(helper_class)
|
|
|
|
self.class.send(:include, helper_class)
|
|
|
|
end
|
2008-06-09 11:05:39 +08:00
|
|
|
|
|
|
|
self.output_buffer = ''
|
2008-04-20 02:06:57 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
class TestController < ActionController::Base
|
|
|
|
attr_accessor :request, :response
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@request = ActionController::TestRequest.new
|
|
|
|
@response = ActionController::TestResponse.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-09 11:05:39 +08:00
|
|
|
protected
|
|
|
|
attr_accessor :output_buffer
|
|
|
|
|
2008-04-20 02:06:57 +08:00
|
|
|
private
|
|
|
|
def method_missing(selector, *args)
|
|
|
|
controller = TestController.new
|
2008-09-01 04:15:26 +08:00
|
|
|
return controller.__send__(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
|
2008-04-20 02:06:57 +08:00
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|