roda 3.28.0 → 3.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +10 -0
  3. data/README.rdoc +10 -0
  4. data/doc/release_notes/3.29.0.txt +15 -0
  5. data/lib/roda.rb +1 -0
  6. data/lib/roda/plugins/caching.rb +2 -0
  7. data/lib/roda/plugins/common_logger.rb +1 -1
  8. data/lib/roda/plugins/exception_page.rb +7 -1
  9. data/lib/roda/plugins/indifferent_params.rb +2 -0
  10. data/lib/roda/version.rb +1 -1
  11. metadata +4 -214
  12. data/Rakefile +0 -108
  13. data/doc/release_notes/1.0.0.txt +0 -329
  14. data/doc/release_notes/1.1.0.txt +0 -226
  15. data/doc/release_notes/1.2.0.txt +0 -406
  16. data/doc/release_notes/1.3.0.txt +0 -109
  17. data/doc/release_notes/2.0.0.txt +0 -75
  18. data/doc/release_notes/2.1.0.txt +0 -124
  19. data/doc/release_notes/2.10.0.txt +0 -27
  20. data/doc/release_notes/2.11.0.txt +0 -70
  21. data/doc/release_notes/2.12.0.txt +0 -40
  22. data/doc/release_notes/2.13.0.txt +0 -10
  23. data/doc/release_notes/2.14.0.txt +0 -44
  24. data/doc/release_notes/2.15.0.txt +0 -53
  25. data/doc/release_notes/2.16.0.txt +0 -48
  26. data/doc/release_notes/2.17.0.txt +0 -62
  27. data/doc/release_notes/2.18.0.txt +0 -69
  28. data/doc/release_notes/2.19.0.txt +0 -30
  29. data/doc/release_notes/2.2.0.txt +0 -97
  30. data/doc/release_notes/2.20.0.txt +0 -5
  31. data/doc/release_notes/2.21.0.txt +0 -17
  32. data/doc/release_notes/2.22.0.txt +0 -41
  33. data/doc/release_notes/2.23.0.txt +0 -29
  34. data/doc/release_notes/2.24.0.txt +0 -65
  35. data/doc/release_notes/2.25.0.txt +0 -14
  36. data/doc/release_notes/2.26.0.txt +0 -13
  37. data/doc/release_notes/2.27.0.txt +0 -56
  38. data/doc/release_notes/2.28.0.txt +0 -17
  39. data/doc/release_notes/2.29.0.txt +0 -156
  40. data/doc/release_notes/2.3.0.txt +0 -109
  41. data/doc/release_notes/2.4.0.txt +0 -55
  42. data/doc/release_notes/2.5.0.txt +0 -23
  43. data/doc/release_notes/2.5.1.txt +0 -4
  44. data/doc/release_notes/2.6.0.txt +0 -21
  45. data/doc/release_notes/2.7.0.txt +0 -75
  46. data/doc/release_notes/2.8.0.txt +0 -44
  47. data/doc/release_notes/2.9.0.txt +0 -6
  48. data/spec/all.rb +0 -1
  49. data/spec/assets/css/app.scss +0 -1
  50. data/spec/assets/css/no_access.css +0 -1
  51. data/spec/assets/css/raw.css +0 -1
  52. data/spec/assets/js/head/app.js +0 -1
  53. data/spec/composition_spec.rb +0 -31
  54. data/spec/define_roda_method_spec.rb +0 -274
  55. data/spec/env_spec.rb +0 -11
  56. data/spec/freeze_spec.rb +0 -37
  57. data/spec/integration_spec.rb +0 -209
  58. data/spec/matchers_spec.rb +0 -832
  59. data/spec/opts_spec.rb +0 -42
  60. data/spec/plugin/_after_hook_spec.rb +0 -19
  61. data/spec/plugin/all_verbs_spec.rb +0 -29
  62. data/spec/plugin/assets_preloading_spec.rb +0 -98
  63. data/spec/plugin/assets_spec.rb +0 -745
  64. data/spec/plugin/backtracking_array_spec.rb +0 -42
  65. data/spec/plugin/branch_locals_spec.rb +0 -106
  66. data/spec/plugin/caching_spec.rb +0 -337
  67. data/spec/plugin/chunked_spec.rb +0 -201
  68. data/spec/plugin/class_level_routing_spec.rb +0 -164
  69. data/spec/plugin/class_matchers_spec.rb +0 -40
  70. data/spec/plugin/common_logger_spec.rb +0 -85
  71. data/spec/plugin/content_for_spec.rb +0 -162
  72. data/spec/plugin/content_security_policy_spec.rb +0 -175
  73. data/spec/plugin/cookies_spec.rb +0 -51
  74. data/spec/plugin/csrf_spec.rb +0 -111
  75. data/spec/plugin/default_headers_spec.rb +0 -82
  76. data/spec/plugin/default_status_spec.rb +0 -95
  77. data/spec/plugin/delay_build_spec.rb +0 -23
  78. data/spec/plugin/delegate_spec.rb +0 -23
  79. data/spec/plugin/delete_empty_headers_spec.rb +0 -27
  80. data/spec/plugin/direct_call_spec.rb +0 -28
  81. data/spec/plugin/disallow_file_uploads_spec.rb +0 -25
  82. data/spec/plugin/drop_body_spec.rb +0 -24
  83. data/spec/plugin/early_hints_spec.rb +0 -19
  84. data/spec/plugin/empty_root_spec.rb +0 -14
  85. data/spec/plugin/environments_spec.rb +0 -42
  86. data/spec/plugin/error_email_spec.rb +0 -97
  87. data/spec/plugin/error_handler_spec.rb +0 -216
  88. data/spec/plugin/error_mail_spec.rb +0 -93
  89. data/spec/plugin/exception_page_spec.rb +0 -168
  90. data/spec/plugin/flash_spec.rb +0 -121
  91. data/spec/plugin/h_spec.rb +0 -11
  92. data/spec/plugin/halt_spec.rb +0 -119
  93. data/spec/plugin/hash_matcher_spec.rb +0 -27
  94. data/spec/plugin/hash_routes_spec.rb +0 -535
  95. data/spec/plugin/head_spec.rb +0 -52
  96. data/spec/plugin/header_matchers_spec.rb +0 -98
  97. data/spec/plugin/heartbeat_spec.rb +0 -74
  98. data/spec/plugin/hooks_spec.rb +0 -152
  99. data/spec/plugin/indifferent_params_spec.rb +0 -14
  100. data/spec/plugin/json_parser_spec.rb +0 -141
  101. data/spec/plugin/json_spec.rb +0 -83
  102. data/spec/plugin/mail_processor_spec.rb +0 -451
  103. data/spec/plugin/mailer_spec.rb +0 -282
  104. data/spec/plugin/match_affix_spec.rb +0 -43
  105. data/spec/plugin/match_hook_spec.rb +0 -79
  106. data/spec/plugin/middleware_spec.rb +0 -237
  107. data/spec/plugin/middleware_stack_spec.rb +0 -81
  108. data/spec/plugin/module_include_spec.rb +0 -48
  109. data/spec/plugin/multi_route_spec.rb +0 -268
  110. data/spec/plugin/multi_run_spec.rb +0 -87
  111. data/spec/plugin/multi_view_spec.rb +0 -50
  112. data/spec/plugin/multibyte_string_matcher_spec.rb +0 -44
  113. data/spec/plugin/named_templates_spec.rb +0 -96
  114. data/spec/plugin/not_allowed_spec.rb +0 -69
  115. data/spec/plugin/not_found_spec.rb +0 -128
  116. data/spec/plugin/optimized_string_matchers_spec.rb +0 -43
  117. data/spec/plugin/padrino_render_spec.rb +0 -34
  118. data/spec/plugin/param_matchers_spec.rb +0 -69
  119. data/spec/plugin/params_capturing_spec.rb +0 -33
  120. data/spec/plugin/partials_spec.rb +0 -43
  121. data/spec/plugin/pass_spec.rb +0 -29
  122. data/spec/plugin/path_matchers_spec.rb +0 -42
  123. data/spec/plugin/path_rewriter_spec.rb +0 -45
  124. data/spec/plugin/path_spec.rb +0 -222
  125. data/spec/plugin/placeholder_string_matchers_spec.rb +0 -126
  126. data/spec/plugin/precompile_templates_spec.rb +0 -61
  127. data/spec/plugin/public_spec.rb +0 -85
  128. data/spec/plugin/render_each_spec.rb +0 -82
  129. data/spec/plugin/render_locals_spec.rb +0 -114
  130. data/spec/plugin/render_spec.rb +0 -912
  131. data/spec/plugin/request_aref_spec.rb +0 -51
  132. data/spec/plugin/request_headers_spec.rb +0 -39
  133. data/spec/plugin/response_request_spec.rb +0 -43
  134. data/spec/plugin/route_block_args_spec.rb +0 -86
  135. data/spec/plugin/route_csrf_spec.rb +0 -305
  136. data/spec/plugin/run_append_slash_spec.rb +0 -77
  137. data/spec/plugin/run_handler_spec.rb +0 -53
  138. data/spec/plugin/sessions_spec.rb +0 -452
  139. data/spec/plugin/shared_vars_spec.rb +0 -45
  140. data/spec/plugin/sinatra_helpers_spec.rb +0 -537
  141. data/spec/plugin/slash_path_empty_spec.rb +0 -22
  142. data/spec/plugin/static_routing_spec.rb +0 -192
  143. data/spec/plugin/static_spec.rb +0 -30
  144. data/spec/plugin/status_303_spec.rb +0 -28
  145. data/spec/plugin/status_handler_spec.rb +0 -158
  146. data/spec/plugin/streaming_spec.rb +0 -246
  147. data/spec/plugin/strip_path_prefix_spec.rb +0 -24
  148. data/spec/plugin/symbol_matchers_spec.rb +0 -51
  149. data/spec/plugin/symbol_status_spec.rb +0 -25
  150. data/spec/plugin/symbol_views_spec.rb +0 -32
  151. data/spec/plugin/timestamp_public_spec.rb +0 -85
  152. data/spec/plugin/type_routing_spec.rb +0 -348
  153. data/spec/plugin/typecast_params_spec.rb +0 -1370
  154. data/spec/plugin/unescape_path_spec.rb +0 -22
  155. data/spec/plugin/view_options_spec.rb +0 -170
  156. data/spec/plugin_spec.rb +0 -71
  157. data/spec/redirect_spec.rb +0 -41
  158. data/spec/request_spec.rb +0 -97
  159. data/spec/response_spec.rb +0 -199
  160. data/spec/route_spec.rb +0 -39
  161. data/spec/session_middleware_spec.rb +0 -129
  162. data/spec/session_spec.rb +0 -37
  163. data/spec/spec_helper.rb +0 -137
  164. data/spec/version_spec.rb +0 -14
  165. data/spec/views/_test.erb +0 -1
  166. data/spec/views/a.erb +0 -1
  167. data/spec/views/a.rdoc +0 -2
  168. data/spec/views/about.erb +0 -1
  169. data/spec/views/about.str +0 -1
  170. data/spec/views/about/_test.css.gz +0 -0
  171. data/spec/views/about/_test.erb +0 -1
  172. data/spec/views/about/_test.erb.gz +0 -0
  173. data/spec/views/about/comp_test.erb +0 -1
  174. data/spec/views/b.erb +0 -1
  175. data/spec/views/c.erb +0 -1
  176. data/spec/views/comp_layout.erb +0 -1
  177. data/spec/views/comp_test.erb +0 -1
  178. data/spec/views/content-yield.erb +0 -1
  179. data/spec/views/each.str +0 -1
  180. data/spec/views/home.erb +0 -2
  181. data/spec/views/home.str +0 -2
  182. data/spec/views/iv.erb +0 -1
  183. data/spec/views/layout-alternative.erb +0 -2
  184. data/spec/views/layout-yield.erb +0 -3
  185. data/spec/views/layout.erb +0 -2
  186. data/spec/views/layout.str +0 -2
  187. data/spec/views/multiple-layout.erb +0 -1
  188. data/spec/views/multiple.erb +0 -1
