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
data/test/controller/cgi_test.rb
CHANGED
@@ -3,17 +3,67 @@ require 'action_controller/cgi_process'
|
|
3
3
|
|
4
4
|
class BaseCgiTest < Test::Unit::TestCase
|
5
5
|
def setup
|
6
|
-
@request_hash = {
|
6
|
+
@request_hash = {
|
7
|
+
"HTTP_MAX_FORWARDS" => "10",
|
8
|
+
"SERVER_NAME" => "glu.ttono.us:8007",
|
9
|
+
"FCGI_ROLE" => "RESPONDER",
|
10
|
+
"AUTH_TYPE" => "Basic",
|
11
|
+
"HTTP_X_FORWARDED_HOST" => "glu.ttono.us",
|
12
|
+
"HTTP_ACCEPT_CHARSET" => "UTF-8",
|
13
|
+
"HTTP_ACCEPT_ENCODING" => "gzip, deflate",
|
14
|
+
"HTTP_CACHE_CONTROL" => "no-cache, max-age=0",
|
15
|
+
"HTTP_PRAGMA" => "no-cache",
|
16
|
+
"HTTP_USER_AGENT" => "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)",
|
17
|
+
"PATH_INFO" => "/homepage/",
|
18
|
+
"HTTP_ACCEPT_LANGUAGE" => "en",
|
19
|
+
"HTTP_NEGOTIATE" => "trans",
|
20
|
+
"HTTP_HOST" => "glu.ttono.us:8007",
|
21
|
+
"HTTP_REFERER" => "http://www.google.com/search?q=glu.ttono.us",
|
22
|
+
"HTTP_FROM" => "googlebot",
|
23
|
+
"SERVER_PROTOCOL" => "HTTP/1.1",
|
24
|
+
"REDIRECT_URI" => "/dispatch.fcgi",
|
25
|
+
"SCRIPT_NAME" => "/dispatch.fcgi",
|
26
|
+
"SERVER_ADDR" => "207.7.108.53",
|
27
|
+
"REMOTE_ADDR" => "207.7.108.53",
|
28
|
+
"REMOTE_HOST" => "google.com",
|
29
|
+
"REMOTE_IDENT" => "kevin",
|
30
|
+
"REMOTE_USER" => "kevin",
|
31
|
+
"SERVER_SOFTWARE" => "lighttpd/1.4.5",
|
32
|
+
"HTTP_COOKIE" => "_session_id=c84ace84796670c052c6ceb2451fb0f2; is_admin=yes",
|
33
|
+
"HTTP_X_FORWARDED_SERVER" => "glu.ttono.us",
|
34
|
+
"REQUEST_URI" => "/admin",
|
35
|
+
"DOCUMENT_ROOT" => "/home/kevinc/sites/typo/public",
|
36
|
+
"PATH_TRANSLATED" => "/home/kevinc/sites/typo/public/homepage/",
|
37
|
+
"SERVER_PORT" => "8007",
|
38
|
+
"QUERY_STRING" => "",
|
39
|
+
"REMOTE_PORT" => "63137",
|
40
|
+
"GATEWAY_INTERFACE" => "CGI/1.1",
|
41
|
+
"HTTP_X_FORWARDED_FOR" => "65.88.180.234",
|
42
|
+
"HTTP_ACCEPT" => "*/*",
|
43
|
+
"SCRIPT_FILENAME" => "/home/kevinc/sites/typo/public/dispatch.fcgi",
|
44
|
+
"REDIRECT_STATUS" => "200",
|
45
|
+
"REQUEST_METHOD" => "GET"
|
46
|
+
}
|
7
47
|
# some Nokia phone browsers omit the space after the semicolon separator.
|
8
48
|
# some developers have grown accustomed to using comma in cookie values.
|
9
49
|
@alt_cookie_fmt_request_hash = {"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"}
|
10
|
-
@
|
11
|
-
@
|
50
|
+
@cgi = CGI.new
|
51
|
+
class << @cgi; attr_accessor :env_table end
|
52
|
+
@cgi.env_table = @request_hash
|
53
|
+
@request = ActionController::CgiRequest.new(@cgi)
|
12
54
|
end
|
13
55
|
|
14
56
|
def default_test; end
|
15
|
-
end
|
16
57
|
|
58
|
+
private
|
59
|
+
|
60
|
+
def set_content_data(data)
|
61
|
+
@request.env['REQUEST_METHOD'] = 'POST'
|
62
|
+
@request.env['CONTENT_LENGTH'] = data.length
|
63
|
+
@request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
|
64
|
+
@request.env['RAW_POST_DATA'] = data
|
65
|
+
end
|
66
|
+
end
|
17
67
|
|
18
68
|
class CgiRequestTest < BaseCgiTest
|
19
69
|
def test_proxy_request
|
@@ -26,7 +76,7 @@ class CgiRequestTest < BaseCgiTest
|
|
26
76
|
assert_equal "rubyonrails.org:8080", @request.host_with_port
|
27
77
|
|
28
78
|
@request_hash['HTTP_X_FORWARDED_HOST'] = "www.firsthost.org, www.secondhost.org"
|
29
|
-
assert_equal "www.secondhost.org", @request.host
|
79
|
+
assert_equal "www.secondhost.org", @request.host(true)
|
30
80
|
end
|
31
81
|
|
32
82
|
def test_http_host_with_default_port_overrides_server_port
|
@@ -71,6 +121,37 @@ class CgiRequestTest < BaseCgiTest
|
|
71
121
|
assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host
|
72
122
|
end
|
73
123
|
|
124
|
+
def test_cgi_environment_variables
|
125
|
+
assert_equal "Basic", @request.auth_type
|
126
|
+
assert_equal 0, @request.content_length
|
127
|
+
assert_equal nil, @request.content_type
|
128
|
+
assert_equal "CGI/1.1", @request.gateway_interface
|
129
|
+
assert_equal "*/*", @request.accept
|
130
|
+
assert_equal "UTF-8", @request.accept_charset
|
131
|
+
assert_equal "gzip, deflate", @request.accept_encoding
|
132
|
+
assert_equal "en", @request.accept_language
|
133
|
+
assert_equal "no-cache, max-age=0", @request.cache_control
|
134
|
+
assert_equal "googlebot", @request.from
|
135
|
+
assert_equal "glu.ttono.us", @request.host
|
136
|
+
assert_equal "trans", @request.negotiate
|
137
|
+
assert_equal "no-cache", @request.pragma
|
138
|
+
assert_equal "http://www.google.com/search?q=glu.ttono.us", @request.referer
|
139
|
+
assert_equal "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)", @request.user_agent
|
140
|
+
assert_equal "/homepage/", @request.path_info
|
141
|
+
assert_equal "/home/kevinc/sites/typo/public/homepage/", @request.path_translated
|
142
|
+
assert_equal "", @request.query_string
|
143
|
+
assert_equal "207.7.108.53", @request.remote_addr
|
144
|
+
assert_equal "google.com", @request.remote_host
|
145
|
+
assert_equal "kevin", @request.remote_ident
|
146
|
+
assert_equal "kevin", @request.remote_user
|
147
|
+
assert_equal :get, @request.request_method
|
148
|
+
assert_equal "/dispatch.fcgi", @request.script_name
|
149
|
+
assert_equal "glu.ttono.us:8007", @request.server_name
|
150
|
+
assert_equal 8007, @request.server_port
|
151
|
+
assert_equal "HTTP/1.1", @request.server_protocol
|
152
|
+
assert_equal "lighttpd", @request.server_software
|
153
|
+
end
|
154
|
+
|
74
155
|
def test_cookie_syntax_resilience
|
75
156
|
cookies = CGI::Cookie::parse(@request_hash["HTTP_COOKIE"]);
|
76
157
|
assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], cookies["_session_id"], cookies.inspect
|
@@ -82,13 +163,10 @@ class CgiRequestTest < BaseCgiTest
|
|
82
163
|
end
|
83
164
|
end
|
84
165
|
|
85
|
-
|
86
166
|
class CgiRequestParamsParsingTest < BaseCgiTest
|
87
167
|
def test_doesnt_break_when_content_type_has_charset
|
88
|
-
|
89
|
-
|
90
|
-
@request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
|
91
|
-
@request.env['RAW_POST_DATA'] = data
|
168
|
+
set_content_data 'flamenco=love'
|
169
|
+
|
92
170
|
assert_equal({"flamenco"=> "love"}, @request.request_parameters)
|
93
171
|
end
|
94
172
|
|
@@ -98,6 +176,40 @@ class CgiRequestParamsParsingTest < BaseCgiTest
|
|
98
176
|
end
|
99
177
|
end
|
100
178
|
|
179
|
+
class CgiRequestContentTypeTest < BaseCgiTest
|
180
|
+
def test_html_content_type_verification
|
181
|
+
@request.env['CONTENT_TYPE'] = Mime::HTML.to_s
|
182
|
+
assert @request.content_type.verify_request?
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_xml_content_type_verification
|
186
|
+
@request.env['CONTENT_TYPE'] = Mime::XML.to_s
|
187
|
+
assert !@request.content_type.verify_request?
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
class CgiRequestMethodTest < BaseCgiTest
|
192
|
+
def test_get
|
193
|
+
assert_equal :get, @request.request_method
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_post
|
197
|
+
@request.env['REQUEST_METHOD'] = 'POST'
|
198
|
+
assert_equal :post, @request.request_method
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_put
|
202
|
+
set_content_data '_method=put'
|
203
|
+
|
204
|
+
assert_equal :put, @request.request_method
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_delete
|
208
|
+
set_content_data '_method=delete'
|
209
|
+
|
210
|
+
assert_equal :delete, @request.request_method
|
211
|
+
end
|
212
|
+
end
|
101
213
|
|
102
214
|
class CgiRequestNeedsRewoundTest < BaseCgiTest
|
103
215
|
def test_body_should_be_rewound
|
@@ -114,3 +226,38 @@ class CgiRequestNeedsRewoundTest < BaseCgiTest
|
|
114
226
|
assert_equal 0, request.body.pos
|
115
227
|
end
|
116
228
|
end
|
229
|
+
|
230
|
+
uses_mocha 'CGI Response' do
|
231
|
+
class CgiResponseTest < BaseCgiTest
|
232
|
+
def setup
|
233
|
+
super
|
234
|
+
@cgi.expects(:header).returns("HTTP/1.0 200 OK\nContent-Type: text/html\n")
|
235
|
+
@response = ActionController::CgiResponse.new(@cgi)
|
236
|
+
@output = StringIO.new('')
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_simple_output
|
240
|
+
@response.body = "Hello, World!"
|
241
|
+
|
242
|
+
@response.out(@output)
|
243
|
+
assert_equal "HTTP/1.0 200 OK\nContent-Type: text/html\nHello, World!", @output.string
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_head_request
|
247
|
+
@cgi.env_table['REQUEST_METHOD'] = 'HEAD'
|
248
|
+
@response.body = "Hello, World!"
|
249
|
+
|
250
|
+
@response.out(@output)
|
251
|
+
assert_equal "HTTP/1.0 200 OK\nContent-Type: text/html\n", @output.string
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_streaming_block
|
255
|
+
@response.body = Proc.new do |response, output|
|
256
|
+
5.times { |n| output.write(n) }
|
257
|
+
end
|
258
|
+
|
259
|
+
@response.out(@output)
|
260
|
+
assert_equal "HTTP/1.0 200 OK\nContent-Type: text/html\n01234", @output.string
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
@@ -77,49 +77,64 @@ class ComponentsTest < Test::Unit::TestCase
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def test_calling_from_controller
|
80
|
-
|
81
|
-
|
80
|
+
assert_deprecated do
|
81
|
+
get :calling_from_controller
|
82
|
+
assert_equal "Lady of the House, speaking", @response.body
|
83
|
+
end
|
82
84
|
end
|
83
85
|
|
84
86
|
def test_calling_from_controller_with_params
|
85
|
-
|
86
|
-
|
87
|
+
assert_deprecated do
|
88
|
+
get :calling_from_controller_with_params
|
89
|
+
assert_equal "David of the House, speaking", @response.body
|
90
|
+
end
|
87
91
|
end
|
88
92
|
|
89
93
|
def test_calling_from_controller_with_different_status_code
|
90
|
-
|
91
|
-
|
94
|
+
assert_deprecated do
|
95
|
+
get :calling_from_controller_with_different_status_code
|
96
|
+
assert_equal 500, @response.response_code
|
97
|
+
end
|
92
98
|
end
|
93
99
|
|
94
100
|
def test_calling_from_template
|
95
|
-
|
96
|
-
|
101
|
+
assert_deprecated do
|
102
|
+
get :calling_from_template
|
103
|
+
assert_equal "Ring, ring: Lady of the House, speaking", @response.body
|
104
|
+
end
|
97
105
|
end
|
98
106
|
|
99
107
|
def test_etag_is_set_for_parent_template_when_calling_from_template
|
100
|
-
|
101
|
-
|
102
|
-
|
108
|
+
assert_deprecated do
|
109
|
+
get :calling_from_template
|
110
|
+
expected_etag = etag_for("Ring, ring: Lady of the House, speaking")
|
111
|
+
assert_equal expected_etag, @response.headers['ETag']
|
112
|
+
end
|
103
113
|
end
|
104
114
|
|
105
115
|
def test_internal_calling
|
106
|
-
|
107
|
-
|
116
|
+
assert_deprecated do
|
117
|
+
get :internal_caller
|
118
|
+
assert_equal "Are you there? Yes, ma'am", @response.body
|
119
|
+
end
|
108
120
|
end
|
109
121
|
|
110
122
|
def test_flash
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
123
|
+
assert_deprecated do
|
124
|
+
get :set_flash
|
125
|
+
assert_equal 'My stoney baby', flash[:notice]
|
126
|
+
get :use_flash
|
127
|
+
assert_equal 'My stoney baby', @response.body
|
128
|
+
get :use_flash
|
129
|
+
assert_equal 'no flash', @response.body
|
130
|
+
end
|
117
131
|
end
|
118
132
|
|
119
133
|
def test_component_redirect_redirects
|
120
|
-
|
121
|
-
|
122
|
-
|
134
|
+
assert_deprecated do
|
135
|
+
get :calling_redirected
|
136
|
+
assert_redirected_to :controller=>"callee", :action => "being_called"
|
137
|
+
end
|
123
138
|
end
|
124
139
|
|
125
140
|
def test_component_multiple_redirect_redirects
|
@@ -128,9 +143,10 @@ class ComponentsTest < Test::Unit::TestCase
|
|
128
143
|
end
|
129
144
|
|
130
145
|
def test_component_as_string_redirect_renders_redirected_action
|
131
|
-
|
132
|
-
|
133
|
-
|
146
|
+
assert_deprecated do
|
147
|
+
get :calling_redirected_as_string
|
148
|
+
assert_equal "Lady of the House, speaking", @response.body
|
149
|
+
end
|
134
150
|
end
|
135
151
|
|
136
152
|
protected
|
@@ -13,12 +13,17 @@ class ContentTypeController < ActionController::Base
|
|
13
13
|
def render_content_type_from_render
|
14
14
|
render :text => "hello world!", :content_type => Mime::RSS
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def render_charset_from_body
|
18
18
|
response.charset = "utf-16"
|
19
19
|
render :text => "hello world!"
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
|
+
def render_nil_charset_from_body
|
23
|
+
response.charset = nil
|
24
|
+
render :text => "hello world!"
|
25
|
+
end
|
26
|
+
|
22
27
|
def render_default_for_rhtml
|
23
28
|
end
|
24
29
|
|
@@ -45,8 +50,6 @@ class ContentTypeController < ActionController::Base
|
|
45
50
|
def rescue_action(e) raise end
|
46
51
|
end
|
47
52
|
|
48
|
-
ContentTypeController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
|
49
|
-
|
50
53
|
class ContentTypeTest < Test::Unit::TestCase
|
51
54
|
def setup
|
52
55
|
@controller = ContentTypeController.new
|
@@ -68,7 +71,7 @@ class ContentTypeTest < Test::Unit::TestCase
|
|
68
71
|
def test_render_changed_charset_default
|
69
72
|
ContentTypeController.default_charset = "utf-16"
|
70
73
|
get :render_defaults
|
71
|
-
assert_equal "utf-16", @response.charset
|
74
|
+
assert_equal "utf-16", @response.charset
|
72
75
|
assert_equal Mime::HTML, @response.content_type
|
73
76
|
ContentTypeController.default_charset = "utf-8"
|
74
77
|
end
|
@@ -76,63 +79,92 @@ class ContentTypeTest < Test::Unit::TestCase
|
|
76
79
|
def test_content_type_from_body
|
77
80
|
get :render_content_type_from_body
|
78
81
|
assert_equal "application/rss+xml", @response.content_type
|
79
|
-
assert_equal "utf-8", @response.charset
|
82
|
+
assert_equal "utf-8", @response.charset
|
80
83
|
end
|
81
84
|
|
82
85
|
def test_content_type_from_render
|
83
86
|
get :render_content_type_from_render
|
84
87
|
assert_equal "application/rss+xml", @response.content_type
|
85
|
-
assert_equal "utf-8", @response.charset
|
88
|
+
assert_equal "utf-8", @response.charset
|
86
89
|
end
|
87
90
|
|
88
91
|
def test_charset_from_body
|
89
92
|
get :render_charset_from_body
|
93
|
+
assert_equal Mime::HTML, @response.content_type
|
90
94
|
assert_equal "utf-16", @response.charset
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_nil_charset_from_body
|
98
|
+
get :render_nil_charset_from_body
|
99
|
+
assert_equal Mime::HTML, @response.content_type
|
100
|
+
assert_equal "utf-8", @response.charset, @response.headers.inspect
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_nil_default_for_rhtml
|
104
|
+
ContentTypeController.default_charset = nil
|
105
|
+
get :render_default_for_rhtml
|
91
106
|
assert_equal Mime::HTML, @response.content_type
|
107
|
+
assert_nil @response.charset, @response.headers.inspect
|
108
|
+
ensure
|
109
|
+
ContentTypeController.default_charset = "utf-8"
|
92
110
|
end
|
93
111
|
|
94
112
|
def test_default_for_rhtml
|
95
113
|
get :render_default_for_rhtml
|
96
114
|
assert_equal Mime::HTML, @response.content_type
|
97
|
-
assert_equal "utf-8", @response.charset
|
115
|
+
assert_equal "utf-8", @response.charset
|
98
116
|
end
|
99
117
|
|
100
118
|
def test_default_for_rxml
|
101
119
|
get :render_default_for_rxml
|
102
120
|
assert_equal Mime::XML, @response.content_type
|
103
|
-
assert_equal "utf-8", @response.charset
|
121
|
+
assert_equal "utf-8", @response.charset
|
104
122
|
end
|
105
123
|
|
106
124
|
def test_default_for_rjs
|
107
125
|
xhr :post, :render_default_for_rjs
|
108
126
|
assert_equal Mime::JS, @response.content_type
|
109
|
-
assert_equal "utf-8", @response.charset
|
127
|
+
assert_equal "utf-8", @response.charset
|
110
128
|
end
|
111
129
|
|
112
130
|
def test_change_for_rxml
|
113
131
|
get :render_change_for_rxml
|
114
132
|
assert_equal Mime::HTML, @response.content_type
|
115
|
-
assert_equal "utf-8", @response.charset
|
133
|
+
assert_equal "utf-8", @response.charset
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
class AcceptBasedContentTypeTest < ActionController::TestCase
|
138
|
+
|
139
|
+
tests ContentTypeController
|
140
|
+
|
141
|
+
def setup
|
142
|
+
ActionController::Base.use_accept_header = true
|
143
|
+
end
|
144
|
+
|
145
|
+
def teardown
|
146
|
+
ActionController::Base.use_accept_header = false
|
116
147
|
end
|
117
|
-
|
148
|
+
|
149
|
+
|
118
150
|
def test_render_default_content_types_for_respond_to
|
119
|
-
@request.
|
151
|
+
@request.accept = Mime::HTML.to_s
|
120
152
|
get :render_default_content_types_for_respond_to
|
121
153
|
assert_equal Mime::HTML, @response.content_type
|
122
154
|
|
123
|
-
@request.
|
155
|
+
@request.accept = Mime::JS.to_s
|
124
156
|
get :render_default_content_types_for_respond_to
|
125
157
|
assert_equal Mime::JS, @response.content_type
|
126
158
|
end
|
127
159
|
|
128
160
|
def test_render_default_content_types_for_respond_to_with_template
|
129
|
-
@request.
|
161
|
+
@request.accept = Mime::XML.to_s
|
130
162
|
get :render_default_content_types_for_respond_to
|
131
163
|
assert_equal Mime::XML, @response.content_type
|
132
164
|
end
|
133
|
-
|
165
|
+
|
134
166
|
def test_render_default_content_types_for_respond_to_with_overwrite
|
135
|
-
@request.
|
167
|
+
@request.accept = Mime::RSS.to_s
|
136
168
|
get :render_default_content_types_for_respond_to
|
137
169
|
assert_equal Mime::XML, @response.content_type
|
138
170
|
end
|