actionpack 2.1.2 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +223 -7
- data/README +6 -12
- data/Rakefile +11 -11
- data/lib/action_controller.rb +9 -9
- data/lib/action_controller/assertions/response_assertions.rb +29 -78
- data/lib/action_controller/assertions/routing_assertions.rb +33 -33
- data/lib/action_controller/assertions/selector_assertions.rb +9 -5
- data/lib/action_controller/base.rb +227 -161
- data/lib/action_controller/benchmarking.rb +37 -24
- data/lib/action_controller/caching/actions.rb +53 -21
- data/lib/action_controller/caching/fragments.rb +10 -36
- data/lib/action_controller/caching/sweeping.rb +3 -3
- data/lib/action_controller/cgi_ext/session.rb +2 -22
- data/lib/action_controller/cgi_process.rb +8 -46
- data/lib/action_controller/components.rb +4 -1
- data/lib/action_controller/cookies.rb +10 -0
- data/lib/action_controller/dispatcher.rb +49 -15
- data/lib/action_controller/filters.rb +48 -10
- data/lib/action_controller/headers.rb +16 -14
- data/lib/action_controller/helpers.rb +2 -2
- data/lib/action_controller/http_authentication.rb +1 -1
- data/lib/action_controller/integration.rb +57 -60
- data/lib/action_controller/layout.rb +27 -53
- data/lib/action_controller/mime_responds.rb +5 -1
- data/lib/action_controller/mime_type.rb +64 -42
- data/lib/action_controller/mime_types.rb +2 -1
- data/lib/action_controller/performance_test.rb +16 -0
- data/lib/action_controller/polymorphic_routes.rb +16 -9
- data/lib/action_controller/rack_process.rb +303 -0
- data/lib/action_controller/request.rb +205 -97
- data/lib/action_controller/request_forgery_protection.rb +2 -2
- data/lib/action_controller/request_profiler.rb +0 -0
- data/lib/action_controller/rescue.rb +20 -115
- data/lib/action_controller/resources.rb +186 -83
- data/lib/action_controller/response.rb +140 -26
- data/lib/action_controller/routing.rb +28 -30
- data/lib/action_controller/routing/builder.rb +45 -54
- data/lib/action_controller/routing/optimisations.rb +31 -21
- data/lib/action_controller/routing/recognition_optimisation.rb +33 -27
- data/lib/action_controller/routing/route.rb +162 -147
- data/lib/action_controller/routing/route_set.rb +8 -7
- data/lib/action_controller/routing/routing_ext.rb +4 -1
- data/lib/action_controller/routing/segments.rb +50 -21
- data/lib/action_controller/session/cookie_store.rb +3 -2
- data/lib/action_controller/session/drb_server.rb +7 -7
- data/lib/action_controller/session_management.rb +6 -2
- data/lib/action_controller/streaming.rb +15 -8
- data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
- data/lib/action_controller/templates/rescues/template_error.erb +2 -2
- data/lib/action_controller/test_case.rb +66 -2
- data/lib/action_controller/test_process.rb +71 -66
- data/lib/action_controller/translation.rb +13 -0
- data/lib/action_controller/url_rewriter.rb +90 -13
- data/lib/action_controller/vendor/html-scanner/html/node.rb +9 -2
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +1 -1
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +2 -2
- data/lib/action_controller/verification.rb +2 -2
- data/lib/action_pack/version.rb +1 -1
- data/lib/action_view.rb +19 -11
- data/lib/action_view/base.rb +184 -150
- data/lib/action_view/helpers.rb +38 -0
- data/lib/action_view/helpers/active_record_helper.rb +56 -27
- data/lib/action_view/helpers/asset_tag_helper.rb +356 -153
- data/lib/action_view/helpers/atom_feed_helper.rb +74 -19
- data/lib/action_view/helpers/benchmark_helper.rb +3 -3
- data/lib/action_view/helpers/cache_helper.rb +1 -2
- data/lib/action_view/helpers/capture_helper.rb +19 -44
- data/lib/action_view/helpers/date_helper.rb +486 -296
- data/lib/action_view/helpers/debug_helper.rb +20 -13
- data/lib/action_view/helpers/form_helper.rb +71 -30
- data/lib/action_view/helpers/form_options_helper.rb +15 -85
- data/lib/action_view/helpers/form_tag_helper.rb +61 -38
- data/lib/action_view/helpers/javascript_helper.rb +80 -89
- data/lib/action_view/helpers/number_helper.rb +179 -74
- data/lib/action_view/helpers/prototype_helper.rb +216 -201
- data/lib/action_view/helpers/record_tag_helper.rb +4 -5
- data/lib/action_view/helpers/sanitize_helper.rb +65 -33
- data/lib/action_view/helpers/scriptaculous_helper.rb +2 -2
- data/lib/action_view/helpers/tag_helper.rb +39 -22
- data/lib/action_view/helpers/text_helper.rb +212 -118
- data/lib/action_view/helpers/translation_helper.rb +21 -0
- data/lib/action_view/helpers/url_helper.rb +100 -58
- data/lib/action_view/inline_template.rb +13 -14
- data/lib/action_view/locale/en.yml +91 -0
- data/lib/action_view/partials.rb +100 -55
- data/lib/action_view/paths.rb +125 -0
- data/lib/action_view/renderable.rb +102 -0
- data/lib/action_view/renderable_partial.rb +48 -0
- data/lib/action_view/template.rb +90 -101
- data/lib/action_view/template_error.rb +11 -21
- data/lib/action_view/template_handler.rb +8 -28
- data/lib/action_view/template_handlers.rb +45 -0
- data/lib/action_view/template_handlers/builder.rb +5 -15
- data/lib/action_view/template_handlers/erb.rb +9 -6
- data/lib/action_view/template_handlers/rjs.rb +2 -17
- data/lib/action_view/test_case.rb +7 -4
- data/test/abstract_unit.rb +4 -1
- data/test/active_record_unit.rb +28 -30
- data/test/activerecord/render_partial_with_record_identification_test.rb +25 -12
- data/test/controller/action_pack_assertions_test.rb +8 -37
- data/test/controller/addresses_render_test.rb +0 -3
- data/test/controller/assert_select_test.rb +51 -24
- data/test/controller/base_test.rb +4 -4
- data/test/controller/caching_test.rb +136 -66
- data/test/controller/capture_test.rb +1 -21
- data/test/controller/cgi_test.rb +157 -10
- data/test/controller/components_test.rb +41 -25
- data/test/controller/content_type_test.rb +49 -17
- data/test/controller/cookie_test.rb +1 -1
- data/test/controller/deprecation/deprecated_base_methods_test.rb +0 -3
- data/test/controller/dispatcher_test.rb +9 -1
- data/test/controller/filter_params_test.rb +2 -2
- data/test/controller/filters_test.rb +13 -13
- data/test/controller/html-scanner/cdata_node_test.rb +15 -0
- data/test/controller/html-scanner/node_test.rb +21 -0
- data/test/controller/html-scanner/sanitizer_test.rb +14 -0
- data/test/controller/integration_test.rb +167 -6
- data/test/controller/layout_test.rb +11 -68
- data/test/controller/logging_test.rb +46 -0
- data/test/controller/mime_responds_test.rb +61 -59
- data/test/controller/mime_type_test.rb +6 -6
- data/test/controller/polymorphic_routes_test.rb +37 -2
- data/test/controller/rack_test.rb +323 -0
- data/test/controller/redirect_test.rb +72 -71
- data/test/controller/render_test.rb +1120 -108
- data/test/controller/request_forgery_protection_test.rb +66 -52
- data/test/controller/request_test.rb +103 -146
- data/test/controller/rescue_test.rb +20 -24
- data/test/controller/resources_test.rb +408 -25
- data/test/controller/routing_test.rb +1774 -1774
- data/test/controller/send_file_test.rb +0 -4
- data/test/controller/session/cookie_store_test.rb +53 -1
- data/test/controller/test_test.rb +15 -37
- data/test/controller/translation_test.rb +26 -0
- data/test/controller/url_rewriter_test.rb +27 -28
- data/test/controller/view_paths_test.rb +48 -47
- data/test/fixtures/_top_level_partial.html.erb +1 -0
- data/test/fixtures/_top_level_partial_only.erb +1 -0
- data/test/fixtures/developers/_developer.erb +1 -0
- data/test/fixtures/fun/games/_game.erb +1 -0
- data/test/fixtures/fun/serious/games/_game.erb +1 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.html.erb +3 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +6 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder +5 -0
- data/test/fixtures/functional_caching/inline_fragment_cached.html.erb +2 -0
- data/test/fixtures/layouts/_column.html.erb +2 -0
- data/test/fixtures/projects/_project.erb +1 -0
- data/test/fixtures/public/javascripts/subdir/subdir.js +1 -0
- data/test/fixtures/public/stylesheets/subdir/subdir.css +1 -0
- data/test/fixtures/replies/_reply.erb +1 -0
- data/test/fixtures/test/_counter.html.erb +1 -0
- data/test/fixtures/test/_customer.erb +1 -1
- data/test/fixtures/test/_customer_with_var.erb +1 -0
- data/test/fixtures/test/_layout_for_block_with_args.html.erb +3 -0
- data/test/fixtures/test/_local_inspector.html.erb +1 -0
- data/test/fixtures/test/_partial_with_only_html_version.html.erb +1 -0
- data/test/fixtures/test/hello.builder +1 -1
- data/test/fixtures/test/hyphen-ated.erb +1 -0
- data/test/fixtures/test/implicit_content_type.atom.builder +2 -0
- data/test/fixtures/test/nested_layout.erb +3 -0
- data/test/fixtures/test/non_erb_block_content_for.builder +1 -1
- data/test/fixtures/test/sub_template_raise.html.erb +1 -0
- data/test/fixtures/test/template.erb +1 -0
- data/test/fixtures/test/using_layout_around_block_with_args.html.erb +1 -0
- data/test/template/active_record_helper_i18n_test.rb +46 -0
- data/test/template/active_record_helper_test.rb +24 -24
- data/test/template/asset_tag_helper_test.rb +161 -29
- data/test/template/atom_feed_helper_test.rb +114 -5
- data/test/template/compiled_templates_test.rb +59 -0
- data/test/template/date_helper_i18n_test.rb +113 -0
- data/test/template/date_helper_test.rb +403 -109
- data/test/template/form_helper_test.rb +213 -154
- data/test/template/form_options_helper_test.rb +249 -897
- data/test/template/form_tag_helper_test.rb +80 -32
- data/test/template/javascript_helper_test.rb +17 -18
- data/test/template/number_helper_i18n_test.rb +54 -0
- data/test/template/number_helper_test.rb +43 -13
- data/test/template/prototype_helper_test.rb +101 -84
- data/test/template/record_tag_helper_test.rb +24 -20
- data/test/template/render_test.rb +193 -0
- data/test/template/sanitize_helper_test.rb +3 -3
- data/test/template/tag_helper_test.rb +34 -14
- data/test/template/text_helper_test.rb +83 -9
- data/test/template/translation_helper_test.rb +28 -0
- data/test/template/url_helper_test.rb +55 -18
- metadata +57 -18
- data/lib/action_view/helpers/javascripts/controls.js +0 -963
- data/lib/action_view/helpers/javascripts/dragdrop.js +0 -972
- data/lib/action_view/helpers/javascripts/effects.js +0 -1120
- data/lib/action_view/helpers/javascripts/prototype.js +0 -4225
- data/lib/action_view/partial_template.rb +0 -70
- data/lib/action_view/template_finder.rb +0 -177
- data/lib/action_view/template_handlers/compilable.rb +0 -128
- data/test/controller/custom_handler_test.rb +0 -45
- data/test/controller/new_render_test.rb +0 -945
- data/test/fixtures/test/block_content_for.erb +0 -2
- data/test/fixtures/test/erb_content_for.erb +0 -2
- data/test/template/deprecated_erb_variable_test.rb +0 -9
- data/test/template/template_finder_test.rb +0 -73
- data/test/template/template_object_test.rb +0 -95
@@ -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
|
@@ -107,7 +107,7 @@ class RespondToController < ActionController::Base
|
|
107
107
|
type.any(:js, :xml) { render :text => "Either JS or XML" }
|
108
108
|
end
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
def handle_any_any
|
112
112
|
respond_to do |type|
|
113
113
|
type.html { render :text => 'HTML' }
|
@@ -120,12 +120,12 @@ class RespondToController < ActionController::Base
|
|
120
120
|
type.html
|
121
121
|
type.js
|
122
122
|
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def iphone_with_html_response_type
|
123
|
+
end
|
124
|
+
|
125
|
+
def iphone_with_html_response_type
|
126
126
|
Mime::Type.register_alias("text/html", :iphone)
|
127
127
|
request.format = :iphone if request.env["HTTP_ACCEPT"] == "text/iphone"
|
128
|
-
|
128
|
+
|
129
129
|
respond_to do |type|
|
130
130
|
type.html { @type = "Firefox" }
|
131
131
|
type.iphone { @type = "iPhone" }
|
@@ -138,7 +138,7 @@ class RespondToController < ActionController::Base
|
|
138
138
|
def iphone_with_html_response_type_without_layout
|
139
139
|
Mime::Type.register_alias("text/html", :iphone)
|
140
140
|
request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone"
|
141
|
-
|
141
|
+
|
142
142
|
respond_to do |type|
|
143
143
|
type.html { @type = "Firefox"; render :action => "iphone_with_html_response_type" }
|
144
144
|
type.iphone { @type = "iPhone" ; render :action => "iphone_with_html_response_type" }
|
@@ -162,10 +162,9 @@ class RespondToController < ActionController::Base
|
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
|
-
RespondToController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
|
166
|
-
|
167
165
|
class MimeControllerTest < Test::Unit::TestCase
|
168
166
|
def setup
|
167
|
+
ActionController::Base.use_accept_header = true
|
169
168
|
@request = ActionController::TestRequest.new
|
170
169
|
@response = ActionController::TestResponse.new
|
171
170
|
|
@@ -173,8 +172,12 @@ class MimeControllerTest < Test::Unit::TestCase
|
|
173
172
|
@request.host = "www.example.com"
|
174
173
|
end
|
175
174
|
|
175
|
+
def teardown
|
176
|
+
ActionController::Base.use_accept_header = false
|
177
|
+
end
|
178
|
+
|
176
179
|
def test_html
|
177
|
-
@request.
|
180
|
+
@request.accept = "text/html"
|
178
181
|
get :js_or_html
|
179
182
|
assert_equal 'HTML', @response.body
|
180
183
|
|
@@ -186,7 +189,7 @@ class MimeControllerTest < Test::Unit::TestCase
|
|
186
189
|
end
|
187
190
|
|
188
191
|
def test_all
|
189
|
-
@request.
|
192
|
+
@request.accept = "*/*"
|
190
193
|
get :js_or_html
|
191
194
|
assert_equal 'HTML', @response.body # js is not part of all
|
192
195
|
|
@@ -198,13 +201,13 @@ class MimeControllerTest < Test::Unit::TestCase
|
|
198
201
|
end
|
199
202
|
|
200
203
|
def test_xml
|
201
|
-
@request.
|
204
|
+
@request.accept = "application/xml"
|
202
205
|
get :html_xml_or_rss
|
203
206
|
assert_equal 'XML', @response.body
|
204
207
|
end
|
205
208
|
|
206
209
|
def test_js_or_html
|
207
|
-
@request.
|
210
|
+
@request.accept = "text/javascript, text/html"
|
208
211
|
get :js_or_html
|
209
212
|
assert_equal 'JS', @response.body
|
210
213
|
|
@@ -229,7 +232,7 @@ class MimeControllerTest < Test::Unit::TestCase
|
|
229
232
|
'JSON' => %w(application/json text/x-json)
|
230
233
|
}.each do |body, content_types|
|
231
234
|
content_types.each do |content_type|
|
232
|
-
@request.
|
235
|
+
@request.accept = content_type
|
233
236
|
get :json_or_yaml
|
234
237
|
assert_equal body, @response.body
|
235
238
|
end
|
@@ -237,7 +240,7 @@ class MimeControllerTest < Test::Unit::TestCase
|
|
237
240
|
end
|
238
241
|
|
239
242
|
def test_js_or_anything
|
240
|
-
@request.
|
243
|
+
@request.accept = "text/javascript, */*"
|
241
244
|
get :js_or_html
|
242
245
|
assert_equal 'JS', @response.body
|
243
246
|
|
@@ -247,36 +250,36 @@ class MimeControllerTest < Test::Unit::TestCase
|
|
247
250
|
get :just_xml
|
248
251
|
assert_equal 'XML', @response.body
|
249
252
|
end
|
250
|
-
|
253
|
+
|
251
254
|
def test_using_defaults
|
252
|
-
@request.
|
255
|
+
@request.accept = "*/*"
|
253
256
|
get :using_defaults
|
254
257
|
assert_equal "text/html", @response.content_type
|
255
258
|
assert_equal 'Hello world!', @response.body
|
256
259
|
|
257
|
-
@request.
|
260
|
+
@request.accept = "text/javascript"
|
258
261
|
get :using_defaults
|
259
262
|
assert_equal "text/javascript", @response.content_type
|
260
263
|
assert_equal '$("body").visualEffect("highlight");', @response.body
|
261
264
|
|
262
|
-
@request.
|
265
|
+
@request.accept = "application/xml"
|
263
266
|
get :using_defaults
|
264
267
|
assert_equal "application/xml", @response.content_type
|
265
268
|
assert_equal "<p>Hello world!</p>\n", @response.body
|
266
269
|
end
|
267
270
|
|
268
271
|
def test_using_defaults_with_type_list
|
269
|
-
@request.
|
272
|
+
@request.accept = "*/*"
|
270
273
|
get :using_defaults_with_type_list
|
271
274
|
assert_equal "text/html", @response.content_type
|
272
275
|
assert_equal 'Hello world!', @response.body
|
273
276
|
|
274
|
-
@request.
|
277
|
+
@request.accept = "text/javascript"
|
275
278
|
get :using_defaults_with_type_list
|
276
279
|
assert_equal "text/javascript", @response.content_type
|
277
280
|
assert_equal '$("body").visualEffect("highlight");', @response.body
|
278
281
|
|
279
|
-
@request.
|
282
|
+
@request.accept = "application/xml"
|
280
283
|
get :using_defaults_with_type_list
|
281
284
|
assert_equal "application/xml", @response.content_type
|
282
285
|
assert_equal "<p>Hello world!</p>\n", @response.body
|
@@ -295,90 +298,90 @@ class MimeControllerTest < Test::Unit::TestCase
|
|
295
298
|
end
|
296
299
|
|
297
300
|
def test_synonyms
|
298
|
-
@request.
|
301
|
+
@request.accept = "application/javascript"
|
299
302
|
get :js_or_html
|
300
303
|
assert_equal 'JS', @response.body
|
301
304
|
|
302
|
-
@request.
|
305
|
+
@request.accept = "application/x-xml"
|
303
306
|
get :html_xml_or_rss
|
304
307
|
assert_equal "XML", @response.body
|
305
308
|
end
|
306
309
|
|
307
310
|
def test_custom_types
|
308
|
-
@request.
|
311
|
+
@request.accept = "application/crazy-xml"
|
309
312
|
get :custom_type_handling
|
310
313
|
assert_equal "application/crazy-xml", @response.content_type
|
311
314
|
assert_equal 'Crazy XML', @response.body
|
312
315
|
|
313
|
-
@request.
|
316
|
+
@request.accept = "text/html"
|
314
317
|
get :custom_type_handling
|
315
318
|
assert_equal "text/html", @response.content_type
|
316
319
|
assert_equal 'HTML', @response.body
|
317
320
|
end
|
318
321
|
|
319
322
|
def test_xhtml_alias
|
320
|
-
@request.
|
323
|
+
@request.accept = "application/xhtml+xml,application/xml"
|
321
324
|
get :html_or_xml
|
322
325
|
assert_equal 'HTML', @response.body
|
323
326
|
end
|
324
327
|
|
325
328
|
def test_firefox_simulation
|
326
|
-
@request.
|
329
|
+
@request.accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
|
327
330
|
get :html_or_xml
|
328
331
|
assert_equal 'HTML', @response.body
|
329
332
|
end
|
330
333
|
|
331
334
|
def test_handle_any
|
332
|
-
@request.
|
335
|
+
@request.accept = "*/*"
|
333
336
|
get :handle_any
|
334
337
|
assert_equal 'HTML', @response.body
|
335
338
|
|
336
|
-
@request.
|
339
|
+
@request.accept = "text/javascript"
|
337
340
|
get :handle_any
|
338
341
|
assert_equal 'Either JS or XML', @response.body
|
339
342
|
|
340
|
-
@request.
|
343
|
+
@request.accept = "text/xml"
|
341
344
|
get :handle_any
|
342
345
|
assert_equal 'Either JS or XML', @response.body
|
343
346
|
end
|
344
347
|
|
345
348
|
def test_handle_any_any
|
346
|
-
@request.
|
349
|
+
@request.accept = "*/*"
|
347
350
|
get :handle_any_any
|
348
351
|
assert_equal 'HTML', @response.body
|
349
352
|
end
|
350
|
-
|
353
|
+
|
351
354
|
def test_handle_any_any_parameter_format
|
352
355
|
get :handle_any_any, {:format=>'html'}
|
353
356
|
assert_equal 'HTML', @response.body
|
354
357
|
end
|
355
|
-
|
358
|
+
|
356
359
|
def test_handle_any_any_explicit_html
|
357
|
-
@request.
|
360
|
+
@request.accept = "text/html"
|
358
361
|
get :handle_any_any
|
359
362
|
assert_equal 'HTML', @response.body
|
360
363
|
end
|
361
364
|
|
362
365
|
def test_handle_any_any_javascript
|
363
|
-
@request.
|
366
|
+
@request.accept = "text/javascript"
|
364
367
|
get :handle_any_any
|
365
368
|
assert_equal 'Whatever you ask for, I got it', @response.body
|
366
369
|
end
|
367
|
-
|
370
|
+
|
368
371
|
def test_handle_any_any_xml
|
369
|
-
@request.
|
372
|
+
@request.accept = "text/xml"
|
370
373
|
get :handle_any_any
|
371
374
|
assert_equal 'Whatever you ask for, I got it', @response.body
|
372
375
|
end
|
373
376
|
|
374
377
|
def test_rjs_type_skips_layout
|
375
|
-
@request.
|
378
|
+
@request.accept = "text/javascript"
|
376
379
|
get :all_types_with_layout
|
377
380
|
assert_equal 'RJS for all_types_with_layout', @response.body
|
378
381
|
end
|
379
382
|
|
380
383
|
def test_html_type_with_layout
|
381
|
-
@request.
|
384
|
+
@request.accept = "text/html"
|
382
385
|
get :all_types_with_layout
|
383
386
|
assert_equal '<html><div id="html">HTML for all_types_with_layout</div></html>', @response.body
|
384
387
|
end
|
@@ -445,31 +448,31 @@ class MimeControllerTest < Test::Unit::TestCase
|
|
445
448
|
|
446
449
|
get :using_defaults, :format => "xml"
|
447
450
|
assert_equal "using_defaults - xml", @response.body
|
448
|
-
end
|
449
|
-
|
451
|
+
end
|
452
|
+
|
450
453
|
def test_format_with_custom_response_type
|
451
454
|
get :iphone_with_html_response_type
|
452
|
-
assert_equal '<html><div id="html">Hello future from Firefox!</div></html>', @response.body
|
453
|
-
|
455
|
+
assert_equal '<html><div id="html">Hello future from Firefox!</div></html>', @response.body
|
456
|
+
|
454
457
|
get :iphone_with_html_response_type, :format => "iphone"
|
455
458
|
assert_equal "text/html", @response.content_type
|
456
459
|
assert_equal '<html><div id="iphone">Hello iPhone future from iPhone!</div></html>', @response.body
|
457
|
-
end
|
458
|
-
|
460
|
+
end
|
461
|
+
|
459
462
|
def test_format_with_custom_response_type_and_request_headers
|
460
|
-
@request.
|
463
|
+
@request.accept = "text/iphone"
|
461
464
|
get :iphone_with_html_response_type
|
462
465
|
assert_equal '<html><div id="iphone">Hello iPhone future from iPhone!</div></html>', @response.body
|
463
466
|
assert_equal "text/html", @response.content_type
|
464
|
-
end
|
467
|
+
end
|
465
468
|
|
466
469
|
def test_format_with_custom_response_type_and_request_headers_with_only_one_layout_present
|
467
470
|
get :iphone_with_html_response_type_without_layout
|
468
|
-
assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body
|
471
|
+
assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body
|
469
472
|
|
470
|
-
@request.
|
473
|
+
@request.accept = "text/iphone"
|
471
474
|
assert_raises(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
|
472
|
-
end
|
475
|
+
end
|
473
476
|
end
|
474
477
|
|
475
478
|
class AbstractPostController < ActionController::Base
|
@@ -497,7 +500,7 @@ class PostController < AbstractPostController
|
|
497
500
|
end
|
498
501
|
end
|
499
502
|
|
500
|
-
class SuperPostController < PostController
|
503
|
+
class SuperPostController < PostController
|
501
504
|
def index
|
502
505
|
respond_to do |type|
|
503
506
|
type.html
|
@@ -514,25 +517,24 @@ class MimeControllerLayoutsTest < Test::Unit::TestCase
|
|
514
517
|
@controller = PostController.new
|
515
518
|
@request.host = "www.example.com"
|
516
519
|
end
|
517
|
-
|
520
|
+
|
518
521
|
def test_missing_layout_renders_properly
|
519
522
|
get :index
|
520
|
-
assert_equal '<html><div id="html">Hello Firefox</div></html>', @response.body
|
523
|
+
assert_equal '<html><div id="html">Hello Firefox</div></html>', @response.body
|
521
524
|
|
522
|
-
@request.
|
525
|
+
@request.accept = "text/iphone"
|
523
526
|
get :index
|
524
527
|
assert_equal 'Hello iPhone', @response.body
|
525
528
|
end
|
526
|
-
|
529
|
+
|
527
530
|
def test_format_with_inherited_layouts
|
528
531
|
@controller = SuperPostController.new
|
529
|
-
|
532
|
+
|
530
533
|
get :index
|
531
534
|
assert_equal 'Super Firefox', @response.body
|
532
|
-
|
533
|
-
@request.
|
535
|
+
|
536
|
+
@request.accept = "text/iphone"
|
534
537
|
get :index
|
535
538
|
assert_equal '<html><div id="super_iphone">Super iPhone</div></html>', @response.body
|
536
539
|
end
|
537
540
|
end
|
538
|
-
|
@@ -61,7 +61,9 @@ class MimeTypeTest < Test::Unit::TestCase
|
|
61
61
|
types.each do |type|
|
62
62
|
mime = Mime.const_get(type.to_s.upcase)
|
63
63
|
assert mime.send("#{type}?"), "#{mime.inspect} is not #{type}?"
|
64
|
-
|
64
|
+
invalid_types = types - [type]
|
65
|
+
invalid_types.delete(:html) if Mime::Type.html_types.include?(type)
|
66
|
+
invalid_types.each { |other_type| assert !mime.send("#{other_type}?"), "#{mime.inspect} is #{other_type}?" }
|
65
67
|
end
|
66
68
|
end
|
67
69
|
|
@@ -71,14 +73,12 @@ class MimeTypeTest < Test::Unit::TestCase
|
|
71
73
|
end
|
72
74
|
|
73
75
|
def test_verifiable_mime_types
|
74
|
-
unverified_types = Mime::Type.unverifiable_types
|
75
76
|
all_types = Mime::SET.to_a.map(&:to_sym)
|
76
77
|
all_types.uniq!
|
77
78
|
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
|
78
79
|
all_types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
|
79
|
-
|
80
|
-
|
81
|
-
assert
|
82
|
-
assert unverified.all? { |type| !Mime.const_get(type.to_s.upcase).verify_request? }, "Some Mime Types are verified: #{unverified.inspect}"
|
80
|
+
verified, unverified = all_types.partition { |type| Mime::Type.browser_generated_types.include? type }
|
81
|
+
assert verified.each { |type| assert Mime.const_get(type.to_s.upcase).verify_request?, "Verifiable Mime Type is not verified: #{type.inspect}" }
|
82
|
+
assert unverified.each { |type| assert !Mime.const_get(type.to_s.upcase).verify_request?, "Nonverifiable Mime Type is verified: #{type.inspect}" }
|
83
83
|
end
|
84
84
|
end
|
@@ -60,6 +60,18 @@ uses_mocha 'polymorphic URL helpers' do
|
|
60
60
|
edit_polymorphic_url(@article)
|
61
61
|
end
|
62
62
|
|
63
|
+
def test_url_helper_prefixed_with_edit_with_url_options
|
64
|
+
@article.save
|
65
|
+
expects(:edit_article_url).with(@article, :param1 => '10')
|
66
|
+
edit_polymorphic_url(@article, :param1 => '10')
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_url_helper_with_url_options
|
70
|
+
@article.save
|
71
|
+
expects(:article_url).with(@article, :param1 => '10')
|
72
|
+
polymorphic_url(@article, :param1 => '10')
|
73
|
+
end
|
74
|
+
|
63
75
|
def test_formatted_url_helper
|
64
76
|
expects(:formatted_article_url).with(@article, :pdf)
|
65
77
|
formatted_polymorphic_url([@article, :pdf])
|
@@ -67,10 +79,16 @@ uses_mocha 'polymorphic URL helpers' do
|
|
67
79
|
|
68
80
|
def test_format_option
|
69
81
|
@article.save
|
70
|
-
expects(:
|
82
|
+
expects(:formatted_article_url).with(@article, :pdf)
|
71
83
|
polymorphic_url(@article, :format => :pdf)
|
72
84
|
end
|
73
85
|
|
86
|
+
def test_format_option_with_url_options
|
87
|
+
@article.save
|
88
|
+
expects(:formatted_article_url).with(@article, :pdf, :param1 => '10')
|
89
|
+
polymorphic_url(@article, :format => :pdf, :param1 => '10')
|
90
|
+
end
|
91
|
+
|
74
92
|
def test_id_and_format_option
|
75
93
|
@article.save
|
76
94
|
expects(:article_url).with(:id => @article, :format => :pdf)
|
@@ -147,10 +165,27 @@ uses_mocha 'polymorphic URL helpers' do
|
|
147
165
|
def test_nesting_with_array_containing_singleton_resource_and_format_option
|
148
166
|
@tag = Tag.new
|
149
167
|
@tag.save
|
150
|
-
expects(:
|
168
|
+
expects(:formatted_article_response_tag_url).with(@article, @tag, :pdf)
|
151
169
|
polymorphic_url([@article, :response, @tag], :format => :pdf)
|
152
170
|
end
|
153
171
|
|
172
|
+
def test_nesting_with_array_containing_nil
|
173
|
+
expects(:article_response_url).with(@article)
|
174
|
+
polymorphic_url([@article, nil, :response])
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_with_array_containing_single_object
|
178
|
+
@article.save
|
179
|
+
expects(:article_url).with(@article)
|
180
|
+
polymorphic_url([nil, @article])
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_with_array_containing_single_name
|
184
|
+
@article.save
|
185
|
+
expects(:articles_url)
|
186
|
+
polymorphic_url([:articles])
|
187
|
+
end
|
188
|
+
|
154
189
|
# TODO: Needs to be updated to correctly know about whether the object is in a hash or not
|
155
190
|
def xtest_with_hash
|
156
191
|
expects(:article_url).with(@article)
|