actionpack 2.3.2 → 2.3.3

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.

Files changed (117) hide show
  1. data/CHANGELOG +5 -0
  2. data/Rakefile +10 -9
  3. data/lib/action_controller.rb +2 -7
  4. data/lib/action_controller/assertions/response_assertions.rb +11 -3
  5. data/lib/action_controller/base.rb +7 -2
  6. data/lib/action_controller/caching.rb +1 -1
  7. data/lib/action_controller/caching/actions.rb +9 -1
  8. data/lib/action_controller/caching/sweeper.rb +45 -0
  9. data/lib/action_controller/caching/sweeping.rb +0 -42
  10. data/lib/action_controller/failsafe.rb +40 -6
  11. data/lib/action_controller/flash.rb +11 -3
  12. data/lib/action_controller/http_authentication.rb +5 -2
  13. data/lib/action_controller/integration.rb +5 -12
  14. data/lib/action_controller/middlewares.rb +0 -1
  15. data/lib/action_controller/reloader.rb +34 -3
  16. data/lib/action_controller/request.rb +6 -2
  17. data/lib/action_controller/response.rb +2 -2
  18. data/lib/action_controller/routing/route_set.rb +2 -1
  19. data/lib/action_controller/streaming.rb +1 -1
  20. data/lib/action_controller/test_process.rb +9 -1
  21. data/lib/action_pack/version.rb +1 -1
  22. data/lib/action_view/helpers.rb +1 -1
  23. data/lib/action_view/helpers/asset_tag_helper.rb +21 -9
  24. data/lib/action_view/helpers/date_helper.rb +2 -2
  25. data/lib/action_view/helpers/form_helper.rb +25 -12
  26. data/lib/action_view/helpers/form_options_helper.rb +2 -0
  27. data/lib/action_view/helpers/form_tag_helper.rb +10 -4
  28. data/lib/action_view/helpers/number_helper.rb +1 -1
  29. data/lib/action_view/helpers/prototype_helper.rb +7 -7
  30. data/lib/action_view/helpers/scriptaculous_helper.rb +5 -5
  31. data/lib/action_view/helpers/text_helper.rb +3 -3
  32. data/lib/action_view/helpers/url_helper.rb +1 -1
  33. data/lib/action_view/paths.rb +1 -1
  34. data/lib/action_view/template.rb +22 -33
  35. data/test/abstract_unit.rb +1 -1
  36. data/test/activerecord/active_record_store_test.rb +3 -3
  37. data/test/controller/action_pack_assertions_test.rb +27 -0
  38. data/test/controller/caching_test.rb +39 -0
  39. data/test/controller/cookie_test.rb +10 -0
  40. data/test/controller/dispatcher_test.rb +9 -7
  41. data/test/controller/failsafe_test.rb +60 -0
  42. data/test/controller/filter_params_test.rb +2 -1
  43. data/test/controller/flash_test.rb +6 -1
  44. data/test/controller/http_digest_authentication_test.rb +34 -3
  45. data/test/controller/integration_test.rb +31 -3
  46. data/test/controller/redirect_test.rb +4 -1
  47. data/test/controller/reloader_test.rb +97 -0
  48. data/test/controller/render_test.rb +19 -9
  49. data/test/controller/request/multipart_params_parsing_test.rb +1 -62
  50. data/test/controller/request/test_request_test.rb +35 -0
  51. data/test/controller/request/url_encoded_params_parsing_test.rb +0 -38
  52. data/test/controller/request_test.rb +218 -230
  53. data/test/controller/resources_test.rb +8 -0
  54. data/test/controller/routing_test.rb +21 -0
  55. data/test/controller/send_file_test.rb +1 -1
  56. data/test/controller/session/cookie_store_test.rb +9 -32
  57. data/test/controller/test_test.rb +8 -0
  58. data/test/fixtures/failsafe/500.html +1 -0
  59. data/test/template/active_record_helper_test.rb +1 -1
  60. data/test/template/asset_tag_helper_test.rb +46 -0
  61. data/test/template/form_helper_test.rb +117 -6
  62. data/test/template/form_options_helper_test.rb +22 -0
  63. data/test/template/form_tag_helper_test.rb +23 -6
  64. data/test/template/prototype_helper_test.rb +11 -11
  65. data/test/template/template_test.rb +32 -0
  66. metadata +20 -63
  67. data/lib/action_controller/rewindable_input.rb +0 -28
  68. data/lib/action_controller/vendor/rack-1.0/rack.rb +0 -89
  69. data/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +0 -22
  70. data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +0 -37
  71. data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +0 -37
  72. data/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +0 -58
  73. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +0 -124
  74. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +0 -51
  75. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +0 -55
  76. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +0 -40
  77. data/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +0 -480
  78. data/lib/action_controller/vendor/rack-1.0/rack/builder.rb +0 -63
  79. data/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +0 -36
  80. data/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +0 -49
  81. data/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +0 -61
  82. data/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +0 -45
  83. data/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +0 -29
  84. data/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +0 -23
  85. data/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +0 -85
  86. data/lib/action_controller/vendor/rack-1.0/rack/directory.rb +0 -153
  87. data/lib/action_controller/vendor/rack-1.0/rack/file.rb +0 -88
  88. data/lib/action_controller/vendor/rack-1.0/rack/handler.rb +0 -48
  89. data/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +0 -61
  90. data/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +0 -8
  91. data/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +0 -89
  92. data/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +0 -55
  93. data/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +0 -84
  94. data/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +0 -59
  95. data/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +0 -8
  96. data/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +0 -18
  97. data/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +0 -67
  98. data/lib/action_controller/vendor/rack-1.0/rack/head.rb +0 -19
  99. data/lib/action_controller/vendor/rack-1.0/rack/lint.rb +0 -462
  100. data/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +0 -65
  101. data/lib/action_controller/vendor/rack-1.0/rack/lock.rb +0 -16
  102. data/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +0 -27
  103. data/lib/action_controller/vendor/rack-1.0/rack/mime.rb +0 -204
  104. data/lib/action_controller/vendor/rack-1.0/rack/mock.rb +0 -160
  105. data/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +0 -57
  106. data/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +0 -64
  107. data/lib/action_controller/vendor/rack-1.0/rack/request.rb +0 -241
  108. data/lib/action_controller/vendor/rack-1.0/rack/response.rb +0 -179
  109. data/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +0 -142
  110. data/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +0 -91
  111. data/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +0 -109
  112. data/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +0 -100
  113. data/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +0 -349
  114. data/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +0 -106
  115. data/lib/action_controller/vendor/rack-1.0/rack/static.rb +0 -38
  116. data/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +0 -55
  117. data/lib/action_controller/vendor/rack-1.0/rack/utils.rb +0 -392