@@ -1,201 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- begin
4
- require 'tilt/erb'
5
- rescue LoadError
6
- warn "tilt not installed, skipping chunked plugin test"
7
- else
8
- describe "chunked plugin" do
9
- def cbody(env={})
10
- body({'HTTP_VERSION'=>'HTTP/1.1'}.merge(env))
11
- end
12
-
13
- it "streams templates in chunked encoding only if HTTP 1.1 is used" do
14
- app(:chunked) do |r|
15
- chunked(:inline=>'m', :layout=>{:inline=>'h<%= yield %>t'})
16
- end
17
-
18
- cbody.must_equal "1\r\nh\r\n1\r\nm\r\n1\r\nt\r\n0\r\n\r\n"
19
- body.must_equal "hmt"
20
- end
21
-
22
- it "hex encodes chunk sizes" do
23
- m = 'm' * 31
24
- app(:chunked) do |r|
25
- chunked(:inline=>m.dup, :layout=>{:inline=>'h<%= yield %>t'})
26
- end
27
-
28
- cbody.must_equal "1\r\nh\r\n1f\r\n#{m}\r\n1\r\nt\r\n0\r\n\r\n"
29
- body.must_equal "h#{m}t"
30
- end
31
-
32
- it "accepts a block that is called after layout yielding but before content when streaming" do
33
- app(:chunked) do |r|
34
- @h = nil
35
- chunked(:inline=>'m<%= @h %>', :layout=>{:inline=>'<%= @h %><%= yield %>t'}) do
36
- @h = 'h'
37
- end
38
- end
39
-
40
- cbody.must_equal "2\r\nmh\r\n1\r\nt\r\n0\r\n\r\n"
41
- body.must_equal "hmht"
42
- end
43
-
44
- it "has delay accept block that is called after layout yielding but before content when streaming" do
45
- app(:chunked) do |r|
46
- delay do
47
- @h << 'i'
48
- end
49
- @h = String.new('h')
50
- chunked(:inline=>'m<%= @h %>', :layout=>{:inline=>'<%= @h %><%= yield %>t'}) do
51
- @h << 'j'
52
- end
53
- end
54
-
55
- cbody.must_equal "1\r\nh\r\n4\r\nmhij\r\n1\r\nt\r\n0\r\n\r\n"
56
- body.must_equal "hijmhijt"
57
- end
58
-
59
- it "has delay raise if not given a block" do
60
- app(:chunked){|r| delay}
61
- proc{body}.must_raise(Roda::RodaError)
62
- end
63
-
64
- it "works when a layout is not used" do
65
- app(:chunked) do |r|
66
- chunked(:inline=>'m', :layout=>nil)
67
- end
68
-
69
- cbody.must_equal "1\r\nm\r\n0\r\n\r\n"
70
- body.must_equal "m"
71
- end
72
-
73
- it "streams partial template responses if flush is used in content template" do
74
- app(:chunked) do |r|
75
- chunked(:inline=>'m<%= flush %>n', :layout=>{:inline=>'h<%= yield %>t'})
76
- end
77
-
78
- cbody.must_equal "1\r\nh\r\n1\r\nm\r\n1\r\nn\r\n1\r\nt\r\n0\r\n\r\n"
79
- body.must_equal "hmnt"
80
- end
81
-
82
- it "streams partial template responses if flush is used in layout template" do
83
- app(:chunked) do |r|
84
- chunked(:inline=>'m', :layout=>{:inline=>'h<%= flush %>i<%= yield %>t'})
85
- end
86
-
87
- cbody.must_equal "1\r\nh\r\n1\r\ni\r\n1\r\nm\r\n1\r\nt\r\n0\r\n\r\n"
88
- body.must_equal "himt"
89
- end
90
-
91
- it "does not stream if no_chunk! is used" do
92
- app(:chunked) do |r|
93
- no_chunk!
94
- chunked(:inline=>'m', :layout=>{:inline=>'h<%= yield %>t'})
95
- end
96
-
97
- cbody.must_equal "hmt"
98
- body.must_equal "hmt"
99
- end
100
-
101
- it "streams existing response body before call" do
102
- app(:chunked) do |r|
103
- response.write('a')
104
- response.write chunked(:inline=>'m', :layout=>{:inline=>'h<%= yield %>t'})
105
- end
106
-
107
- cbody.must_equal "1\r\na\r\n1\r\nh\r\n1\r\nm\r\n1\r\nt\r\n0\r\n\r\n"
108
- body.must_equal "ahmt"
109
- end
110
-
111
- it "should not include Content-Length header even if body is already written to" do
112
- app(:chunked) do |r|
113
- response.write('a')
114
- response.write chunked(:inline=>'m', :layout=>{:inline=>'h<%= yield %>t'})
115
- end
116
-
117
- header('Content-Length', 'HTTP_VERSION'=>'HTTP/1.1').must_be_nil
118
- header('Content-Length', 'HTTP_VERSION'=>'HTTP/1.0').must_equal '4'
119
- end
120
-
121
- it "stream template responses for view if :chunk_by_default is used" do
122
- app(:bare) do
123
- plugin :chunked, :chunk_by_default=>true
124
- route do |r|
125
- view(:inline=>'m', :layout=>{:inline=>'h<%= yield %>t'})
126
- end
127
- end
128
-
129
- cbody.must_equal "1\r\nh\r\n1\r\nm\r\n1\r\nt\r\n0\r\n\r\n"
130
- body.must_equal "hmt"
131
- end
132
-
133
- it "uses Transfer-Encoding header when chunking" do
134
- app(:chunked) do |r|
135
- chunked(:inline=>'m', :layout=>{:inline=>'h<%= yield %>t'})
136
- end
137
-
138
- header('Transfer-Encoding', 'HTTP_VERSION'=>'HTTP/1.1').must_equal 'chunked'
139
- header('Transfer-Encoding', 'HTTP_VERSION'=>'HTTP/1.0').must_be_nil
140
- end
141
-
142
- it "uses given :headers when chunking" do
143
- app(:bare) do
144
- plugin :chunked, :headers=>{'Foo'=>'bar'}
145
- route do |r|
146
- chunked(:inline=>'m', :layout=>{:inline=>'h<%= yield %>t'})
147
- end
148
- end
149
-
150
- header('Foo', 'HTTP_VERSION'=>'HTTP/1.1').must_equal 'bar'
151
- header('Foo', 'HTTP_VERSION'=>'HTTP/1.0').must_be_nil
152
- end
153
-
154
- it "handles multiple arguments to chunked" do
155
- app(:bare) do
156
- plugin :chunked, :chunk_by_default=>true
157
- plugin :render, :views => "./spec/views"
158
- route do |r|
159
- chunked('about', :locals=>{:title=>'m'}, :layout=>{:inline=>'h<%= yield %>t'})
160
- end
161
- end
162
-
163
- cbody.must_equal "1\r\nh\r\nb\r\n<h1>m</h1>\n\r\n1\r\nt\r\n0\r\n\r\n"
164
- body.must_equal "h<h1>m</h1>\nt"
165
- end
166
-
167
- it "handles multiple hash arguments to chunked" do
168
- app(:chunked) do |r|
169
- chunked({:inline=>'m'}, :layout=>{:inline=>'h<%= yield %>t'})
170
- end
171
-
172
- cbody.must_equal "1\r\nh\r\n1\r\nm\r\n1\r\nt\r\n0\r\n\r\n"
173
- body.must_equal "hmt"
174
- end
175
-
176
- it "handles :layout_opts option" do
177
- app(:chunked) do |r|
178
- chunked(:inline=>'m', :layout=>{:inline=>'<%= h %><%= yield %>t'}, :layout_opts=>{:locals=>{:h=>'h'}})
179
- end
180
-
181
- cbody.must_equal "1\r\nh\r\n1\r\nm\r\n1\r\nt\r\n0\r\n\r\n"
182
- body.must_equal "hmt"
183
- end
184
-
185
- it "uses handle_chunk_error for handling errors when chunking" do
186
- app(:chunked) do |r|
187
- chunked(:inline=>'m', :layout=>{:inline=>'h<%= yield %><% raise %>'})
188
- end
189
- proc{cbody}.must_raise RuntimeError
190
- proc{body}.must_raise RuntimeError
191
-
192
- app.send(:define_method, :handle_chunk_error) do |v|
193
- @_out_buf = 'e'
194
- flush
195
- end
196
-
197
- cbody.must_equal "1\r\nh\r\n1\r\nm\r\n1\r\ne\r\n0\r\n\r\n"
198
- proc{body}.must_raise RuntimeError
199
- end
200
- end
201
- end
@@ -1,164 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "class_level_routing plugin" do
4
- before do
5
- app(:bare) do
6
- plugin :class_level_routing
7
- plugin :all_verbs
8
-
9
- root do
10
- 'root'
11
- end
12
-
13
- on "foo" do
14
- request.get "bar" do
15
- "foobar"
16
- end
17
-
18
- "foo"
19
- end
20
-
21
- is "d", :d do |x|
22
- request.get do
23
- "bazget#{x}"
24
- end
25
-
26
- request.post do
27
- "bazpost#{x}"
28
- end
29
- end
30
-
31
- meths = %w'get post delete head options patch put trace'
32
- meths.concat(%w'link unlink') if ::Rack::Request.method_defined?("link?")
33
- meths.each do |meth|
34
- send(meth, :d) do |m|
35
- "x-#{meth}-#{m}"
36
- end
37
- end
38
- end
39
- end
40
-
41
- it "adds class methods for setting up routes" do
42
- body.must_equal 'root'
43
- body('/foo').must_equal 'foo'
44
- body('/foo/bar').must_equal 'foobar'
45
- body('/d/go').must_equal 'bazgetgo'
46
- body('/d/go', 'REQUEST_METHOD'=>'POST').must_equal 'bazpostgo'
47
- body('/bar').must_equal "x-get-bar"
48
- body('/bar', 'REQUEST_METHOD'=>'POST').must_equal "x-post-bar"
49
- body('/bar', 'REQUEST_METHOD'=>'DELETE').must_equal "x-delete-bar"
50
- body('/bar', 'REQUEST_METHOD'=>'HEAD').must_equal "x-head-bar"
51
- body('/bar', 'REQUEST_METHOD'=>'OPTIONS').must_equal "x-options-bar"
52
- body('/bar', 'REQUEST_METHOD'=>'PATCH').must_equal "x-patch-bar"
53
- body('/bar', 'REQUEST_METHOD'=>'PUT').must_equal "x-put-bar"
54
- body('/bar', 'REQUEST_METHOD'=>'TRACE').must_equal "x-trace-bar"
55
- if ::Rack::Request.method_defined?("link?")
56
- body('/bar', 'REQUEST_METHOD'=>'LINK').must_equal "x-link-bar"
57
- body('/bar', 'REQUEST_METHOD'=>'UNLINK').must_equal "x-unlink-bar"
58
- end
59
-
60
- status.must_equal 200
61
- status("/asdfa/asdf").must_equal 404
62
-
63
- @app = Class.new(app)
64
- body.must_equal 'root'
65
- body('/foo').must_equal 'foo'
66
- body('/foo/bar').must_equal 'foobar'
67
- body('/d/go').must_equal 'bazgetgo'
68
- body('/d/go', 'REQUEST_METHOD'=>'POST').must_equal 'bazpostgo'
69
- body('/bar').must_equal "x-get-bar"
70
- body('/bar', 'REQUEST_METHOD'=>'POST').must_equal "x-post-bar"
71
- body('/bar', 'REQUEST_METHOD'=>'DELETE').must_equal "x-delete-bar"
72
- body('/bar', 'REQUEST_METHOD'=>'HEAD').must_equal "x-head-bar"
73
- body('/bar', 'REQUEST_METHOD'=>'OPTIONS').must_equal "x-options-bar"
74
- body('/bar', 'REQUEST_METHOD'=>'PATCH').must_equal "x-patch-bar"
75
- body('/bar', 'REQUEST_METHOD'=>'PUT').must_equal "x-put-bar"
76
- body('/bar', 'REQUEST_METHOD'=>'TRACE').must_equal "x-trace-bar"
77
- end
78
-
79
- it "only calls class level routes if routing tree doesn't handle request" do
80
- app.route do |r|
81
- r.root do
82
- 'iroot'
83
- end
84
-
85
- r.get 'foo' do
86
- 'ifoo'
87
- end
88
-
89
- r.on 'bar' do
90
- r.get true do
91
- response.status = 404
92
- ''
93
- end
94
- r.post true do
95
- 'ibar'
96
- end
97
- end
98
- end
99
-
100
- body.must_equal 'iroot'
101
- body('/foo').must_equal 'ifoo'
102
- body('/foo/bar').must_equal 'foobar'
103
- body('/d/go').must_equal 'bazgetgo'
104
- body('/d/go', 'REQUEST_METHOD'=>'POST').must_equal 'bazpostgo'
105
- body('/bar').must_equal ""
106
- body('/bar', 'REQUEST_METHOD'=>'POST').must_equal "ibar"
107
- body('/bar', 'REQUEST_METHOD'=>'DELETE').must_equal "x-delete-bar"
108
- body('/bar', 'REQUEST_METHOD'=>'HEAD').must_equal "x-head-bar"
109
- body('/bar', 'REQUEST_METHOD'=>'OPTIONS').must_equal "x-options-bar"
110
- body('/bar', 'REQUEST_METHOD'=>'PATCH').must_equal "x-patch-bar"
111
- body('/bar', 'REQUEST_METHOD'=>'PUT').must_equal "x-put-bar"
112
- body('/bar', 'REQUEST_METHOD'=>'TRACE').must_equal "x-trace-bar"
113
- end
114
-
115
- it "works with the not_found plugin if loaded before" do
116
- app.plugin :not_found do
117
- "nf"
118
- end
119
-
120
- body.must_equal 'root'
121
- body('/foo').must_equal 'foo'
122
- body('/foo/bar').must_equal 'foobar'
123
- body('/d/go').must_equal 'bazgetgo'
124
- body('/d/go', 'REQUEST_METHOD'=>'POST').must_equal 'bazpostgo'
125
- body('/bar').must_equal "x-get-bar"
126
- body('/bar', 'REQUEST_METHOD'=>'POST').must_equal "x-post-bar"
127
- body('/bar', 'REQUEST_METHOD'=>'DELETE').must_equal "x-delete-bar"
128
- body('/bar', 'REQUEST_METHOD'=>'HEAD').must_equal "x-head-bar"
129
- body('/bar', 'REQUEST_METHOD'=>'OPTIONS').must_equal "x-options-bar"
130
- body('/bar', 'REQUEST_METHOD'=>'PATCH').must_equal "x-patch-bar"
131
- body('/bar', 'REQUEST_METHOD'=>'PUT').must_equal "x-put-bar"
132
- body('/bar', 'REQUEST_METHOD'=>'TRACE').must_equal "x-trace-bar"
133
-
134
- status.must_equal 200
135
- status("/asdfa/asdf").must_equal 404
136
- body("/asdfa/asdf").must_equal "nf"
137
- end
138
-
139
- it "works when freezing the app" do
140
- app.freeze
141
- body.must_equal 'root'
142
- body('/foo').must_equal 'foo'
143
- body('/foo/bar').must_equal 'foobar'
144
- body('/d/go').must_equal 'bazgetgo'
145
- body('/d/go', 'REQUEST_METHOD'=>'POST').must_equal 'bazpostgo'
146
- body('/bar').must_equal "x-get-bar"
147
- body('/bar', 'REQUEST_METHOD'=>'POST').must_equal "x-post-bar"
148
- body('/bar', 'REQUEST_METHOD'=>'DELETE').must_equal "x-delete-bar"
149
- body('/bar', 'REQUEST_METHOD'=>'HEAD').must_equal "x-head-bar"
150
- body('/bar', 'REQUEST_METHOD'=>'OPTIONS').must_equal "x-options-bar"
151
- body('/bar', 'REQUEST_METHOD'=>'PATCH').must_equal "x-patch-bar"
152
- body('/bar', 'REQUEST_METHOD'=>'PUT').must_equal "x-put-bar"
153
- body('/bar', 'REQUEST_METHOD'=>'TRACE').must_equal "x-trace-bar"
154
- if ::Rack::Request.method_defined?("link?")
155
- body('/bar', 'REQUEST_METHOD'=>'LINK').must_equal "x-link-bar"
156
- body('/bar', 'REQUEST_METHOD'=>'UNLINK').must_equal "x-unlink-bar"
157
- end
158
-
159
- status.must_equal 200
160
- status("/asdfa/asdf").must_equal 404
161
-
162
- proc{app.on{}}.must_raise
163
- end
164
- end
@@ -1,40 +0,0 @@
1
- require_relative "../spec_helper"
2
- require 'date'
3
-
4
- describe "class_matchers plugin" do
5
- it "allows class specific regexps with type conversion for class matchers" do
6
- app(:bare) do
7
- plugin :class_matchers
8
- class_matcher(Date, /(\d\d\d\d)-(\d\d)-(\d\d)/){|y,m,d| [Date.new(y.to_i, m.to_i, d.to_i)]}
9
- class_matcher(Array, /(\w+)\/(\w+)/){|a, b| [[a, 1], [b, 2]]}
10
- class_matcher(Hash, /(\d+)\/(\d+)/){|a, b| [{a.to_i=>b.to_i}]}
11
-
12
- route do |r|
13
- r.on Array do |(a,b), (c,d)|
14
- r.get Date do |date|
15
- [date.year, date.month, date.day, a, b, c, d].join('-')
16
- end
17
- r.get Hash do |h|
18
- [h.inspect, a, b, c, d].join('-')
19
- end
20
- r.get Array do |(a1,b1), (c1,d1)|
21
- [a1, b1, c1, d1, a, b, c, d].join('-')
22
- end
23
- r.is do
24
- [a, b, c, d].join('-')
25
- end
26
- "array"
27
- end
28
- ""
29
- end
30
- end
31
-
32
- body("/c").must_equal ''
33
- body("/c/d").must_equal 'c-1-d-2'
34
- body("/c/d/e").must_equal 'array'
35
- body("/c/d/2009-10-a").must_equal 'array'
36
- body("/c/d/2009-10-01").must_equal '2009-10-1-c-1-d-2'
37
- body("/c/d/1/2").must_equal '{1=>2}-c-1-d-2'
38
- body("/c/d/e/f").must_equal 'e-1-f-2-c-1-d-2'
39
- end
40
- end
@@ -1,85 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- require 'logger'
4
-
5
- describe "common_logger plugin" do
6
- def cl_app(&block)
7
- app(:common_logger, &block)
8
- @logger = StringIO.new
9
- @app.plugin :common_logger, @logger
10
- end
11
-
12
- it 'logs requests to given logger/stream' do
13
- cl_app(&:path_info)
14
-
15
- body.must_equal '/'
16
- @logger.rewind
17
- @logger.read.must_match(/\A- - - \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "GET \/ " 200 1 0.\d\d\d\d\n\z/)
18
-
19
- @logger.rewind
20
- @logger.truncate(0)
21
- body('', 'HTTP_X_FORWARDED_FOR'=>'1.1.1.1', 'REMOTE_USER'=>'je', 'REQUEST_METHOD'=>'POST', 'QUERY_STRING'=>'', "HTTP_VERSION"=>'HTTP/1.1').must_equal ''
22
- @logger.rewind
23
- @logger.read.must_match(/\A1\.1\.1\.1 - je \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "POST HTTP\/1.1" 200 - 0.\d\d\d\d\n\z/)
24
-
25
- @logger.rewind
26
- @logger.truncate(0)
27
- body('/b', 'REMOTE_ADDR'=>'1.1.1.2', 'QUERY_STRING'=>'foo=bar', "HTTP_VERSION"=>'HTTP/1.0').must_equal '/b'
28
- @logger.rewind
29
- @logger.read.must_match(/\A1\.1\.1\.2 - - \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "GET \/b\?foo=bar HTTP\/1.0" 200 2 0.\d\d\d\d\n\z/)
30
-
31
- @app.plugin :common_logger, Logger.new(@logger)
32
- @logger.rewind
33
- @logger.truncate(0)
34
- body.must_equal '/'
35
- @logger.rewind
36
- @logger.read.must_match(/\A- - - \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "GET \/ " 200 1 0.\d\d\d\d\n\z/)
37
- end
38
-
39
- it 'skips timer information if not available' do
40
- cl_app do |r|
41
- @_request_timer = nil
42
- r.path_info
43
- end
44
-
45
- body.must_equal '/'
46
- @logger.rewind
47
- @logger.read.must_match(/\A- - - \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "GET \/ " 200 1 -\n\z/)
48
- end
49
-
50
- it 'skips length information if not available' do
51
- cl_app do |r|
52
- r.halt [500, {}, []]
53
- end
54
-
55
- body.must_equal ''
56
- @logger.rewind
57
- @logger.read.must_match(/\A- - - \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "GET \/ " 500 - 0.\d\d\d\d\n\z/)
58
- end
59
-
60
- it 'does not log if an error is raised' do
61
- cl_app do |r|
62
- raise "foo"
63
- end
64
-
65
- begin
66
- body
67
- rescue => e
68
- end
69
- e.must_be_instance_of(RuntimeError)
70
- e.message.must_equal 'foo'
71
- end
72
-
73
- it 'logs errors if used with error_handler' do
74
- cl_app do |r|
75
- raise "foo"
76
- end
77
- @app.plugin :error_handler do |_|
78
- "bad"
79
- end
80
-
81
- body.must_equal 'bad'
82
- @logger.rewind
83
- @logger.read.must_match(/\A- - - \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "GET \/ " 500 3 0.\d\d\d\d\n\z/)
84
- end
85
- end