c69f9455b2424f82e8045f65ec29a8a2c985fb80
[depot.git] / test_case.rb
1 require 'active_support/test_case'
2
3 module ActionView
4 class TestCase < ActiveSupport::TestCase
5 class_inheritable_accessor :helper_class
6 @@helper_class = nil
7
8 class << self
9 def tests(helper_class)
10 self.helper_class = helper_class
11 end
12
13 def helper_class
14 if current_helper_class = read_inheritable_attribute(:helper_class)
15 current_helper_class
16 else
17 self.helper_class = determine_default_helper_class(name)
18 end
19 end
20
21 def determine_default_helper_class(name)
22 name.sub(/Test$/, '').constantize
23 rescue NameError
24 nil
25 end
26 end
27
28 include ActionView::Helpers
29 include ActionController::PolymorphicRoutes
30 include ActionController::RecordIdentifier
31
32 setup :setup_with_helper_class
33
34 def setup_with_helper_class
35 if helper_class && !self.class.ancestors.include?(helper_class)
36 self.class.send(:include, helper_class)
37 end
38
39 self.output_buffer = ''
40 end
41
42 class TestController < ActionController::Base
43 attr_accessor :request, :response
44
45 def initialize
46 @request = ActionController::TestRequest.new
47 @response = ActionController::TestResponse.new
48 end
49 end
50
51 protected
52 attr_accessor :output_buffer
53
54 private
55 def method_missing(selector, *args)
56 controller = TestController.new
57 return controller.__send__(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
58 super
59 end
60 end
61 end