@@ -1,65 +0,0 @@
1
- require 'zlib'
2
-
3
- require 'rack/request'
4
- require 'rack/response'
5
-
6
- module Rack
7
- # Paste has a Pony, Rack has a Lobster!
8
- class Lobster
9
- LobsterString = Zlib::Inflate.inflate("eJx9kEEOwyAMBO99xd7MAcytUhPlJyj2
10
- P6jy9i4k9EQyGAnBarEXeCBqSkntNXsi/ZCvC48zGQoZKikGrFMZvgS5ZHd+aGWVuWwhVF0
11
- t1drVmiR42HcWNz5w3QanT+2gIvTVCiE1lm1Y0eU4JGmIIbaKwextKn8rvW+p5PIwFl8ZWJ
12
- I8jyiTlhTcYXkekJAzTyYN6E08A+dk8voBkAVTJQ==".delete("\n ").unpack("m*")[0])
13
-
14
- LambdaLobster = lambda { |env|
15
- if env["QUERY_STRING"].include?("flip")
16
- lobster = LobsterString.split("\n").
17
- map { |line| line.ljust(42).reverse }.
18
- join("\n")
19
- href = "?"
20
- else
21
- lobster = LobsterString
22
- href = "?flip"
23
- end
24
-
25
- content = ["<title>Lobstericious!</title>",
26
- "<pre>", lobster, "</pre>",
27
- "<a href='#{href}'>flip!</a>"]
28
- length = content.inject(0) { |a,e| a+e.size }.to_s
29
- [200, {"Content-Type" => "text/html", "Content-Length" => length}, content]
30
- }
31
-
32
- def call(env)
33
- req = Request.new(env)
34
- if req.GET["flip"] == "left"
35
- lobster = LobsterString.split("\n").
36
- map { |line| line.ljust(42).reverse }.
37
- join("\n")
38
- href = "?flip=right"
39
- elsif req.GET["flip"] == "crash"
40
- raise "Lobster crashed"
41
- else
42
- lobster = LobsterString
43
- href = "?flip=left"
44
- end
45
-
46
- res = Response.new
47
- res.write "<title>Lobstericious!</title>"
48
- res.write "<pre>"
49
- res.write lobster
50
- res.write "</pre>"
51
- res.write "<p><a href='#{href}'>flip!</a></p>"
52
- res.write "<p><a href='?flip=crash'>crash!</a></p>"
53
- res.finish
54
- end
55
-
56
- end
57
- end
58
-
59
- if $0 == __FILE__
60
- require 'rack'
61
- require 'rack/showexceptions'
62
- Rack::Handler::WEBrick.run \
63
- Rack::ShowExceptions.new(Rack::Lint.new(Rack::Lobster.new)),
64
- :Port => 9292
65
- end
@@ -1,16 +0,0 @@
1
- module Rack
2
- class Lock
3
- FLAG = 'rack.multithread'.freeze
4
-
5
- def initialize(app, lock = Mutex.new)
6
- @app, @lock = app, lock
7
- end
8
-
9
- def call(env)
10
- old, env[FLAG] = env[FLAG], false
11
- @lock.synchronize { @app.call(env) }
12
- ensure
13
- env[FLAG] = old
14
- end
15
- end
16
- end
@@ -1,27 +0,0 @@
1
- module Rack
2
- class MethodOverride
3
- HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS)
4
-
5
- METHOD_OVERRIDE_PARAM_KEY = "_method".freeze
6
- HTTP_METHOD_OVERRIDE_HEADER = "HTTP_X_HTTP_METHOD_OVERRIDE".freeze
7
-
8
- def initialize(app)
9
- @app = app
10
- end
11
-
12
- def call(env)
13
- if env["REQUEST_METHOD"] == "POST"
14
- req = Request.new(env)
15
- method = req.POST[METHOD_OVERRIDE_PARAM_KEY] ||
16
- env[HTTP_METHOD_OVERRIDE_HEADER]
17
- method = method.to_s.upcase
18
- if HTTP_METHODS.include?(method)
19
- env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"]
20
- env["REQUEST_METHOD"] = method
21
- end
22
- end
23
-
24
- @app.call(env)
25
- end
26
- end
27
- end
@@ -1,204 +0,0 @@
1
- module Rack
2
- module Mime
3
- # Returns String with mime type if found, otherwise use +fallback+.
4
- # +ext+ should be filename extension in the '.ext' format that
5
- # File.extname(file) returns.
6
- # +fallback+ may be any object
7
- #
8
- # Also see the documentation for MIME_TYPES
9
- #
10
- # Usage:
11
- # Rack::Mime.mime_type('.foo')
12
- #
13
- # This is a shortcut for:
14
- # Rack::Mime::MIME_TYPES.fetch('.foo', 'application/octet-stream')
15
-
16
- def mime_type(ext, fallback='application/octet-stream')
17
- MIME_TYPES.fetch(ext, fallback)
18
- end
19
- module_function :mime_type
20
-
21
- # List of most common mime-types, selected various sources
22
- # according to their usefulness in a webserving scope for Ruby
23
- # users.
24
- #
25
- # To amend this list with your local mime.types list you can use:
26
- #
27
- # require 'webrick/httputils'
28
- # list = WEBrick::HTTPUtils.load_mime_types('/etc/mime.types')
29
- # Rack::Mime::MIME_TYPES.merge!(list)
30
- #
31
- # To add the list mongrel provides, use:
32
- #
33
- # require 'mongrel/handlers'
34
- # Rack::Mime::MIME_TYPES.merge!(Mongrel::DirHandler::MIME_TYPES)
35
-
36
- MIME_TYPES = {
37
- ".3gp" => "video/3gpp",
38
- ".a" => "application/octet-stream",
39
- ".ai" => "application/postscript",
40
- ".aif" => "audio/x-aiff",
41
- ".aiff" => "audio/x-aiff",
42
- ".asc" => "application/pgp-signature",
43
- ".asf" => "video/x-ms-asf",
44
- ".asm" => "text/x-asm",
45
- ".asx" => "video/x-ms-asf",
46
- ".atom" => "application/atom+xml",
47
- ".au" => "audio/basic",
48
- ".avi" => "video/x-msvideo",
49
- ".bat" => "application/x-msdownload",
50
- ".bin" => "application/octet-stream",
51
- ".bmp" => "image/bmp",
52
- ".bz2" => "application/x-bzip2",
53
- ".c" => "text/x-c",
54
- ".cab" => "application/vnd.ms-cab-compressed",
55
- ".cc" => "text/x-c",
56
- ".chm" => "application/vnd.ms-htmlhelp",
57
- ".class" => "application/octet-stream",
58
- ".com" => "application/x-msdownload",
59
- ".conf" => "text/plain",
60
- ".cpp" => "text/x-c",
61
- ".crt" => "application/x-x509-ca-cert",
62
- ".css" => "text/css",
63
- ".csv" => "text/csv",
64
- ".cxx" => "text/x-c",
65
- ".deb" => "application/x-debian-package",
66
- ".der" => "application/x-x509-ca-cert",
67
- ".diff" => "text/x-diff",
68
- ".djv" => "image/vnd.djvu",
69
- ".djvu" => "image/vnd.djvu",
70
- ".dll" => "application/x-msdownload",
71
- ".dmg" => "application/octet-stream",
72
- ".doc" => "application/msword",
73
- ".dot" => "application/msword",
74
- ".dtd" => "application/xml-dtd",
75
- ".dvi" => "application/x-dvi",
76
- ".ear" => "application/java-archive",
77
- ".eml" => "message/rfc822",
78
- ".eps" => "application/postscript",
79
- ".exe" => "application/x-msdownload",
80
- ".f" => "text/x-fortran",
81
- ".f77" => "text/x-fortran",
82
- ".f90" => "text/x-fortran",
83
- ".flv" => "video/x-flv",
84
- ".for" => "text/x-fortran",
85
- ".gem" => "application/octet-stream",
86
- ".gemspec" => "text/x-script.ruby",
87
- ".gif" => "image/gif",
88
- ".gz" => "application/x-gzip",
89
- ".h" => "text/x-c",
90
- ".hh" => "text/x-c",
91
- ".htm" => "text/html",
92
- ".html" => "text/html",
93
- ".ico" => "image/vnd.microsoft.icon",
94
- ".ics" => "text/calendar",
95
- ".ifb" => "text/calendar",
96
- ".iso" => "application/octet-stream",
97
- ".jar" => "application/java-archive",
98
- ".java" => "text/x-java-source",
99
- ".jnlp" => "application/x-java-jnlp-file",
100
- ".jpeg" => "image/jpeg",
101
- ".jpg" => "image/jpeg",
102
- ".js" => "application/javascript",
103
- ".json" => "application/json",
104
- ".log" => "text/plain",
105
- ".m3u" => "audio/x-mpegurl",
106
- ".m4v" => "video/mp4",
107
- ".man" => "text/troff",
108
- ".mathml" => "application/mathml+xml",
109
- ".mbox" => "application/mbox",
110
- ".mdoc" => "text/troff",
111
- ".me" => "text/troff",
112
- ".mid" => "audio/midi",
113
- ".midi" => "audio/midi",
114
- ".mime" => "message/rfc822",
115
- ".mml" => "application/mathml+xml",
116
- ".mng" => "video/x-mng",
117
- ".mov" => "video/quicktime",
118
- ".mp3" => "audio/mpeg",
119
- ".mp4" => "video/mp4",
120
- ".mp4v" => "video/mp4",
121
- ".mpeg" => "video/mpeg",
122
- ".mpg" => "video/mpeg",
123
- ".ms" => "text/troff",
124
- ".msi" => "application/x-msdownload",
125
- ".odp" => "application/vnd.oasis.opendocument.presentation",
126
- ".ods" => "application/vnd.oasis.opendocument.spreadsheet",
127
- ".odt" => "application/vnd.oasis.opendocument.text",
128
- ".ogg" => "application/ogg",
129
- ".p" => "text/x-pascal",
130
- ".pas" => "text/x-pascal",
131
- ".pbm" => "image/x-portable-bitmap",
132
- ".pdf" => "application/pdf",
133
- ".pem" => "application/x-x509-ca-cert",
134
- ".pgm" => "image/x-portable-graymap",
135
- ".pgp" => "application/pgp-encrypted",
136
- ".pkg" => "application/octet-stream",
137
- ".pl" => "text/x-script.perl",
138
- ".pm" => "text/x-script.perl-module",
139
- ".png" => "image/png",
140
- ".pnm" => "image/x-portable-anymap",
141
- ".ppm" => "image/x-portable-pixmap",
142
- ".pps" => "application/vnd.ms-powerpoint",
143
- ".ppt" => "application/vnd.ms-powerpoint",
144
- ".ps" => "application/postscript",
145
- ".psd" => "image/vnd.adobe.photoshop",
146
- ".py" => "text/x-script.python",
147
- ".qt" => "video/quicktime",
148
- ".ra" => "audio/x-pn-realaudio",
149
- ".rake" => "text/x-script.ruby",
150
- ".ram" => "audio/x-pn-realaudio",
151
- ".rar" => "application/x-rar-compressed",
152
- ".rb" => "text/x-script.ruby",
153
- ".rdf" => "application/rdf+xml",
154
- ".roff" => "text/troff",
155
- ".rpm" => "application/x-redhat-package-manager",
156
- ".rss" => "application/rss+xml",
157
- ".rtf" => "application/rtf",
158
- ".ru" => "text/x-script.ruby",
159
- ".s" => "text/x-asm",
160
- ".sgm" => "text/sgml",
161
- ".sgml" => "text/sgml",
162
- ".sh" => "application/x-sh",
163
- ".sig" => "application/pgp-signature",
164
- ".snd" => "audio/basic",
165
- ".so" => "application/octet-stream",
166
- ".svg" => "image/svg+xml",
167
- ".svgz" => "image/svg+xml",
168
- ".swf" => "application/x-shockwave-flash",
169
- ".t" => "text/troff",
170
- ".tar" => "application/x-tar",
171
- ".tbz" => "application/x-bzip-compressed-tar",
172
- ".tcl" => "application/x-tcl",
173
- ".tex" => "application/x-tex",
174
- ".texi" => "application/x-texinfo",
175
- ".texinfo" => "application/x-texinfo",
176
- ".text" => "text/plain",
177
- ".tif" => "image/tiff",
178
- ".tiff" => "image/tiff",
179
- ".torrent" => "application/x-bittorrent",
180
- ".tr" => "text/troff",
181
- ".txt" => "text/plain",
182
- ".vcf" => "text/x-vcard",
183
- ".vcs" => "text/x-vcalendar",
184
- ".vrml" => "model/vrml",
185
- ".war" => "application/java-archive",
186
- ".wav" => "audio/x-wav",
187
- ".wma" => "audio/x-ms-wma",
188
- ".wmv" => "video/x-ms-wmv",
189
- ".wmx" => "video/x-ms-wmx",
190
- ".wrl" => "model/vrml",
191
- ".wsdl" => "application/wsdl+xml",
192
- ".xbm" => "image/x-xbitmap",
193
- ".xhtml" => "application/xhtml+xml",
194
- ".xls" => "application/vnd.ms-excel",
195
- ".xml" => "application/xml",
196
- ".xpm" => "image/x-xpixmap",
197
- ".xsl" => "application/xml",
198
- ".xslt" => "application/xslt+xml",
199
- ".yaml" => "text/yaml",
200
- ".yml" => "text/yaml",
201
- ".zip" => "application/zip",
202
- }
203
- end
204
- end
@@ -1,160 +0,0 @@
1
- require 'uri'
2
- require 'stringio'
3
- require 'rack/lint'
4
- require 'rack/utils'
5
- require 'rack/response'
6
-
7
- module Rack
8
- # Rack::MockRequest helps testing your Rack application without
9
- # actually using HTTP.
10
- #
11
- # After performing a request on a URL with get/post/put/delete, it
12
- # returns a MockResponse with useful helper methods for effective
13
- # testing.
14
- #
15
- # You can pass a hash with additional configuration to the
16
- # get/post/put/delete.
17
- # <tt>:input</tt>:: A String or IO-like to be used as rack.input.
18
- # <tt>:fatal</tt>:: Raise a FatalWarning if the app writes to rack.errors.
19
- # <tt>:lint</tt>:: If true, wrap the application in a Rack::Lint.
20
-
21
- class MockRequest
22
- class FatalWarning < RuntimeError
23
- end
24
-
25
- class FatalWarner
26
- def puts(warning)
27
- raise FatalWarning, warning
28
- end
29
-
30
- def write(warning)
31
- raise FatalWarning, warning
32
- end
33
-
34
- def flush
35
- end
36
-
37
- def string
38
- ""
39
- end
40
- end
41
-
42
- DEFAULT_ENV = {
43
- "rack.version" => [0,1],
44
- "rack.input" => StringIO.new,
45
- "rack.errors" => StringIO.new,
46
- "rack.multithread" => true,
47
- "rack.multiprocess" => true,
48
- "rack.run_once" => false,
49
- }
50
-
51
- def initialize(app)
52
- @app = app
53
- end
54
-
55
- def get(uri, opts={}) request("GET", uri, opts) end
56
- def post(uri, opts={}) request("POST", uri, opts) end
57
- def put(uri, opts={}) request("PUT", uri, opts) end
58
- def delete(uri, opts={}) request("DELETE", uri, opts) end
59
-
60
- def request(method="GET", uri="", opts={})
61
- env = self.class.env_for(uri, opts.merge(:method => method))
62
-
63
- if opts[:lint]
64
- app = Rack::Lint.new(@app)
65
- else
66
- app = @app
67
- end
68
-
69
- errors = env["rack.errors"]
70
- MockResponse.new(*(app.call(env) + [errors]))
71
- end
72
-
73
- # Return the Rack environment used for a request to +uri+.
74
- def self.env_for(uri="", opts={})
75
- uri = URI(uri)
76
- env = DEFAULT_ENV.dup
77
-
78
- env["REQUEST_METHOD"] = opts[:method] || "GET"
79
- env["SERVER_NAME"] = uri.host || "example.org"
80
- env["SERVER_PORT"] = uri.port ? uri.port.to_s : "80"
81
- env["QUERY_STRING"] = uri.query.to_s
82
- env["PATH_INFO"] = (!uri.path || uri.path.empty?) ? "/" : uri.path
83
- env["rack.url_scheme"] = uri.scheme || "http"
84
-
85
- env["SCRIPT_NAME"] = opts[:script_name] || ""
86
-
87
- if opts[:fatal]
88
- env["rack.errors"] = FatalWarner.new
89
- else
90
- env["rack.errors"] = StringIO.new
91
- end
92
-
93
- opts[:input] ||= ""
94
- if String === opts[:input]
95
- env["rack.input"] = StringIO.new(opts[:input])
96
- else
97
- env["rack.input"] = opts[:input]
98
- end
99
-
100
- env["CONTENT_LENGTH"] ||= env["rack.input"].length.to_s
101
-
102
- opts.each { |field, value|
103
- env[field] = value if String === field
104
- }
105
-
106
- env
107
- end
108
- end
109
-
110
- # Rack::MockResponse provides useful helpers for testing your apps.
111
- # Usually, you don't create the MockResponse on your own, but use
112
- # MockRequest.
113
-
114
- class MockResponse
115
- def initialize(status, headers, body, errors=StringIO.new(""))
116
- @status = status.to_i
117
-
118
- @original_headers = headers
119
- @headers = Rack::Utils::HeaderHash.new
120
- headers.each { |field, values|
121
- @headers[field] = values
122
- @headers[field] = "" if values.empty?
123
- }
124
-
125
- @body = ""
126
- body.each { |part| @body << part }
127
-
128
- @errors = errors.string
129
- end
130
-
131
- # Status
132
- attr_reader :status
133
-
134
- # Headers
135
- attr_reader :headers, :original_headers
136
-
137
- def [](field)
138
- headers[field]
139
- end
140
-
141
-
142
- # Body
143
- attr_reader :body
144
-
145
- def =~(other)
146
- @body =~ other
147
- end
148
-
149
- def match(other)
150
- @body.match other
151
- end
152
-
153
-
154
- # Errors
155
- attr_accessor :errors
156
-
157
-
158
- include Response::Helpers
159
- end
160
- end