Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 5686 Bytes
1 | require 'abstract_unit' |
2 | |
3 | ActionController::Base.helpers_dir = File.dirname(__FILE__) + '/../fixtures/helpers' |
4 | |
5 | class TestController < ActionController::Base |
6 | attr_accessor :delegate_attr |
7 | def delegate_method() end |
8 | def rescue_action(e) raise end |
9 | end |
10 | |
11 | module Fun |
12 | class GamesController < ActionController::Base |
13 | def render_hello_world |
14 | render :inline => "hello: <%= stratego %>" |
15 | end |
16 | |
17 | def rescue_action(e) raise end |
18 | end |
19 | |
20 | class PdfController < ActionController::Base |
21 | def test |
22 | render :inline => "test: <%= foobar %>" |
23 | end |
24 | |
25 | def rescue_action(e) raise end |
26 | end |
27 | end |
28 | |
29 | class ApplicationController < ActionController::Base |
30 | helper :all |
31 | end |
32 | |
33 | module LocalAbcHelper |
34 | def a() end |
35 | def b() end |
36 | def c() end |
37 | end |
38 | |
39 | class HelperTest < Test::Unit::TestCase |
40 | def setup |
41 | # Increment symbol counter. |
42 | @symbol = (@@counter ||= 'A0').succ!.dup |
43 | |
44 | # Generate new controller class. |
45 | controller_class_name = "Helper#{@symbol}Controller" |
46 | eval("class #{controller_class_name} < TestController; end") |
47 | @controller_class = self.class.const_get(controller_class_name) |
48 | |
49 | # Set default test helper. |
50 | self.test_helper = LocalAbcHelper |
51 | end |
52 | |
53 | def test_deprecated_helper |
54 | assert_equal expected_helper_methods, missing_methods |
55 | assert_nothing_raised { @controller_class.helper TestHelper } |
56 | assert_equal [], missing_methods |
57 | end |
58 | |
59 | def test_declare_helper |
60 | require 'abc_helper' |
61 | self.test_helper = AbcHelper |
62 | assert_equal expected_helper_methods, missing_methods |
63 | assert_nothing_raised { @controller_class.helper :abc } |
64 | assert_equal [], missing_methods |
65 | end |
66 | |
67 | def test_declare_missing_helper |
68 | assert_equal expected_helper_methods, missing_methods |
69 | assert_raise(MissingSourceFile) { @controller_class.helper :missing } |
70 | end |
71 | |
72 | def test_declare_missing_file_from_helper |
73 | require 'broken_helper' |
74 | rescue LoadError => e |
75 | assert_nil(/\bbroken_helper\b/.match(e.to_s)[1]) |
76 | end |
77 | |
78 | def test_helper_block |
79 | assert_nothing_raised { |
80 | @controller_class.helper { def block_helper_method; end } |
81 | } |
82 | assert master_helper_methods.include?('block_helper_method') |
83 | end |
84 | |
85 | def test_helper_block_include |
86 | assert_equal expected_helper_methods, missing_methods |
87 | assert_nothing_raised { |
88 | @controller_class.helper { include HelperTest::TestHelper } |
89 | } |
90 | assert_equal [], missing_methods |
91 | end |
92 | |
93 | def test_helper_method |
94 | assert_nothing_raised { @controller_class.helper_method :delegate_method } |
95 | assert master_helper_methods.include?('delegate_method') |
96 | end |
97 | |
98 | def test_helper_attr |
99 | assert_nothing_raised { @controller_class.helper_attr :delegate_attr } |
100 | assert master_helper_methods.include?('delegate_attr') |
101 | assert master_helper_methods.include?('delegate_attr=') |
102 | end |
103 | |
104 | def test_helper_for_nested_controller |
105 | request = ActionController::TestRequest.new |
106 | response = ActionController::TestResponse.new |
107 | request.action = 'render_hello_world' |
108 | |
109 | assert_equal 'hello: Iz guuut!', Fun::GamesController.process(request, response).body |
110 | end |
111 | |
112 | def test_helper_for_acronym_controller |
113 | request = ActionController::TestRequest.new |
114 | response = ActionController::TestResponse.new |
115 | request.action = 'test' |
116 | |
117 | assert_equal 'test: baz', Fun::PdfController.process(request, response).body |
118 | end |
119 | |
120 | def test_all_helpers |
121 | methods = ApplicationController.master_helper_module.instance_methods.map(&:to_s) |
122 | |
123 | # abc_helper.rb |
124 | assert methods.include?('bare_a') |
125 | |
126 | # fun/games_helper.rb |
127 | assert methods.include?('stratego') |
128 | |
129 | # fun/pdf_helper.rb |
130 | assert methods.include?('foobar') |
131 | end |
132 | |
133 | def test_all_helpers_with_alternate_helper_dir |
134 | @controller_class.helpers_dir = File.dirname(__FILE__) + '/../fixtures/alternate_helpers' |
135 | |
136 | # Reload helpers |
137 | @controller_class.master_helper_module = Module.new |
138 | @controller_class.helper :all |
139 | |
140 | # helpers/abc_helper.rb should not be included |
141 | assert !master_helper_methods.include?('bare_a') |
142 | |
143 | # alternate_helpers/foo_helper.rb |
144 | assert master_helper_methods.include?('baz') |
145 | end |
146 | |
147 | def test_helper_proxy |
148 | methods = ApplicationController.helpers.methods.map(&:to_s) |
149 | |
150 | # ActionView |
151 | assert methods.include?('pluralize') |
152 | |
153 | # abc_helper.rb |
154 | assert methods.include?('bare_a') |
155 | |
156 | # fun/games_helper.rb |
157 | assert methods.include?('stratego') |
158 | |
159 | # fun/pdf_helper.rb |
160 | assert methods.include?('foobar') |
161 | end |
162 | |
163 | private |
164 | def expected_helper_methods |
165 | TestHelper.instance_methods.map(&:to_s) |
166 | end |
167 | |
168 | def master_helper_methods |
169 | @controller_class.master_helper_module.instance_methods.map(&:to_s) |
170 | end |
171 | |
172 | def missing_methods |
173 | expected_helper_methods - master_helper_methods |
174 | end |
175 | |
176 | def test_helper=(helper_module) |
177 | silence_warnings { self.class.const_set('TestHelper', helper_module) } |
178 | end |
179 | end |
180 | |
181 | |
182 | class IsolatedHelpersTest < Test::Unit::TestCase |
183 | class A < ActionController::Base |
184 | def index |
185 | render :inline => '<%= shout %>' |
186 | end |
187 | |
188 | def rescue_action(e) raise end |
189 | end |
190 | |
191 | class B < A |
192 | helper { def shout; 'B' end } |
193 | |
194 | def index |
195 | render :inline => '<%= shout %>' |
196 | end |
197 | end |
198 | |
199 | class C < A |
200 | helper { def shout; 'C' end } |
201 | |
202 | def index |
203 | render :inline => '<%= shout %>' |
204 | end |
205 | end |
206 | |
207 | def setup |
208 | @request = ActionController::TestRequest.new |
209 | @response = ActionController::TestResponse.new |
210 | @request.action = 'index' |
211 | end |
212 | |
213 | def test_helper_in_a |
214 | assert_raise(NameError) { A.process(@request, @response) } |
215 | end |
216 | |
217 | def test_helper_in_b |
218 | assert_equal 'B', B.process(@request, @response).body |
219 | end |
220 | |
221 | def test_helper_in_c |
222 | assert_equal 'C', C.process(@request, @response).body |
223 | end |
224 | end |