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,323 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'action_controller/rack_process'
|
3
|
+
|
4
|
+
class BaseRackTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@env = {
|
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
|
+
}
|
47
|
+
@request = ActionController::RackRequest.new(@env)
|
48
|
+
# some Nokia phone browsers omit the space after the semicolon separator.
|
49
|
+
# some developers have grown accustomed to using comma in cookie values.
|
50
|
+
@alt_cookie_fmt_request = ActionController::RackRequest.new(@env.merge({"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"}))
|
51
|
+
end
|
52
|
+
|
53
|
+
def default_test; end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def set_content_data(data)
|
58
|
+
@request.env['REQUEST_METHOD'] = 'POST'
|
59
|
+
@request.env['CONTENT_LENGTH'] = data.length
|
60
|
+
@request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
|
61
|
+
@request.env['RAW_POST_DATA'] = data
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class RackRequestTest < BaseRackTest
|
66
|
+
def test_proxy_request
|
67
|
+
assert_equal 'glu.ttono.us', @request.host_with_port(true)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_http_host
|
71
|
+
@env.delete "HTTP_X_FORWARDED_HOST"
|
72
|
+
@env['HTTP_HOST'] = "rubyonrails.org:8080"
|
73
|
+
assert_equal "rubyonrails.org", @request.host(true)
|
74
|
+
assert_equal "rubyonrails.org:8080", @request.host_with_port(true)
|
75
|
+
|
76
|
+
@env['HTTP_X_FORWARDED_HOST'] = "www.firsthost.org, www.secondhost.org"
|
77
|
+
assert_equal "www.secondhost.org", @request.host(true)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_http_host_with_default_port_overrides_server_port
|
81
|
+
@env.delete "HTTP_X_FORWARDED_HOST"
|
82
|
+
@env['HTTP_HOST'] = "rubyonrails.org"
|
83
|
+
assert_equal "rubyonrails.org", @request.host_with_port(true)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_host_with_port_defaults_to_server_name_if_no_host_headers
|
87
|
+
@env.delete "HTTP_X_FORWARDED_HOST"
|
88
|
+
@env.delete "HTTP_HOST"
|
89
|
+
assert_equal "glu.ttono.us:8007", @request.host_with_port(true)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_host_with_port_falls_back_to_server_addr_if_necessary
|
93
|
+
@env.delete "HTTP_X_FORWARDED_HOST"
|
94
|
+
@env.delete "HTTP_HOST"
|
95
|
+
@env.delete "SERVER_NAME"
|
96
|
+
assert_equal "207.7.108.53", @request.host(true)
|
97
|
+
assert_equal 8007, @request.port(true)
|
98
|
+
assert_equal "207.7.108.53:8007", @request.host_with_port(true)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_host_with_port_if_http_standard_port_is_specified
|
102
|
+
@env['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:80"
|
103
|
+
assert_equal "glu.ttono.us", @request.host_with_port(true)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_host_with_port_if_https_standard_port_is_specified
|
107
|
+
@env['HTTP_X_FORWARDED_PROTO'] = "https"
|
108
|
+
@env['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:443"
|
109
|
+
assert_equal "glu.ttono.us", @request.host_with_port(true)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_host_if_ipv6_reference
|
113
|
+
@env.delete "HTTP_X_FORWARDED_HOST"
|
114
|
+
@env['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]"
|
115
|
+
assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host(true)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_host_if_ipv6_reference_with_port
|
119
|
+
@env.delete "HTTP_X_FORWARDED_HOST"
|
120
|
+
@env['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]:8008"
|
121
|
+
assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host(true)
|
122
|
+
end
|
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
|
+
|
155
|
+
def test_cookie_syntax_resilience
|
156
|
+
cookies = @request.cookies
|
157
|
+
assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], cookies["_session_id"], cookies.inspect
|
158
|
+
assert_equal ["yes"], cookies["is_admin"], cookies.inspect
|
159
|
+
|
160
|
+
alt_cookies = @alt_cookie_fmt_request.cookies
|
161
|
+
assert_equal ["c84ace847,96670c052c6ceb2451fb0f2"], alt_cookies["_session_id"], alt_cookies.inspect
|
162
|
+
assert_equal ["yes"], alt_cookies["is_admin"], alt_cookies.inspect
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
class RackRequestParamsParsingTest < BaseRackTest
|
167
|
+
def test_doesnt_break_when_content_type_has_charset
|
168
|
+
set_content_data 'flamenco=love'
|
169
|
+
|
170
|
+
assert_equal({"flamenco"=> "love"}, @request.request_parameters)
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_doesnt_interpret_request_uri_as_query_string_when_missing
|
174
|
+
@request.env['REQUEST_URI'] = 'foo'
|
175
|
+
assert_equal({}, @request.query_parameters)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
class RackRequestContentTypeTest < BaseRackTest
|
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 RackRequestMethodTest < BaseRackTest
|
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
|
213
|
+
|
214
|
+
class RackRequestNeedsRewoundTest < BaseRackTest
|
215
|
+
def test_body_should_be_rewound
|
216
|
+
data = 'foo'
|
217
|
+
@env['rack.input'] = StringIO.new(data)
|
218
|
+
@env['CONTENT_LENGTH'] = data.length
|
219
|
+
@env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
|
220
|
+
|
221
|
+
# Read the request body by parsing params.
|
222
|
+
request = ActionController::RackRequest.new(@env)
|
223
|
+
request.request_parameters
|
224
|
+
|
225
|
+
# Should have rewound the body.
|
226
|
+
assert_equal 0, request.body.pos
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
class RackResponseTest < BaseRackTest
|
231
|
+
def setup
|
232
|
+
super
|
233
|
+
@response = ActionController::RackResponse.new(@request)
|
234
|
+
@output = StringIO.new('')
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_simple_output
|
238
|
+
@response.body = "Hello, World!"
|
239
|
+
@response.prepare!
|
240
|
+
|
241
|
+
status, headers, body = @response.out(@output)
|
242
|
+
assert_equal "200 OK", status
|
243
|
+
assert_equal({
|
244
|
+
"Content-Type" => "text/html; charset=utf-8",
|
245
|
+
"Cache-Control" => "private, max-age=0, must-revalidate",
|
246
|
+
"ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"',
|
247
|
+
"Set-Cookie" => [],
|
248
|
+
"Content-Length" => "13"
|
249
|
+
}, headers)
|
250
|
+
|
251
|
+
parts = []
|
252
|
+
body.each { |part| parts << part }
|
253
|
+
assert_equal ["Hello, World!"], parts
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_streaming_block
|
257
|
+
@response.body = Proc.new do |response, output|
|
258
|
+
5.times { |n| output.write(n) }
|
259
|
+
end
|
260
|
+
@response.prepare!
|
261
|
+
|
262
|
+
status, headers, body = @response.out(@output)
|
263
|
+
assert_equal "200 OK", status
|
264
|
+
assert_equal({"Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers)
|
265
|
+
|
266
|
+
parts = []
|
267
|
+
body.each { |part| parts << part }
|
268
|
+
assert_equal ["0", "1", "2", "3", "4"], parts
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_set_session_cookie
|
272
|
+
cookie = CGI::Cookie.new({"name" => "name", "value" => "Josh"})
|
273
|
+
@request.cgi.send :instance_variable_set, '@output_cookies', [cookie]
|
274
|
+
|
275
|
+
@response.body = "Hello, World!"
|
276
|
+
@response.prepare!
|
277
|
+
|
278
|
+
status, headers, body = @response.out(@output)
|
279
|
+
assert_equal "200 OK", status
|
280
|
+
assert_equal({
|
281
|
+
"Content-Type" => "text/html; charset=utf-8",
|
282
|
+
"Cache-Control" => "private, max-age=0, must-revalidate",
|
283
|
+
"ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"',
|
284
|
+
"Set-Cookie" => ["name=Josh; path="],
|
285
|
+
"Content-Length" => "13"
|
286
|
+
}, headers)
|
287
|
+
|
288
|
+
parts = []
|
289
|
+
body.each { |part| parts << part }
|
290
|
+
assert_equal ["Hello, World!"], parts
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
class RackResponseHeadersTest < BaseRackTest
|
295
|
+
def setup
|
296
|
+
super
|
297
|
+
@response = ActionController::RackResponse.new(@request)
|
298
|
+
@output = StringIO.new('')
|
299
|
+
@response.headers['Status'] = "200 OK"
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_content_type
|
303
|
+
[204, 304].each do |c|
|
304
|
+
@response.headers['Status'] = c.to_s
|
305
|
+
assert !response_headers.has_key?("Content-Type"), "#{c} should not have Content-Type header"
|
306
|
+
end
|
307
|
+
|
308
|
+
[200, 302, 404, 500].each do |c|
|
309
|
+
@response.headers['Status'] = c.to_s
|
310
|
+
assert response_headers.has_key?("Content-Type"), "#{c} did not have Content-Type header"
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
def test_status
|
315
|
+
assert !response_headers.has_key?('Status')
|
316
|
+
end
|
317
|
+
|
318
|
+
private
|
319
|
+
def response_headers
|
320
|
+
@response.prepare!
|
321
|
+
@response.out(@output)[1]
|
322
|
+
end
|
323
|
+
end
|
@@ -9,11 +9,11 @@ class Workshop
|
|
9
9
|
def initialize(id, new_record)
|
10
10
|
@id, @new_record = id, new_record
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def new_record?
|
14
14
|
@new_record
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def to_s
|
18
18
|
id.to_s
|
19
19
|
end
|
@@ -24,32 +24,32 @@ class RedirectController < ActionController::Base
|
|
24
24
|
redirect_to :action => "hello_world"
|
25
25
|
end
|
26
26
|
|
27
|
-
def redirect_with_status
|
27
|
+
def redirect_with_status
|
28
28
|
redirect_to({:action => "hello_world", :status => 301})
|
29
|
-
end
|
29
|
+
end
|
30
30
|
|
31
31
|
def redirect_with_status_hash
|
32
32
|
redirect_to({:action => "hello_world"}, {:status => 301})
|
33
|
-
end
|
33
|
+
end
|
34
34
|
|
35
|
-
def url_redirect_with_status
|
35
|
+
def url_redirect_with_status
|
36
36
|
redirect_to("http://www.example.com", :status => :moved_permanently)
|
37
|
-
end
|
38
|
-
|
39
|
-
def url_redirect_with_status_hash
|
37
|
+
end
|
38
|
+
|
39
|
+
def url_redirect_with_status_hash
|
40
40
|
redirect_to("http://www.example.com", {:status => 301})
|
41
|
-
end
|
41
|
+
end
|
42
42
|
|
43
|
-
def relative_url_redirect_with_status
|
43
|
+
def relative_url_redirect_with_status
|
44
44
|
redirect_to("/things/stuff", :status => :found)
|
45
|
-
end
|
46
|
-
|
45
|
+
end
|
46
|
+
|
47
47
|
def relative_url_redirect_with_status_hash
|
48
48
|
redirect_to("/things/stuff", {:status => 301})
|
49
|
-
end
|
50
|
-
|
51
|
-
def redirect_to_back_with_status
|
52
|
-
redirect_to :back, :status => 307
|
49
|
+
end
|
50
|
+
|
51
|
+
def redirect_to_back_with_status
|
52
|
+
redirect_to :back, :status => 307
|
53
53
|
end
|
54
54
|
|
55
55
|
def host_redirect
|
@@ -73,6 +73,10 @@ class RedirectController < ActionController::Base
|
|
73
73
|
redirect_to "http://dev.rubyonrails.org/query?status=new"
|
74
74
|
end
|
75
75
|
|
76
|
+
def redirect_to_url_with_complex_scheme
|
77
|
+
redirect_to "x-test+scheme.complex:redirect"
|
78
|
+
end
|
79
|
+
|
76
80
|
def redirect_to_back
|
77
81
|
redirect_to :back
|
78
82
|
end
|
@@ -90,9 +94,9 @@ class RedirectController < ActionController::Base
|
|
90
94
|
end
|
91
95
|
|
92
96
|
def rescue_errors(e) raise e end
|
93
|
-
|
97
|
+
|
94
98
|
def rescue_action(e) raise end
|
95
|
-
|
99
|
+
|
96
100
|
protected
|
97
101
|
def dashbord_url(id, message)
|
98
102
|
url_for :action => "dashboard", :params => { "id" => id, "message" => message }
|
@@ -118,69 +122,54 @@ class RedirectTest < Test::Unit::TestCase
|
|
118
122
|
assert_equal "http://test.host/redirect/hello_world", redirect_to_url
|
119
123
|
end
|
120
124
|
|
121
|
-
def test_redirect_with_status
|
122
|
-
get :redirect_with_status
|
123
|
-
assert_response 301
|
124
|
-
assert_equal "http://test.host/redirect/hello_world", redirect_to_url
|
125
|
-
end
|
125
|
+
def test_redirect_with_status
|
126
|
+
get :redirect_with_status
|
127
|
+
assert_response 301
|
128
|
+
assert_equal "http://test.host/redirect/hello_world", redirect_to_url
|
129
|
+
end
|
126
130
|
|
127
|
-
def test_redirect_with_status_hash
|
131
|
+
def test_redirect_with_status_hash
|
128
132
|
get :redirect_with_status_hash
|
129
|
-
assert_response 301
|
130
|
-
assert_equal "http://test.host/redirect/hello_world", redirect_to_url
|
133
|
+
assert_response 301
|
134
|
+
assert_equal "http://test.host/redirect/hello_world", redirect_to_url
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_url_redirect_with_status
|
138
|
+
get :url_redirect_with_status
|
139
|
+
assert_response 301
|
140
|
+
assert_equal "http://www.example.com", redirect_to_url
|
131
141
|
end
|
132
|
-
|
133
|
-
def test_url_redirect_with_status
|
134
|
-
get :url_redirect_with_status
|
135
|
-
assert_response 301
|
136
|
-
assert_equal "http://www.example.com", redirect_to_url
|
137
|
-
end
|
138
142
|
|
139
143
|
def test_url_redirect_with_status_hash
|
140
144
|
get :url_redirect_with_status_hash
|
141
|
-
assert_response 301
|
142
|
-
assert_equal "http://www.example.com", redirect_to_url
|
143
|
-
end
|
145
|
+
assert_response 301
|
146
|
+
assert_equal "http://www.example.com", redirect_to_url
|
147
|
+
end
|
148
|
+
|
144
149
|
|
145
|
-
|
146
|
-
|
147
|
-
get :relative_url_redirect_with_status
|
150
|
+
def test_relative_url_redirect_with_status
|
151
|
+
get :relative_url_redirect_with_status
|
148
152
|
assert_response 302
|
149
|
-
assert_equal "http://test.host/things/stuff", redirect_to_url
|
150
|
-
end
|
151
|
-
|
153
|
+
assert_equal "http://test.host/things/stuff", redirect_to_url
|
154
|
+
end
|
155
|
+
|
152
156
|
def test_relative_url_redirect_with_status_hash
|
153
157
|
get :relative_url_redirect_with_status_hash
|
154
|
-
assert_response 301
|
155
|
-
assert_equal "http://test.host/things/stuff", redirect_to_url
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_redirect_to_back_with_status
|
159
|
-
@request.env["HTTP_REFERER"] = "http://www.example.com/coming/from"
|
160
|
-
get :redirect_to_back_with_status
|
161
|
-
assert_response 307
|
162
|
-
assert_equal "http://www.example.com/coming/from", redirect_to_url
|
158
|
+
assert_response 301
|
159
|
+
assert_equal "http://test.host/things/stuff", redirect_to_url
|
163
160
|
end
|
164
161
|
|
165
|
-
def
|
166
|
-
|
167
|
-
|
168
|
-
|
162
|
+
def test_redirect_to_back_with_status
|
163
|
+
@request.env["HTTP_REFERER"] = "http://www.example.com/coming/from"
|
164
|
+
get :redirect_to_back_with_status
|
165
|
+
assert_response 307
|
166
|
+
assert_equal "http://www.example.com/coming/from", redirect_to_url
|
169
167
|
end
|
170
168
|
|
171
|
-
def
|
169
|
+
def test_simple_redirect_using_options
|
172
170
|
get :host_redirect
|
173
171
|
assert_response :redirect
|
174
|
-
|
175
|
-
assert_redirected_to :action => "other_host", :only_path => true
|
176
|
-
rescue Test::Unit::AssertionFailedError => err
|
177
|
-
expected_msg, redirection_msg, diff_msg = err.message.scan(/<\{[^\}]+\}>/).collect { |s| s[2..-3] }
|
178
|
-
assert_match %r("only_path"=>false), redirection_msg
|
179
|
-
assert_match %r("host"=>"other.test.host"), redirection_msg
|
180
|
-
assert_match %r("action"=>"other_host"), redirection_msg
|
181
|
-
assert_match %r("only_path"=>false), diff_msg
|
182
|
-
assert_match %r("host"=>"other.test.host"), diff_msg
|
183
|
-
end
|
172
|
+
assert_redirected_to :action => "other_host", :only_path => false, :host => 'other.test.host'
|
184
173
|
end
|
185
174
|
|
186
175
|
def test_module_redirect
|
@@ -213,31 +202,44 @@ class RedirectTest < Test::Unit::TestCase
|
|
213
202
|
assert_redirected_to "http://dev.rubyonrails.org/query?status=new"
|
214
203
|
end
|
215
204
|
|
205
|
+
def test_redirect_to_url_with_complex_scheme
|
206
|
+
get :redirect_to_url_with_complex_scheme
|
207
|
+
assert_response :redirect
|
208
|
+
assert_equal "x-test+scheme.complex:redirect", redirect_to_url
|
209
|
+
end
|
210
|
+
|
216
211
|
def test_redirect_to_back
|
217
212
|
@request.env["HTTP_REFERER"] = "http://www.example.com/coming/from"
|
218
213
|
get :redirect_to_back
|
219
214
|
assert_response :redirect
|
220
215
|
assert_equal "http://www.example.com/coming/from", redirect_to_url
|
221
216
|
end
|
222
|
-
|
217
|
+
|
223
218
|
def test_redirect_to_back_with_no_referer
|
224
219
|
assert_raises(ActionController::RedirectBackError) {
|
225
220
|
@request.env["HTTP_REFERER"] = nil
|
226
221
|
get :redirect_to_back
|
227
222
|
}
|
228
223
|
end
|
229
|
-
|
224
|
+
|
230
225
|
def test_redirect_to_record
|
231
226
|
ActionController::Routing::Routes.draw do |map|
|
232
227
|
map.resources :workshops
|
233
228
|
map.connect ':controller/:action/:id'
|
234
229
|
end
|
235
|
-
|
230
|
+
|
236
231
|
get :redirect_to_existing_record
|
237
232
|
assert_equal "http://test.host/workshops/5", redirect_to_url
|
233
|
+
assert_redirected_to Workshop.new(5, false)
|
238
234
|
|
239
235
|
get :redirect_to_new_record
|
240
236
|
assert_equal "http://test.host/workshops", redirect_to_url
|
237
|
+
assert_redirected_to Workshop.new(5, true)
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_redirect_with_partial_params
|
241
|
+
get :module_redirect
|
242
|
+
assert_redirected_to :action => 'hello_world'
|
241
243
|
end
|
242
244
|
|
243
245
|
def test_redirect_to_nil
|
@@ -245,7 +247,6 @@ class RedirectTest < Test::Unit::TestCase
|
|
245
247
|
get :redirect_to_nil
|
246
248
|
end
|
247
249
|
end
|
248
|
-
|
249
250
|
end
|
250
251
|
|
251
252
|
module ModuleTest
|
@@ -283,7 +284,7 @@ module ModuleTest
|
|
283
284
|
def test_module_redirect_using_options
|
284
285
|
get :module_redirect
|
285
286
|
assert_response :redirect
|
286
|
-
assert_redirected_to :controller => 'redirect', :action => "hello_world"
|
287
|
+
assert_redirected_to :controller => '/redirect', :action => "hello_world"
|
287
288
|
end
|
288
289
|
end
|
289
290
|
end
|