2008-05-18 06:22:34 +02:00
|
|
|
require 'active_support/test_case'
|
|
|
|
|
|
|
|
module ActionView
|
2009-02-04 21:26:08 +01: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-05-18 06:22:34 +02:00
|
|
|
class TestCase < ActiveSupport::TestCase
|
2009-02-04 21:26:08 +01:00
|
|
|
include ActionController::TestCase::Assertions
|
|
|
|
include ActionController::TestProcess
|
|
|
|
|
2008-05-18 06:22:34 +02: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-06-02 08:35:38 +02:00
|
|
|
nil
|
2008-05-18 06:22:34 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-27 07:47:01 +01:00
|
|
|
include ActionView::Helpers
|
2008-05-18 06:22:34 +02:00
|
|
|
include ActionController::PolymorphicRoutes
|
|
|
|
include ActionController::RecordIdentifier
|
|
|
|
|
|
|
|
setup :setup_with_helper_class
|
|
|
|
|
|
|
|
def setup_with_helper_class
|
2008-06-02 08:35:38 +02:00
|
|
|
if helper_class && !self.class.ancestors.include?(helper_class)
|
|
|
|
self.class.send(:include, helper_class)
|
|
|
|
end
|
2008-10-27 07:47:01 +01:00
|
|
|
|
|
|
|
self.output_buffer = ''
|
2008-05-18 06:22:34 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
class TestController < ActionController::Base
|
2009-02-04 21:26:08 +01:00
|
|
|
attr_accessor :request, :response, :params
|
2008-05-18 06:22:34 +02:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
@request = ActionController::TestRequest.new
|
|
|
|
@response = ActionController::TestResponse.new
|
2009-02-04 21:26:08 +01:00
|
|
|
|
|
|
|
@params = {}
|
|
|
|
send(:initialize_current_url)
|
2008-05-18 06:22:34 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-27 07:47:01 +01:00
|
|
|
protected
|
|
|
|
attr_accessor :output_buffer
|
|
|
|
|
2008-05-18 06:22:34 +02:00
|
|
|
private
|
|
|
|
def method_missing(selector, *args)
|
|
|
|
controller = TestController.new
|
2008-10-27 07:47:01 +01:00
|
|
|
return controller.__send__(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
|
2008-05-18 06:22:34 +02:00
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|