roda 3.28.0 → 3.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +40 -0
  3. data/README.rdoc +15 -1
  4. data/doc/conventions.rdoc +17 -8
  5. data/doc/release_notes/3.29.0.txt +15 -0
  6. data/doc/release_notes/3.30.0.txt +14 -0
  7. data/doc/release_notes/3.31.0.txt +11 -0
  8. data/doc/release_notes/3.32.0.txt +42 -0
  9. data/doc/release_notes/3.33.0.txt +8 -0
  10. data/lib/roda.rb +3 -0
  11. data/lib/roda/plugins/_symbol_regexp_matchers.rb +2 -0
  12. data/lib/roda/plugins/assets.rb +26 -5
  13. data/lib/roda/plugins/caching.rb +2 -0
  14. data/lib/roda/plugins/common_logger.rb +1 -1
  15. data/lib/roda/plugins/content_security_policy.rb +2 -0
  16. data/lib/roda/plugins/default_headers.rb +2 -0
  17. data/lib/roda/plugins/exception_page.rb +9 -5
  18. data/lib/roda/plugins/hash_matcher.rb +1 -1
  19. data/lib/roda/plugins/header_matchers.rb +5 -1
  20. data/lib/roda/plugins/indifferent_params.rb +4 -0
  21. data/lib/roda/plugins/partials.rb +33 -6
  22. data/lib/roda/plugins/path.rb +42 -15
  23. data/lib/roda/plugins/placeholder_string_matchers.rb +2 -0
  24. data/lib/roda/plugins/public.rb +25 -17
  25. data/lib/roda/plugins/relative_path.rb +73 -0
  26. data/lib/roda/plugins/render.rb +17 -5
  27. data/lib/roda/plugins/render_each.rb +11 -3
  28. data/lib/roda/plugins/run_append_slash.rb +1 -1
  29. data/lib/roda/plugins/symbol_matchers.rb +2 -2
  30. data/lib/roda/version.rb +1 -1
  31. metadata +13 -214
  32. data/Rakefile +0 -108
  33. data/doc/release_notes/1.0.0.txt +0 -329
  34. data/doc/release_notes/1.1.0.txt +0 -226
  35. data/doc/release_notes/1.2.0.txt +0 -406
  36. data/doc/release_notes/1.3.0.txt +0 -109
  37. data/doc/release_notes/2.0.0.txt +0 -75
  38. data/doc/release_notes/2.1.0.txt +0 -124
  39. data/doc/release_notes/2.10.0.txt +0 -27
  40. data/doc/release_notes/2.11.0.txt +0 -70
  41. data/doc/release_notes/2.12.0.txt +0 -40
  42. data/doc/release_notes/2.13.0.txt +0 -10
  43. data/doc/release_notes/2.14.0.txt +0 -44
  44. data/doc/release_notes/2.15.0.txt +0 -53
  45. data/doc/release_notes/2.16.0.txt +0 -48
  46. data/doc/release_notes/2.17.0.txt +0 -62
  47. data/doc/release_notes/2.18.0.txt +0 -69
  48. data/doc/release_notes/2.19.0.txt +0 -30
  49. data/doc/release_notes/2.2.0.txt +0 -97
  50. data/doc/release_notes/2.20.0.txt +0 -5
  51. data/doc/release_notes/2.21.0.txt +0 -17
  52. data/doc/release_notes/2.22.0.txt +0 -41
  53. data/doc/release_notes/2.23.0.txt +0 -29
  54. data/doc/release_notes/2.24.0.txt +0 -65
  55. data/doc/release_notes/2.25.0.txt +0 -14
  56. data/doc/release_notes/2.26.0.txt +0 -13
  57. data/doc/release_notes/2.27.0.txt +0 -56
  58. data/doc/release_notes/2.28.0.txt +0 -17
  59. data/doc/release_notes/2.29.0.txt +0 -156
  60. data/doc/release_notes/2.3.0.txt +0 -109
  61. data/doc/release_notes/2.4.0.txt +0 -55
  62. data/doc/release_notes/2.5.0.txt +0 -23
  63. data/doc/release_notes/2.5.1.txt +0 -4
  64. data/doc/release_notes/2.6.0.txt +0 -21
  65. data/doc/release_notes/2.7.0.txt +0 -75
  66. data/doc/release_notes/2.8.0.txt +0 -44
  67. data/doc/release_notes/2.9.0.txt +0 -6
  68. data/spec/all.rb +0 -1
  69. data/spec/assets/css/app.scss +0 -1
  70. data/spec/assets/css/no_access.css +0 -1
  71. data/spec/assets/css/raw.css +0 -1
  72. data/spec/assets/js/head/app.js +0 -1
  73. data/spec/composition_spec.rb +0 -31
  74. data/spec/define_roda_method_spec.rb +0 -274
  75. data/spec/env_spec.rb +0 -11
  76. data/spec/freeze_spec.rb +0 -37
  77. data/spec/integration_spec.rb +0 -209
  78. data/spec/matchers_spec.rb +0 -832
  79. data/spec/opts_spec.rb +0 -42
  80. data/spec/plugin/_after_hook_spec.rb +0 -19
  81. data/spec/plugin/all_verbs_spec.rb +0 -29
  82. data/spec/plugin/assets_preloading_spec.rb +0 -98
  83. data/spec/plugin/assets_spec.rb +0 -745
  84. data/spec/plugin/backtracking_array_spec.rb +0 -42
  85. data/spec/plugin/branch_locals_spec.rb +0 -106
  86. data/spec/plugin/caching_spec.rb +0 -337
  87. data/spec/plugin/chunked_spec.rb +0 -201
  88. data/spec/plugin/class_level_routing_spec.rb +0 -164
  89. data/spec/plugin/class_matchers_spec.rb +0 -40
  90. data/spec/plugin/common_logger_spec.rb +0 -85
  91. data/spec/plugin/content_for_spec.rb +0 -162
  92. data/spec/plugin/content_security_policy_spec.rb +0 -175
  93. data/spec/plugin/cookies_spec.rb +0 -51
  94. data/spec/plugin/csrf_spec.rb +0 -111
  95. data/spec/plugin/default_headers_spec.rb +0 -82
  96. data/spec/plugin/default_status_spec.rb +0 -95
  97. data/spec/plugin/delay_build_spec.rb +0 -23
  98. data/spec/plugin/delegate_spec.rb +0 -23
  99. data/spec/plugin/delete_empty_headers_spec.rb +0 -27
  100. data/spec/plugin/direct_call_spec.rb +0 -28
  101. data/spec/plugin/disallow_file_uploads_spec.rb +0 -25
  102. data/spec/plugin/drop_body_spec.rb +0 -24
  103. data/spec/plugin/early_hints_spec.rb +0 -19
  104. data/spec/plugin/empty_root_spec.rb +0 -14
  105. data/spec/plugin/environments_spec.rb +0 -42
  106. data/spec/plugin/error_email_spec.rb +0 -97
  107. data/spec/plugin/error_handler_spec.rb +0 -216
  108. data/spec/plugin/error_mail_spec.rb +0 -93
  109. data/spec/plugin/exception_page_spec.rb +0 -168
  110. data/spec/plugin/flash_spec.rb +0 -121
  111. data/spec/plugin/h_spec.rb +0 -11
  112. data/spec/plugin/halt_spec.rb +0 -119
  113. data/spec/plugin/hash_matcher_spec.rb +0 -27
  114. data/spec/plugin/hash_routes_spec.rb +0 -535
  115. data/spec/plugin/head_spec.rb +0 -52
  116. data/spec/plugin/header_matchers_spec.rb +0 -98
  117. data/spec/plugin/heartbeat_spec.rb +0 -74
  118. data/spec/plugin/hooks_spec.rb +0 -152
  119. data/spec/plugin/indifferent_params_spec.rb +0 -14
  120. data/spec/plugin/json_parser_spec.rb +0 -141
  121. data/spec/plugin/json_spec.rb +0 -83
  122. data/spec/plugin/mail_processor_spec.rb +0 -451
  123. data/spec/plugin/mailer_spec.rb +0 -282
  124. data/spec/plugin/match_affix_spec.rb +0 -43
  125. data/spec/plugin/match_hook_spec.rb +0 -79
  126. data/spec/plugin/middleware_spec.rb +0 -237
  127. data/spec/plugin/middleware_stack_spec.rb +0 -81
  128. data/spec/plugin/module_include_spec.rb +0 -48
  129. data/spec/plugin/multi_route_spec.rb +0 -268
  130. data/spec/plugin/multi_run_spec.rb +0 -87
  131. data/spec/plugin/multi_view_spec.rb +0 -50
  132. data/spec/plugin/multibyte_string_matcher_spec.rb +0 -44
  133. data/spec/plugin/named_templates_spec.rb +0 -96
  134. data/spec/plugin/not_allowed_spec.rb +0 -69
  135. data/spec/plugin/not_found_spec.rb +0 -128
  136. data/spec/plugin/optimized_string_matchers_spec.rb +0 -43
  137. data/spec/plugin/padrino_render_spec.rb +0 -34
  138. data/spec/plugin/param_matchers_spec.rb +0 -69
  139. data/spec/plugin/params_capturing_spec.rb +0 -33
  140. data/spec/plugin/partials_spec.rb +0 -43
  141. data/spec/plugin/pass_spec.rb +0 -29
  142. data/spec/plugin/path_matchers_spec.rb +0 -42
  143. data/spec/plugin/path_rewriter_spec.rb +0 -45
  144. data/spec/plugin/path_spec.rb +0 -222
  145. data/spec/plugin/placeholder_string_matchers_spec.rb +0 -126
  146. data/spec/plugin/precompile_templates_spec.rb +0 -61
  147. data/spec/plugin/public_spec.rb +0 -85
  148. data/spec/plugin/render_each_spec.rb +0 -82
  149. data/spec/plugin/render_locals_spec.rb +0 -114
  150. data/spec/plugin/render_spec.rb +0 -912
  151. data/spec/plugin/request_aref_spec.rb +0 -51
  152. data/spec/plugin/request_headers_spec.rb +0 -39
  153. data/spec/plugin/response_request_spec.rb +0 -43
  154. data/spec/plugin/route_block_args_spec.rb +0 -86
  155. data/spec/plugin/route_csrf_spec.rb +0 -305
  156. data/spec/plugin/run_append_slash_spec.rb +0 -77
  157. data/spec/plugin/run_handler_spec.rb +0 -53
  158. data/spec/plugin/sessions_spec.rb +0 -452
  159. data/spec/plugin/shared_vars_spec.rb +0 -45
  160. data/spec/plugin/sinatra_helpers_spec.rb +0 -537
  161. data/spec/plugin/slash_path_empty_spec.rb +0 -22
  162. data/spec/plugin/static_routing_spec.rb +0 -192
  163. data/spec/plugin/static_spec.rb +0 -30
  164. data/spec/plugin/status_303_spec.rb +0 -28
  165. data/spec/plugin/status_handler_spec.rb +0 -158
  166. data/spec/plugin/streaming_spec.rb +0 -246
  167. data/spec/plugin/strip_path_prefix_spec.rb +0 -24
  168. data/spec/plugin/symbol_matchers_spec.rb +0 -51
  169. data/spec/plugin/symbol_status_spec.rb +0 -25
  170. data/spec/plugin/symbol_views_spec.rb +0 -32
  171. data/spec/plugin/timestamp_public_spec.rb +0 -85
  172. data/spec/plugin/type_routing_spec.rb +0 -348
  173. data/spec/plugin/typecast_params_spec.rb +0 -1370
  174. data/spec/plugin/unescape_path_spec.rb +0 -22
  175. data/spec/plugin/view_options_spec.rb +0 -170
  176. data/spec/plugin_spec.rb +0 -71
  177. data/spec/redirect_spec.rb +0 -41
  178. data/spec/request_spec.rb +0 -97
  179. data/spec/response_spec.rb +0 -199
  180. data/spec/route_spec.rb +0 -39
  181. data/spec/session_middleware_spec.rb +0 -129
  182. data/spec/session_spec.rb +0 -37
  183. data/spec/spec_helper.rb +0 -137
  184. data/spec/version_spec.rb +0 -14
  185. data/spec/views/_test.erb +0 -1
  186. data/spec/views/a.erb +0 -1
  187. data/spec/views/a.rdoc +0 -2
  188. data/spec/views/about.erb +0 -1
  189. data/spec/views/about.str +0 -1
  190. data/spec/views/about/_test.css.gz +0 -0
  191. data/spec/views/about/_test.erb +0 -1
  192. data/spec/views/about/_test.erb.gz +0 -0
  193. data/spec/views/about/comp_test.erb +0 -1
  194. data/spec/views/b.erb +0 -1
  195. data/spec/views/c.erb +0 -1
  196. data/spec/views/comp_layout.erb +0 -1
  197. data/spec/views/comp_test.erb +0 -1
  198. data/spec/views/content-yield.erb +0 -1
  199. data/spec/views/each.str +0 -1
  200. data/spec/views/home.erb +0 -2
  201. data/spec/views/home.str +0 -2
  202. data/spec/views/iv.erb +0 -1
  203. data/spec/views/layout-alternative.erb +0 -2
  204. data/spec/views/layout-yield.erb +0 -3
  205. data/spec/views/layout.erb +0 -2
  206. data/spec/views/layout.str +0 -2
  207. data/spec/views/multiple-layout.erb +0 -1
  208. data/spec/views/multiple.erb +0 -1
