ghazel-erubis_rails_helper 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +66 -0
- data/lib/erubis_rails_helper/erubis/generator.rb +100 -0
- data/lib/erubis_rails_helper/template_handlers/erubis.rb +260 -0
- data/lib/erubis_rails_helper.rb +20 -0
- data/test/abstract_unit.rb +51 -0
- data/test/controller/action_pack_assertions_test.rb +516 -0
- data/test/controller/addresses_render_test.rb +37 -0
- data/test/controller/assert_select_test.rb +734 -0
- data/test/controller/base_test.rb +217 -0
- data/test/controller/benchmark_test.rb +32 -0
- data/test/controller/caching_test.rb +690 -0
- data/test/controller/capture_test.rb +66 -0
- data/test/controller/content_type_test.rb +168 -0
- data/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
- data/test/controller/cookie_test.rb +111 -0
- data/test/controller/deprecation/deprecated_base_methods_test.rb +32 -0
- data/test/controller/dispatcher_test.rb +103 -0
- data/test/controller/fake_controllers.rb +33 -0
- data/test/controller/fake_models.rb +19 -0
- data/test/controller/filter_params_test.rb +49 -0
- data/test/controller/filters_test.rb +885 -0
- data/test/controller/flash_test.rb +142 -0
- data/test/controller/header_test.rb +14 -0
- data/test/controller/helper_test.rb +224 -0
- data/test/controller/html-scanner/cdata_node_test.rb +15 -0
- data/test/controller/html-scanner/document_test.rb +148 -0
- data/test/controller/html-scanner/node_test.rb +89 -0
- data/test/controller/html-scanner/sanitizer_test.rb +273 -0
- data/test/controller/html-scanner/tag_node_test.rb +238 -0
- data/test/controller/html-scanner/text_node_test.rb +50 -0
- data/test/controller/html-scanner/tokenizer_test.rb +131 -0
- data/test/controller/http_basic_authentication_test.rb +88 -0
- data/test/controller/http_digest_authentication_test.rb +178 -0
- data/test/controller/integration_test.rb +417 -0
- data/test/controller/layout_test.rb +204 -0
- data/test/controller/logging_test.rb +46 -0
- data/test/controller/middleware_stack_test.rb +90 -0
- data/test/controller/mime_responds_test.rb +536 -0
- data/test/controller/mime_type_test.rb +93 -0
- data/test/controller/polymorphic_routes_test.rb +293 -0
- data/test/controller/rack_test.rb +294 -0
- data/test/controller/record_identifier_test.rb +139 -0
- data/test/controller/redirect_test.rb +282 -0
- data/test/controller/render_test.rb +1752 -0
- data/test/controller/request/json_params_parsing_test.rb +45 -0
- data/test/controller/request/multipart_params_parsing_test.rb +223 -0
- data/test/controller/request/query_string_parsing_test.rb +120 -0
- data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
- data/test/controller/request/xml_params_parsing_test.rb +88 -0
- data/test/controller/request_forgery_protection_test.rb +246 -0
- data/test/controller/request_test.rb +407 -0
- data/test/controller/rescue_test.rb +536 -0
- data/test/controller/resources_test.rb +1341 -0
- data/test/controller/routing_test.rb +2557 -0
- data/test/controller/selector_test.rb +628 -0
- data/test/controller/send_file_test.rb +161 -0
- data/test/controller/session/cookie_store_test.rb +239 -0
- data/test/controller/session/mem_cache_store_test.rb +127 -0
- data/test/controller/session/test_session_test.rb +58 -0
- data/test/controller/test_test.rb +692 -0
- data/test/controller/translation_test.rb +26 -0
- data/test/controller/url_rewriter_test.rb +359 -0
- data/test/controller/verification_test.rb +270 -0
- data/test/controller/view_paths_test.rb +141 -0
- data/test/controller/webservice_test.rb +260 -0
- data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
- data/test/fixtures/company.rb +10 -0
- data/test/fixtures/developer.rb +9 -0
- data/test/fixtures/helpers/abc_helper.rb +5 -0
- data/test/fixtures/helpers/fun/games_helper.rb +3 -0
- data/test/fixtures/helpers/fun/pdf_helper.rb +3 -0
- data/test/fixtures/mascot.rb +3 -0
- data/test/fixtures/project.rb +3 -0
- data/test/fixtures/reply.rb +7 -0
- data/test/fixtures/topic.rb +3 -0
- data/test/template/asset_tag_helper_test.rb +713 -0
- data/test/template/atom_feed_helper_test.rb +286 -0
- data/test/template/benchmark_helper_test.rb +86 -0
- data/test/template/compiled_templates_test.rb +203 -0
- data/test/template/date_helper_i18n_test.rb +120 -0
- data/test/template/date_helper_test.rb +2469 -0
- data/test/template/erb_util_test.rb +24 -0
- data/test/template/form_helper_test.rb +1176 -0
- data/test/template/form_options_helper_test.rb +751 -0
- data/test/template/form_tag_helper_test.rb +327 -0
- data/test/template/javascript_helper_test.rb +106 -0
- data/test/template/number_helper_i18n_test.rb +69 -0
- data/test/template/number_helper_test.rb +128 -0
- data/test/template/prototype_helper_test.rb +639 -0
- data/test/template/record_tag_helper_test.rb +58 -0
- data/test/template/render_test.rb +291 -0
- data/test/template/sanitize_helper_test.rb +48 -0
- data/test/template/scriptaculous_helper_test.rb +90 -0
- data/test/template/tag_helper_test.rb +97 -0
- data/test/template/test_test.rb +54 -0
- data/test/template/text_helper_test.rb +520 -0
- data/test/template/translation_helper_test.rb +32 -0
- data/test/template/url_helper_test.rb +614 -0
- data/test/test_erubis_rails_helper.rb +4 -0
- data/test/testing_sandbox.rb +15 -0
- data/test/view/test_case_test.rb +8 -0
- metadata +174 -0
@@ -0,0 +1,417 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class SessionTest < Test::Unit::TestCase
|
4
|
+
StubApp = lambda { |env|
|
5
|
+
[200, {"Content-Type" => "text/html", "Content-Length" => "13"}, "Hello, World!"]
|
6
|
+
}
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@session = ActionController::Integration::Session.new(StubApp)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_https_bang_works_and_sets_truth_by_default
|
13
|
+
assert !@session.https?
|
14
|
+
@session.https!
|
15
|
+
assert @session.https?
|
16
|
+
@session.https! false
|
17
|
+
assert !@session.https?
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_host!
|
21
|
+
assert_not_equal "glu.ttono.us", @session.host
|
22
|
+
@session.host! "rubyonrails.com"
|
23
|
+
assert_equal "rubyonrails.com", @session.host
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_follow_redirect_raises_when_no_redirect
|
27
|
+
@session.stubs(:redirect?).returns(false)
|
28
|
+
assert_raise(RuntimeError) { @session.follow_redirect! }
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_request_via_redirect_uses_given_method
|
32
|
+
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"}
|
33
|
+
@session.expects(:put).with(path, args, headers)
|
34
|
+
@session.stubs(:redirect?).returns(false)
|
35
|
+
@session.request_via_redirect(:put, path, args, headers)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_request_via_redirect_follows_redirects
|
39
|
+
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"}
|
40
|
+
@session.stubs(:redirect?).returns(true, true, false)
|
41
|
+
@session.expects(:follow_redirect!).times(2)
|
42
|
+
@session.request_via_redirect(:get, path, args, headers)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_request_via_redirect_returns_status
|
46
|
+
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"}
|
47
|
+
@session.stubs(:redirect?).returns(false)
|
48
|
+
@session.stubs(:status).returns(200)
|
49
|
+
assert_equal 200, @session.request_via_redirect(:get, path, args, headers)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_get_via_redirect
|
53
|
+
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
|
54
|
+
@session.expects(:request_via_redirect).with(:get, path, args, headers)
|
55
|
+
@session.get_via_redirect(path, args, headers)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_post_via_redirect
|
59
|
+
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
|
60
|
+
@session.expects(:request_via_redirect).with(:post, path, args, headers)
|
61
|
+
@session.post_via_redirect(path, args, headers)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_put_via_redirect
|
65
|
+
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
|
66
|
+
@session.expects(:request_via_redirect).with(:put, path, args, headers)
|
67
|
+
@session.put_via_redirect(path, args, headers)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_delete_via_redirect
|
71
|
+
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
|
72
|
+
@session.expects(:request_via_redirect).with(:delete, path, args, headers)
|
73
|
+
@session.delete_via_redirect(path, args, headers)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_url_for_with_controller
|
77
|
+
options = {:action => 'show'}
|
78
|
+
mock_controller = mock()
|
79
|
+
mock_controller.expects(:url_for).with(options).returns('/show')
|
80
|
+
@session.stubs(:controller).returns(mock_controller)
|
81
|
+
assert_equal '/show', @session.url_for(options)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_url_for_without_controller
|
85
|
+
options = {:action => 'show'}
|
86
|
+
mock_rewriter = mock()
|
87
|
+
mock_rewriter.expects(:rewrite).with(options).returns('/show')
|
88
|
+
@session.stubs(:generic_url_rewriter).returns(mock_rewriter)
|
89
|
+
@session.stubs(:controller).returns(nil)
|
90
|
+
assert_equal '/show', @session.url_for(options)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_redirect_bool_with_status_in_300s
|
94
|
+
@session.stubs(:status).returns 301
|
95
|
+
assert @session.redirect?
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_redirect_bool_with_status_in_200s
|
99
|
+
@session.stubs(:status).returns 200
|
100
|
+
assert !@session.redirect?
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_get
|
104
|
+
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
105
|
+
@session.expects(:process).with(:get,path,params,headers)
|
106
|
+
@session.get(path,params,headers)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_post
|
110
|
+
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
111
|
+
@session.expects(:process).with(:post,path,params,headers)
|
112
|
+
@session.post(path,params,headers)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_put
|
116
|
+
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
117
|
+
@session.expects(:process).with(:put,path,params,headers)
|
118
|
+
@session.put(path,params,headers)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_delete
|
122
|
+
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
123
|
+
@session.expects(:process).with(:delete,path,params,headers)
|
124
|
+
@session.delete(path,params,headers)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_head
|
128
|
+
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
129
|
+
@session.expects(:process).with(:head,path,params,headers)
|
130
|
+
@session.head(path,params,headers)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_xml_http_request_get
|
134
|
+
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
135
|
+
headers_after_xhr = headers.merge(
|
136
|
+
"X-Requested-With" => "XMLHttpRequest",
|
137
|
+
"Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
|
138
|
+
)
|
139
|
+
@session.expects(:process).with(:get,path,params,headers_after_xhr)
|
140
|
+
@session.xml_http_request(:get,path,params,headers)
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_xml_http_request_post
|
144
|
+
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
145
|
+
headers_after_xhr = headers.merge(
|
146
|
+
"X-Requested-With" => "XMLHttpRequest",
|
147
|
+
"Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
|
148
|
+
)
|
149
|
+
@session.expects(:process).with(:post,path,params,headers_after_xhr)
|
150
|
+
@session.xml_http_request(:post,path,params,headers)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_xml_http_request_put
|
154
|
+
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
155
|
+
headers_after_xhr = headers.merge(
|
156
|
+
"X-Requested-With" => "XMLHttpRequest",
|
157
|
+
"Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
|
158
|
+
)
|
159
|
+
@session.expects(:process).with(:put,path,params,headers_after_xhr)
|
160
|
+
@session.xml_http_request(:put,path,params,headers)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_xml_http_request_delete
|
164
|
+
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
165
|
+
headers_after_xhr = headers.merge(
|
166
|
+
"X-Requested-With" => "XMLHttpRequest",
|
167
|
+
"Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
|
168
|
+
)
|
169
|
+
@session.expects(:process).with(:delete,path,params,headers_after_xhr)
|
170
|
+
@session.xml_http_request(:delete,path,params,headers)
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_xml_http_request_head
|
174
|
+
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
175
|
+
headers_after_xhr = headers.merge(
|
176
|
+
"X-Requested-With" => "XMLHttpRequest",
|
177
|
+
"Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
|
178
|
+
)
|
179
|
+
@session.expects(:process).with(:head,path,params,headers_after_xhr)
|
180
|
+
@session.xml_http_request(:head,path,params,headers)
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_xml_http_request_override_accept
|
184
|
+
path = "/index"; params = "blah"; headers = {:location => 'blah', "Accept" => "application/xml"}
|
185
|
+
headers_after_xhr = headers.merge(
|
186
|
+
"X-Requested-With" => "XMLHttpRequest"
|
187
|
+
)
|
188
|
+
@session.expects(:process).with(:post,path,params,headers_after_xhr)
|
189
|
+
@session.xml_http_request(:post,path,params,headers)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
class IntegrationTestTest < Test::Unit::TestCase
|
194
|
+
def setup
|
195
|
+
@test = ::ActionController::IntegrationTest.new(:default_test)
|
196
|
+
@test.class.stubs(:fixture_table_names).returns([])
|
197
|
+
@session = @test.open_session
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_opens_new_session
|
201
|
+
@test.class.expects(:fixture_table_names).times(2).returns(['foo'])
|
202
|
+
|
203
|
+
session1 = @test.open_session { |sess| }
|
204
|
+
session2 = @test.open_session # implicit session
|
205
|
+
|
206
|
+
assert_equal ::ActionController::Integration::Session, session1.class
|
207
|
+
assert_equal ::ActionController::Integration::Session, session2.class
|
208
|
+
assert_not_equal session1, session2
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
# Tests that integration tests don't call Controller test methods for processing.
|
213
|
+
# Integration tests have their own setup and teardown.
|
214
|
+
class IntegrationTestUsesCorrectClass < ActionController::IntegrationTest
|
215
|
+
def self.fixture_table_names
|
216
|
+
[]
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_integration_methods_called
|
220
|
+
reset!
|
221
|
+
@integration_session.stubs(:generic_url_rewriter)
|
222
|
+
@integration_session.stubs(:process)
|
223
|
+
|
224
|
+
%w( get post head put delete ).each do |verb|
|
225
|
+
assert_nothing_raised("'#{verb}' should use integration test methods") { __send__(verb, '/') }
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
class IntegrationProcessTest < ActionController::IntegrationTest
|
231
|
+
class IntegrationController < ActionController::Base
|
232
|
+
def get
|
233
|
+
respond_to do |format|
|
234
|
+
format.html { render :text => "OK", :status => 200 }
|
235
|
+
format.js { render :text => "JS OK", :status => 200 }
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def get_with_params
|
240
|
+
render :text => "foo: #{params[:foo]}", :status => 200
|
241
|
+
end
|
242
|
+
|
243
|
+
def post
|
244
|
+
render :text => "Created", :status => 201
|
245
|
+
end
|
246
|
+
|
247
|
+
def cookie_monster
|
248
|
+
cookies["cookie_1"] = nil
|
249
|
+
cookies["cookie_3"] = "chocolate"
|
250
|
+
render :text => "Gone", :status => 410
|
251
|
+
end
|
252
|
+
|
253
|
+
def redirect
|
254
|
+
redirect_to :action => "get"
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_get
|
259
|
+
with_test_route_set do
|
260
|
+
get '/get'
|
261
|
+
assert_equal 200, status
|
262
|
+
assert_equal "OK", status_message
|
263
|
+
assert_response 200
|
264
|
+
assert_response :success
|
265
|
+
assert_response :ok
|
266
|
+
assert_equal({}, cookies)
|
267
|
+
assert_equal "OK", body
|
268
|
+
assert_equal "OK", response.body
|
269
|
+
assert_kind_of HTML::Document, html_document
|
270
|
+
assert_equal 1, request_count
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_post
|
275
|
+
with_test_route_set do
|
276
|
+
post '/post'
|
277
|
+
assert_equal 201, status
|
278
|
+
assert_equal "Created", status_message
|
279
|
+
assert_response 201
|
280
|
+
assert_response :success
|
281
|
+
assert_response :created
|
282
|
+
assert_equal({}, cookies)
|
283
|
+
assert_equal "Created", body
|
284
|
+
assert_equal "Created", response.body
|
285
|
+
assert_kind_of HTML::Document, html_document
|
286
|
+
assert_equal 1, request_count
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_cookie_monster
|
291
|
+
with_test_route_set do
|
292
|
+
self.cookies['cookie_1'] = "sugar"
|
293
|
+
self.cookies['cookie_2'] = "oatmeal"
|
294
|
+
get '/cookie_monster'
|
295
|
+
assert_equal 410, status
|
296
|
+
assert_equal "Gone", status_message
|
297
|
+
assert_response 410
|
298
|
+
assert_response :gone
|
299
|
+
assert_equal "cookie_1=; path=/\ncookie_3=chocolate; path=/", headers["Set-Cookie"]
|
300
|
+
assert_equal({"cookie_1"=>"", "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate"}, cookies)
|
301
|
+
assert_equal "Gone", response.body
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_redirect
|
306
|
+
with_test_route_set do
|
307
|
+
get '/redirect'
|
308
|
+
assert_equal 302, status
|
309
|
+
assert_equal "Found", status_message
|
310
|
+
assert_response 302
|
311
|
+
assert_response :redirect
|
312
|
+
assert_response :found
|
313
|
+
assert_equal "<html><body>You are being <a href=\"http://www.example.com/get\">redirected</a>.</body></html>", response.body
|
314
|
+
assert_kind_of HTML::Document, html_document
|
315
|
+
assert_equal 1, request_count
|
316
|
+
|
317
|
+
follow_redirect!
|
318
|
+
assert_response :success
|
319
|
+
assert_equal "/get", path
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_xml_http_request_get
|
324
|
+
with_test_route_set do
|
325
|
+
xhr :get, '/get'
|
326
|
+
assert_equal 200, status
|
327
|
+
assert_equal "OK", status_message
|
328
|
+
assert_response 200
|
329
|
+
assert_response :success
|
330
|
+
assert_response :ok
|
331
|
+
assert_equal "JS OK", response.body
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
def test_get_with_query_string
|
336
|
+
with_test_route_set do
|
337
|
+
get '/get_with_params?foo=bar'
|
338
|
+
assert_equal '/get_with_params?foo=bar', request.env["REQUEST_URI"]
|
339
|
+
assert_equal '/get_with_params?foo=bar', request.request_uri
|
340
|
+
assert_equal "", request.env["QUERY_STRING"]
|
341
|
+
assert_equal 'foo=bar', request.query_string
|
342
|
+
assert_equal 'bar', request.parameters['foo']
|
343
|
+
|
344
|
+
assert_equal 200, status
|
345
|
+
assert_equal "foo: bar", response.body
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
def test_get_with_parameters
|
350
|
+
with_test_route_set do
|
351
|
+
get '/get_with_params', :foo => "bar"
|
352
|
+
assert_equal '/get_with_params', request.env["REQUEST_URI"]
|
353
|
+
assert_equal '/get_with_params', request.request_uri
|
354
|
+
assert_equal 'foo=bar', request.env["QUERY_STRING"]
|
355
|
+
assert_equal 'foo=bar', request.query_string
|
356
|
+
assert_equal 'bar', request.parameters['foo']
|
357
|
+
|
358
|
+
assert_equal 200, status
|
359
|
+
assert_equal "foo: bar", response.body
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
def test_head
|
364
|
+
with_test_route_set do
|
365
|
+
head '/get'
|
366
|
+
assert_equal 200, status
|
367
|
+
assert_equal "", body
|
368
|
+
|
369
|
+
head '/post'
|
370
|
+
assert_equal 201, status
|
371
|
+
assert_equal "", body
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
private
|
376
|
+
def with_test_route_set
|
377
|
+
with_routing do |set|
|
378
|
+
set.draw do |map|
|
379
|
+
map.with_options :controller => "IntegrationProcessTest::Integration" do |c|
|
380
|
+
c.connect "/:action"
|
381
|
+
end
|
382
|
+
end
|
383
|
+
yield
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
class MetalTest < ActionController::IntegrationTest
|
389
|
+
class Poller
|
390
|
+
def self.call(env)
|
391
|
+
if env["PATH_INFO"] =~ /^\/success/
|
392
|
+
[200, {"Content-Type" => "text/plain", "Content-Length" => "12"}, "Hello World!"]
|
393
|
+
else
|
394
|
+
[404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, '']
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
def setup
|
400
|
+
@integration_session = ActionController::Integration::Session.new(Poller)
|
401
|
+
end
|
402
|
+
|
403
|
+
def test_successful_get
|
404
|
+
get "/success"
|
405
|
+
assert_response 200
|
406
|
+
assert_response :success
|
407
|
+
assert_response :ok
|
408
|
+
assert_equal "Hello World!", response.body
|
409
|
+
end
|
410
|
+
|
411
|
+
def test_failed_get
|
412
|
+
get "/failure"
|
413
|
+
assert_response 404
|
414
|
+
assert_response :not_found
|
415
|
+
assert_equal '', response.body
|
416
|
+
end
|
417
|
+
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
# The view_paths array must be set on Base and not LayoutTest so that LayoutTest's inherited
|
4
|
+
# method has access to the view_paths array when looking for a layout to automatically assign.
|
5
|
+
old_load_paths = ActionController::Base.view_paths
|
6
|
+
|
7
|
+
ActionView::Template::register_template_handler :mab,
|
8
|
+
lambda { |template| template.source.inspect }
|
9
|
+
|
10
|
+
ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/layout_tests/' ]
|
11
|
+
|
12
|
+
class LayoutTest < ActionController::Base
|
13
|
+
def self.controller_path; 'views' end
|
14
|
+
self.view_paths = ActionController::Base.view_paths.dup
|
15
|
+
end
|
16
|
+
|
17
|
+
# Restore view_paths to previous value
|
18
|
+
ActionController::Base.view_paths = old_load_paths
|
19
|
+
|
20
|
+
class ProductController < LayoutTest
|
21
|
+
end
|
22
|
+
|
23
|
+
class ItemController < LayoutTest
|
24
|
+
end
|
25
|
+
|
26
|
+
class ThirdPartyTemplateLibraryController < LayoutTest
|
27
|
+
end
|
28
|
+
|
29
|
+
module ControllerNameSpace
|
30
|
+
end
|
31
|
+
|
32
|
+
class ControllerNameSpace::NestedController < LayoutTest
|
33
|
+
end
|
34
|
+
|
35
|
+
class MultipleExtensions < LayoutTest
|
36
|
+
end
|
37
|
+
|
38
|
+
class LayoutAutoDiscoveryTest < ActionController::TestCase
|
39
|
+
def setup
|
40
|
+
@request.host = "www.nextangle.com"
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_application_layout_is_default_when_no_controller_match
|
44
|
+
@controller = ProductController.new
|
45
|
+
get :hello
|
46
|
+
assert_equal 'layout_test.rhtml hello.rhtml', @response.body
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_controller_name_layout_name_match
|
50
|
+
@controller = ItemController.new
|
51
|
+
get :hello
|
52
|
+
assert_equal 'item.rhtml hello.rhtml', @response.body
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_third_party_template_library_auto_discovers_layout
|
56
|
+
@controller = ThirdPartyTemplateLibraryController.new
|
57
|
+
get :hello
|
58
|
+
assert_equal 'layouts/third_party_template_library.mab', @controller.active_layout.to_s
|
59
|
+
assert_equal 'layouts/third_party_template_library', @response.layout
|
60
|
+
assert_response :success
|
61
|
+
assert_equal 'Mab', @response.body
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_namespaced_controllers_auto_detect_layouts
|
65
|
+
@controller = ControllerNameSpace::NestedController.new
|
66
|
+
get :hello
|
67
|
+
assert_equal 'layouts/controller_name_space/nested', @controller.active_layout.to_s
|
68
|
+
assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_namespaced_controllers_auto_detect_layouts
|
72
|
+
@controller = MultipleExtensions.new
|
73
|
+
get :hello
|
74
|
+
assert_equal 'layouts/multiple_extensions.html.erb', @controller.active_layout.to_s
|
75
|
+
assert_equal 'multiple_extensions.html.erb hello.rhtml', @response.body.strip
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class DefaultLayoutController < LayoutTest
|
80
|
+
end
|
81
|
+
|
82
|
+
class AbsolutePathLayoutController < LayoutTest
|
83
|
+
layout File.expand_path(File.expand_path(__FILE__) + '/../../fixtures/layout_tests/layouts/layout_test.rhtml')
|
84
|
+
end
|
85
|
+
|
86
|
+
class HasOwnLayoutController < LayoutTest
|
87
|
+
layout 'item'
|
88
|
+
end
|
89
|
+
|
90
|
+
class PrependsViewPathController < LayoutTest
|
91
|
+
def hello
|
92
|
+
prepend_view_path File.dirname(__FILE__) + '/../fixtures/layout_tests/alt/'
|
93
|
+
render :layout => 'alt'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
class SetsLayoutInRenderController < LayoutTest
|
98
|
+
def hello
|
99
|
+
render :layout => 'third_party_template_library'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class RendersNoLayoutController < LayoutTest
|
104
|
+
def hello
|
105
|
+
render :layout => false
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class LayoutSetInResponseTest < ActionController::TestCase
|
110
|
+
def test_layout_set_when_using_default_layout
|
111
|
+
@controller = DefaultLayoutController.new
|
112
|
+
get :hello
|
113
|
+
assert_equal 'layouts/layout_test', @response.layout
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_layout_set_when_set_in_controller
|
117
|
+
@controller = HasOwnLayoutController.new
|
118
|
+
get :hello
|
119
|
+
assert_equal 'layouts/item', @response.layout
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_layout_set_when_using_render
|
123
|
+
@controller = SetsLayoutInRenderController.new
|
124
|
+
get :hello
|
125
|
+
assert_equal 'layouts/third_party_template_library', @response.layout
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_layout_is_not_set_when_none_rendered
|
129
|
+
@controller = RendersNoLayoutController.new
|
130
|
+
get :hello
|
131
|
+
assert_nil @response.layout
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_exempt_from_layout_honored_by_render_template
|
135
|
+
ActionController::Base.exempt_from_layout :rhtml
|
136
|
+
@controller = RenderWithTemplateOptionController.new
|
137
|
+
|
138
|
+
get :hello
|
139
|
+
assert_equal "alt/hello.rhtml", @response.body.strip
|
140
|
+
|
141
|
+
ensure
|
142
|
+
ActionController::Base.exempt_from_layout.delete(/\.rhtml$/)
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_layout_is_picked_from_the_controller_instances_view_path
|
146
|
+
@controller = PrependsViewPathController.new
|
147
|
+
get :hello
|
148
|
+
assert_equal 'layouts/alt', @response.layout
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_absolute_pathed_layout
|
152
|
+
@controller = AbsolutePathLayoutController.new
|
153
|
+
get :hello
|
154
|
+
assert_equal "layout_test.rhtml hello.rhtml", @response.body.strip
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
class RenderWithTemplateOptionController < LayoutTest
|
159
|
+
def hello
|
160
|
+
render :template => 'alt/hello'
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
class SetsNonExistentLayoutFile < LayoutTest
|
165
|
+
layout "nofile.rhtml"
|
166
|
+
end
|
167
|
+
|
168
|
+
class LayoutExceptionRaised < ActionController::TestCase
|
169
|
+
def test_exception_raised_when_layout_file_not_found
|
170
|
+
@controller = SetsNonExistentLayoutFile.new
|
171
|
+
get :hello
|
172
|
+
assert_kind_of ActionView::MissingTemplate, @response.template.instance_eval { @exception }
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
class LayoutStatusIsRendered < LayoutTest
|
177
|
+
def hello
|
178
|
+
render :status => 401
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
class LayoutStatusIsRenderedTest < ActionController::TestCase
|
183
|
+
def test_layout_status_is_rendered
|
184
|
+
@controller = LayoutStatusIsRendered.new
|
185
|
+
get :hello
|
186
|
+
assert_response 401
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
unless RUBY_PLATFORM =~ /(:?mswin|mingw|bccwin)/
|
191
|
+
class LayoutSymlinkedTest < LayoutTest
|
192
|
+
layout "symlinked/symlinked_layout"
|
193
|
+
end
|
194
|
+
|
195
|
+
class LayoutSymlinkedIsRenderedTest < ActionController::TestCase
|
196
|
+
def test_symlinked_layout_is_rendered
|
197
|
+
@controller = LayoutSymlinkedTest.new
|
198
|
+
get :hello
|
199
|
+
assert_response 200
|
200
|
+
assert_equal "layouts/symlinked/symlinked_layout", @response.layout
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class LoggingController < ActionController::Base
|
4
|
+
def show
|
5
|
+
render :nothing => true
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class LoggingTest < ActionController::TestCase
|
10
|
+
tests LoggingController
|
11
|
+
|
12
|
+
class MockLogger
|
13
|
+
attr_reader :logged
|
14
|
+
|
15
|
+
def method_missing(method, *args)
|
16
|
+
@logged ||= []
|
17
|
+
@logged << args.first
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
setup :set_logger
|
22
|
+
|
23
|
+
def test_logging_without_parameters
|
24
|
+
get :show
|
25
|
+
assert_equal 2, logs.size
|
26
|
+
assert_nil logs.detect {|l| l =~ /Parameters/ }
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_logging_with_parameters
|
30
|
+
get :show, :id => 10
|
31
|
+
assert_equal 3, logs.size
|
32
|
+
|
33
|
+
params = logs.detect {|l| l =~ /Parameters/ }
|
34
|
+
assert_equal 'Parameters: {"id"=>"10"}', params
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def set_logger
|
40
|
+
@controller.logger = MockLogger.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def logs
|
44
|
+
@logs ||= @controller.logger.logged.compact.map {|l| l.strip}
|
45
|
+
end
|
46
|
+
end
|