2008-04-19 18:06:57 +00:00
|
|
|
module ActionView
|
|
|
|
class TestCase < ActiveSupport::TestCase
|
2008-11-07 20:42:34 +00:00
|
|
|
include ActionController::TestCase::Assertions
|
|
|
|
|
2008-04-19 18:06:57 +00: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 08:38:56 +00:00
|
|
|
nil
|
2008-04-19 18:06:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-08-26 02:24:48 +00:00
|
|
|
include ActionView::Helpers
|
2008-04-19 18:06:57 +00:00
|
|
|
include ActionController::PolymorphicRoutes
|
|
|
|
include ActionController::RecordIdentifier
|
|
|
|
|
|
|
|
setup :setup_with_helper_class
|
|
|
|
|
|
|
|
def setup_with_helper_class
|
2008-05-26 08:38:56 +00:00
|
|
|
if helper_class && !self.class.ancestors.include?(helper_class)
|
|
|
|
self.class.send(:include, helper_class)
|
|
|
|
end
|
2008-06-09 03:05:39 +00:00
|
|
|
|
|
|
|
self.output_buffer = ''
|
2008-04-19 18:06:57 +00: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 03:05:39 +00:00
|
|
|
protected
|
|
|
|
attr_accessor :output_buffer
|
|
|
|
|
2008-04-19 18:06:57 +00:00
|
|
|
private
|
|
|
|
def method_missing(selector, *args)
|
|
|
|
controller = TestController.new
|
2008-08-31 20:15:26 +00:00
|
|
|
return controller.__send__(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
|
2008-04-19 18:06:57 +00:00
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|