Updated README.rdoc again
[feedcatcher.git] / vendor / rails / actionpack / lib / action_view / test_case.rb
1 require 'active_support/test_case'
2
3 module ActionView
4 class Base
5 alias_method :initialize_without_template_tracking, :initialize
6 def initialize(*args)
7 @_rendered = { :template => nil, :partials => Hash.new(0) }
8 initialize_without_template_tracking(*args)
9 end
10 end
11
12 module Renderable
13 alias_method :render_without_template_tracking, :render
14 def render(view, local_assigns = {})
15 if respond_to?(:path) && !is_a?(InlineTemplate)
16 rendered = view.instance_variable_get(:@_rendered)
17 rendered[:partials][self] += 1 if is_a?(RenderablePartial)
18 rendered[:template] ||= self
19 end
20 render_without_template_tracking(view, local_assigns)
21 end
22 end
23
24 class TestCase < ActiveSupport::TestCase
25 include ActionController::TestCase::Assertions
26 include ActionController::TestProcess
27
28 class_inheritable_accessor :helper_class
29 @@helper_class = nil
30
31 class << self
32 def tests(helper_class)
33 self.helper_class = helper_class
34 end
35
36 def helper_class
37 if current_helper_class = read_inheritable_attribute(:helper_class)
38 current_helper_class
39 else
40 self.helper_class = determine_default_helper_class(name)
41 end
42 end
43
44 def determine_default_helper_class(name)
45 name.sub(/Test$/, '').constantize
46 rescue NameError
47 nil
48 end
49 end
50
51 include ActionView::Helpers
52 include ActionController::PolymorphicRoutes
53 include ActionController::RecordIdentifier
54
55 setup :setup_with_helper_class
56
57 def setup_with_helper_class
58 if helper_class && !self.class.ancestors.include?(helper_class)
59 self.class.send(:include, helper_class)
60 end
61
62 self.output_buffer = ''
63 end
64
65 class TestController < ActionController::Base
66 attr_accessor :request, :response, :params
67
68 def initialize
69 @request = ActionController::TestRequest.new
70 @response = ActionController::TestResponse.new
71
72 @params = {}
73 send(:initialize_current_url)
74 end
75 end
76
77 protected
78 attr_accessor :output_buffer
79
80 private
81 def method_missing(selector, *args)
82 controller = TestController.new
83 return controller.__send__(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
84 super
85 end
86 end
87 end