@@ -1,282 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- begin
4
- require 'mail'
5
- rescue LoadError
6
- warn "mail not installed, skipping mail plugin test"
7
- else
8
- Mail.defaults do
9
- delivery_method :test
10
- end
11
-
12
- describe "mailer plugin" do
13
- def deliveries
14
- Mail::TestMailer.deliveries
15
- end
16
-
17
- after do
18
- deliveries.clear
19
- end
20
-
21
- setup_email = lambda do
22
- from "f@example.com"
23
- to "t@example.com"
24
- subject 's'
25
- end
26
-
27
- it "supports sending emails via the routing tree" do
28
- app(:mailer) do |r|
29
- r.mail do
30
- instance_exec(&setup_email)
31
- cc "c@example.com"
32
- bcc "b@example.com"
33
- response['X-Foo'] = 'Bar'
34
- "b"
35
- end
36
- end
37
-
38
- m = app.mail('/foo')
39
- deliveries.must_equal []
40
- m.from.must_equal ['f@example.com']
41
- m.to.must_equal ['t@example.com']
42
- m.cc.must_equal ['c@example.com']
43
- m.bcc.must_equal ['b@example.com']
44
- m.subject.must_equal 's'
45
- m.body.must_be :==, 'b'
46
- m.header['X-Foo'].to_s.must_equal 'Bar'
47
-
48
- m.deliver!
49
- deliveries.must_equal [m]
50
-
51
- deliveries.clear
52
- m = app.sendmail('/foo')
53
- deliveries.must_equal [m]
54
- m.from.must_equal ['f@example.com']
55
- m.to.must_equal ['t@example.com']
56
- m.cc.must_equal ['c@example.com']
57
- m.bcc.must_equal ['b@example.com']
58
- m.subject.must_equal 's'
59
- m.body.must_be :==, 'b'
60
- m.header['X-Foo'].to_s.must_equal 'Bar'
61
- end
62
-
63
- it "supports arguments to mail/sendmail methods, yielding them to the route blocks" do
64
- app(:mailer) do |r|
65
- instance_exec(&setup_email)
66
- r.mail "foo" do |*args|
67
- "foo#{args.inspect}"
68
- end
69
- r.mail :d do |*args|
70
- args.inspect
71
- end
72
- end
73
-
74
- app.mail('/foo', 1, 2).body.must_be :==, 'foo[1, 2]'
75
- app.sendmail('/bar', 1, 2).body.must_be :==, '["bar", 1, 2]'
76
- end
77
-
78
- it "supports no_mail! method for skipping mailing" do
79
- app(:mailer) do |r|
80
- instance_exec(&setup_email)
81
- r.mail "foo" do |*args|
82
- no_mail!
83
- raise
84
- end
85
- end
86
-
87
- app.mail('/foo', 1, 2).must_be_nil
88
- app.sendmail('/foo', 1, 2).must_be_nil
89
- deliveries.must_equal []
90
- end
91
-
92
- it "supports attachments" do
93
- app(:mailer) do |r|
94
- r.mail do
95
- instance_exec(&setup_email)
96
- add_file __FILE__
97
- end
98
- end
99
-
100
- m = app.mail('foo')
101
- m.attachments.length.must_equal 1
102
- m.attachments.first.content_type.must_match(/mailer_spec\.rb/)
103
- m.content_type.must_match(/\Amultipart\/mixed/)
104
- m.parts.length.must_equal 1
105
- m.parts.first.body.decoded.gsub("\r\n", "\n").must_equal File.read(__FILE__)
106
- end
107
-
108
- it "supports attachments with blocks" do
109
- app(:mailer) do |r|
110
- r.mail do
111
- instance_exec(&setup_email)
112
- add_file __FILE__ do
113
- response.mail.attachments.last.content_type = 'text/foo'
114
- end
115
- end
116
- end
117
-
118
- m = app.mail('foo')
119
- m.attachments.length.must_equal 1
120
- m.attachments.first.content_type.must_equal 'text/foo'
121
- m.content_type.must_match(/\Amultipart\/mixed/)
122
- m.parts.length.must_equal 1
123
- m.parts.first.body.decoded.gsub("\r\n", "\n").must_equal File.read(__FILE__)
124
- end
125
-
126
- it "supports plain-text attachments with an email body" do
127
- app(:mailer) do |r|
128
- r.mail do
129
- instance_exec(&setup_email)
130
- add_file :filename=>'a.txt', :content=>'b'
131
- 'c'
132
- end
133
- end
134
-
135
- m = app.mail('foo')
136
- m.parts.length.must_equal 2
137
- m.parts.first.content_type.must_match(/text\/plain/)
138
- m.parts.first.body.must_be :==, 'c'
139
- m.parts.last.content_type.must_match(/text\/plain/)
140
- m.parts.last.body.must_be :==, 'b'
141
- m.attachments.length.must_equal 1
142
- m.attachments.first.content_type.must_match(/a\.txt/)
143
- m.content_type.must_match(/\Amultipart\/mixed/)
144
- end
145
-
146
- it "supports regular web requests in same application" do
147
- app(:mailer) do |r|
148
- r.get "foo", :bar do |bar|
149
- "foo#{bar}"
150
- end
151
- r.mail "bar" do
152
- instance_exec(&setup_email)
153
- "b"
154
- end
155
- end
156
-
157
- body("/foo/baz", 'rack.input'=>StringIO.new).must_equal 'foobaz'
158
- app.mail('/bar').body.must_be :==, 'b'
159
- end
160
-
161
- it "supports multipart email using text_part/html_pat" do
162
- app(:mailer) do |r|
163
- r.mail do
164
- instance_exec(&setup_email)
165
- text_part "t"
166
- html_part "h"
167
- end
168
- end
169
-
170
- m = app.mail('/foo')
171
- m.text_part.body.must_be :==, 't'
172
- m.html_part.body.must_be :==, 'h'
173
- m.content_type.must_match(/\Amultipart\/alternative/)
174
- end
175
-
176
- it "supports setting arbitrary email headers for multipart emails" do
177
- app(:mailer) do |r|
178
- r.mail do
179
- instance_exec(&setup_email)
180
- text_part "t", "X-Text"=>'T'
181
- html_part "h", "X-HTML"=>'H'
182
- end
183
- end
184
-
185
- m = app.mail('/foo')
186
- m.text_part.body.must_be :==, 't'
187
- m.text_part.header['X-Text'].to_s.must_equal 'T'
188
- m.html_part.body.must_be :==, 'h'
189
- m.html_part.header['X-HTML'].to_s.must_equal 'H'
190
- m.content_type.must_match(/\Amultipart\/alternative/)
191
- end
192
-
193
- it "raises error if mail object is not returned" do
194
- app(:mailer){}
195
- proc{app.mail('/')}.must_raise(Roda::RodaPlugins::Mailer::Error)
196
- end
197
-
198
- it "does not raise an error when using an explicitly empty body" do
199
- app(:mailer){""}
200
- app.mail('/')
201
- end
202
-
203
- it "supports setting the default content-type for emails when loading the plugin" do
204
- app(:bare) do
205
- plugin :mailer, :content_type=>'text/html'
206
- route{""}
207
- end
208
- app.mail('/').content_type.must_match(/\Atext\/html/)
209
- end
210
-
211
- it "supports loading the plugin multiple times" do
212
- app(:bare) do
213
- plugin :mailer, :content_type=>'text/html'
214
- plugin :mailer
215
- route{""}
216
- end
217
- app.mail('/').content_type.must_match(/\Atext\/html/)
218
- end
219
-
220
- it "supports manually overridding the default content-type for emails" do
221
- app(:bare) do
222
- plugin :mailer, :content_type=>'text/html'
223
- route do
224
- response['Content-Type'] = 'text/foo'
225
- ""
226
- end
227
- end
228
- app.mail('/').content_type.must_match(/\Atext\/foo/)
229
- end
230
-
231
- it "supports setting the default content type when attachments are used" do
232
- app(:bare) do
233
- plugin :mailer, :content_type=>'text/html'
234
- route do
235
- add_file 'spec/assets/css/raw.css'
236
- "a"
237
- end
238
- end
239
- m = app.mail('/')
240
- m.content_type.must_match(/\Amultipart\/mixed/)
241
- m.parts.length.must_equal 2
242
- m.parts.first.content_type.must_match(/\Atext\/html/)
243
- m.parts.first.body.must_be :==, "a"
244
- m.parts.last.content_type.must_match(/\Atext\/css/)
245
- m.parts.last.body.decoded.gsub("\r\n", "\n").must_equal File.read('spec/assets/css/raw.css')
246
- end
247
-
248
- it "works with route_block_args plugin" do
249
- app(:bare) do
250
- plugin :mailer
251
- plugin :route_block_args do
252
- [request.path]
253
- end
254
- route do |path|
255
- path
256
- end
257
- end
258
- app.mail('/').body.decoded.must_equal '/'
259
- app.mail('/foo').body.decoded.must_equal '/foo'
260
- end
261
-
262
- it "works with hooks plugin" do
263
- x = []
264
- app(:bare) do
265
- plugin :mailer
266
- plugin :hooks
267
- before do
268
- x << 1
269
- end
270
- after do
271
- x << 2
272
- end
273
- route do
274
- x << 3
275
- ''
276
- end
277
- end
278
- app.mail('/').body.decoded.must_equal ''
279
- x.must_equal [1, 3, 2]
280
- end
281
- end
282
- end
@@ -1,43 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "match_affix plugin" do
4
- it "allows changing the match prefix/suffix" do
5
- app(:bare) do
6
- plugin :match_affix, "", /(\/|\z)/
7
-
8
- route do |r|
9
- r.on "/albums" do |b|
10
- r.on "b/:id" do |id, s|
11
- "b-#{b}-#{id}-#{s.inspect}"
12
- end
13
-
14
- "albums-#{b}"
15
- end
16
- end
17
- end
18
-
19
- body("/albums/a/1").must_equal 'albums-/'
20
- body("/albums/b/1").must_equal 'b-/-1-""'
21
- end
22
-
23
- it "handles extra trailing slash only" do
24
- app(:bare) do
25
- plugin :match_affix, nil, /(?:\/\z|(?=\/|\z))/
26
-
27
- route do |r|
28
- r.on "albums" do
29
- r.on "b" do
30
- "albums/b:#{r.remaining_path}"
31
- end
32
-
33
- "albums:#{r.remaining_path}"
34
- end
35
- end
36
- end
37
-
38
- body("/albums/a").must_equal 'albums:/a'
39
- body("/albums/a/").must_equal 'albums:/a/'
40
- body("/albums/b").must_equal 'albums/b:'
41
- body("/albums/b/").must_equal 'albums/b:'
42
- end
43
- end
@@ -1,79 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "match hook plugin" do
4
- it "matches verbs" do
5
- matches = []
6
- app(:bare) do
7
- plugin :match_hook
8
- match_hook do
9
- matches << [request.matched_path, request.remaining_path]
10
- end
11
- route do |r|
12
- r.on "foo" do
13
- r.on "bar" do
14
- r.get "baz" do
15
- "fbb"
16
- end
17
- "fb"
18
- end
19
- "f"
20
- end
21
-
22
- r.get "bar" do
23
- "b"
24
- end
25
-
26
- r.root do
27
- "r"
28
- end
29
-
30
- "n"
31
- end
32
- end
33
-
34
- body("/foo").must_equal 'f'
35
- matches.must_equal [["/foo", ""]]
36
-
37
- matches.clear
38
- body("/foo/bar").must_equal 'fb'
39
- matches.must_equal [["/foo", "/bar"], ["/foo/bar", ""]]
40
-
41
- matches.clear
42
- body("/foo/bar/baz").must_equal 'fbb'
43
- matches.must_equal [["/foo", "/bar/baz"], ["/foo/bar", "/baz"], ["/foo/bar/baz", ""]]
44
-
45
- matches.clear
46
- body("/bar").must_equal 'b'
47
- matches.must_equal [["/bar", ""]]
48
-
49
- matches.clear
50
- body.must_equal 'r'
51
- matches.must_equal [["", "/"]]
52
-
53
- matches.clear
54
- body('/x').must_equal 'n'
55
- matches.must_be_empty
56
-
57
- matches.clear
58
- body("/foo/baz").must_equal 'f'
59
- matches.must_equal [["/foo", "/baz"]]
60
-
61
- matches.clear
62
- body("/foo/bar/bar").must_equal 'fb'
63
- matches.must_equal [["/foo", "/bar/bar"], ["/foo/bar", "/bar"]]
64
-
65
- app.match_hook{matches << :x }
66
-
67
- matches.clear
68
- body("/foo/bar/baz").must_equal 'fbb'
69
- matches.must_equal [["/foo", "/bar/baz"], :x, ["/foo/bar", "/baz"], :x, ["/foo/bar/baz", ""], :x]
70
-
71
- app.freeze
72
-
73
- matches.clear
74
- body("/foo/bar/baz").must_equal 'fbb'
75
- matches.must_equal [["/foo", "/bar/baz"], :x, ["/foo/bar", "/baz"], :x, ["/foo/bar/baz", ""], :x]
76
-
77
- app.opts[:match_hooks].must_be :frozen?
78
- end
79
- end
@@ -1,237 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "middleware plugin" do
4
- [false, true].each do |def_call|
5
- meth = def_call ? :deprecated : :it
6
- send meth, "turns Roda app into middlware" do
7
- a2 = app(:bare) do
8
- plugin :middleware
9
-
10
- if def_call
11
- def call
12
- super
13
- end
14
- end
15
-
16
- route do |r|
17
- r.is "a" do
18
- "a2"
19
- end
20
- r.post "b" do
21
- "b2"
22
- end
23
- end
24
- end
25
-
26
- a3 = app(:bare) do
27
- plugin :middleware
28
-
29
- route do |r|
30
- r.get "a" do
31
- "a3"
32
- end
33
- r.get "b" do
34
- "b3"
35
- end
36
- end
37
- end
38
-
39
- app(:bare) do
40
- use a3
41
- use a2
42
-
43
- route do |r|
44
- r.is "a" do
45
- "a1"
46
- end
47
- r.is "b" do
48
- "b1"
49
- end
50
- end
51
- end
52
-
53
- body('/a').must_equal 'a3'
54
- body('/b').must_equal 'b3'
55
- body('/a', 'REQUEST_METHOD'=>'POST').must_equal 'a2'
56
- body('/b', 'REQUEST_METHOD'=>'POST').must_equal 'b2'
57
- body('/a', 'REQUEST_METHOD'=>'PATCH').must_equal 'a2'
58
- body('/b', 'REQUEST_METHOD'=>'PATCH').must_equal 'b1'
59
- end
60
- end
61
-
62
- it "makes it still possible to use the Roda app normally" do
63
- app(:middleware) do
64
- "a"
65
- end
66
- body.must_equal 'a'
67
- end
68
-
69
- deprecated "makes it still possible to use the Roda app normally when #call is overwritten" do
70
- app(:bare) do
71
- plugin :middleware
72
- def call
73
- super
74
- end
75
-
76
- route do
77
- "a"
78
- end
79
- end
80
- app
81
- body.must_equal 'a'
82
- end
83
-
84
- it "makes middleware always use a subclass of the app" do
85
- app(:middleware) do |r|
86
- r.get{opts[:a]}
87
- end
88
- app.opts[:a] = 'a'
89
- a = app
90
- app(:bare) do
91
- use a
92
- route{}
93
- end
94
- body.must_equal 'a'
95
- a.opts[:a] = 'b'
96
- body.must_equal 'a'
97
- end
98
-
99
- it "should raise error if attempting to use options for Roda application that does not support configurable middleware" do
100
- a1 = app(:bare){plugin :middleware}
101
- proc{app(:bare){use a1, :foo; route{}; build_rack_app}}.must_raise Roda::RodaError
102
- proc{app(:bare){use(a1){}; route{}; build_rack_app}}.must_raise Roda::RodaError
103
- end
104
-
105
- it "supports configuring middleware via a block" do
106
- a1 = app(:bare) do
107
- plugin :middleware do |mid, *args, &block|
108
- mid.opts[:a] = args.concat(block.call(:quux)).join(' ')
109
- end
110
- opts[:a] = 'a1'
111
-
112
- route do |r|
113
- r.is 'a' do opts[:a] end
114
- end
115
- end
116
-
117
- body('/a').must_equal 'a1'
118
-
119
- app(:bare) do
120
- use a1, :foo, :bar do |baz|
121
- [baz, :a1]
122
- end
123
-
124
- route do
125
- 'b1'
126
- end
127
- end
128
-
129
- body.must_equal 'b1'
130
- body('/a').must_equal 'foo bar quux a1'
131
-
132
- @app = a1
133
- body('/a').must_equal 'a1'
134
- end
135
-
136
- it "is compatible with the multi_route plugin" do
137
- app(:bare) do
138
- plugin :multi_route
139
- plugin :middleware
140
-
141
- route("a") do |r|
142
- r.is "b" do
143
- "ab"
144
- end
145
- end
146
-
147
- route do |r|
148
- r.multi_route
149
- end
150
- end
151
-
152
- body('/a/b').must_equal 'ab'
153
- end
154
-
155
- it "uses the app's middleware if :include_middleware option is given" do
156
- mid = Struct.new(:app) do
157
- def call(env)
158
- env['foo'] = 'bar'
159
- app.call(env)
160
- end
161
- end
162
- app(:bare) do
163
- plugin :middleware, :include_middleware=>true
164
- use mid
165
- route{}
166
- end
167
- mid2 = app
168
- app(:bare) do
169
- use mid2
170
- route{env['foo']}
171
- end
172
- body.must_equal 'bar'
173
- end
174
-
175
- it "calls :handle_result option with env and response" do
176
- app(:bare) do
177
- plugin :middleware, :handle_result=>(proc do |env, res|
178
- res[2] << env['foo']
179
- end)
180
- route{}
181
- end
182
- mid2 = app
183
- app(:bare) do
184
- use mid2
185
- route{env['foo'] = 'bar'; 'baz'}
186
- end
187
- body.must_equal 'bazbar'
188
- end
189
-
190
- it "works with the route_block_args block when loaded before" do
191
- app(:bare) do
192
- plugin :middleware
193
- plugin :route_block_args do
194
- [request.path, response]
195
- end
196
-
197
- route do |path, res|
198
- request.get 'a' do
199
- res.write(path + '2')
200
- end
201
- end
202
- end
203
- a = app
204
-
205
- app(:bare) do
206
- use a
207
- route{|r| 'b'}
208
- end
209
-
210
- body('/a').must_equal '/a2'
211
- body('/x').must_equal 'b'
212
- end
213
-
214
- it "works with the route_block_args block when loaded after" do
215
- app(:bare) do
216
- plugin :route_block_args do
217
- [request.path, response]
218
- end
219
- plugin :middleware
220
-
221
- route do |path, res|
222
- request.get 'a' do
223
- res.write(path + '2')
224
- end
225
- end
226
- end
227
- a = app
228
-
229
- app(:bare) do
230
- use a
231
- route{|r| 'b'}
232
- end
233
-
234
- body('/a').must_equal '/a2'
235
- body('/x').must_equal 'b'
236
- end
237
- end