roda 3.28.0 → 3.29.0

Sign up to get free protection for your applications and to get access to all the features.
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,24 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "strip_path_prefix plugin" do
4
- it "strips path prefix when expanding paths" do
5
- app(:bare){}
6
- abs_dir = app.expand_path('spec')
7
-
8
- app.plugin :strip_path_prefix
9
- app.expand_path('spec').must_equal 'spec'
10
- File.expand_path(app.expand_path('spec'), Dir.pwd).must_equal abs_dir
11
-
12
- app.expand_path('/foo').must_equal '/foo'
13
- app.expand_path('bar', '/foo').must_equal '/foo/bar'
14
-
15
- app.opts[:root] = '/foo'
16
- app.expand_path('bar').must_equal '/foo/bar'
17
- app.plugin :strip_path_prefix, '/foo'
18
- app.expand_path('bar').must_equal 'bar'
19
-
20
- app.opts[:root] = '/foo/bar'
21
- app.expand_path('baz').must_equal 'bar/baz'
22
- end
23
- end
24
-
@@ -1,51 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "symbol_matchers plugin" do
4
- it "allows symbol specific regexps for symbol matchers" do
5
- app(:bare) do
6
- plugin :symbol_matchers
7
- symbol_matcher(:f, /(f+)/)
8
-
9
- route do |r|
10
- r.is :d do |d|
11
- "d#{d}"
12
- end
13
-
14
- r.is "thing2", :thing do |d|
15
- "thing2#{d}"
16
- end
17
-
18
- r.is :f do |f|
19
- "f#{f}"
20
- end
21
-
22
- r.is 'q', :rest do |rest|
23
- "rest#{rest}"
24
- end
25
-
26
- r.is :w do |w|
27
- "w#{w}"
28
- end
29
-
30
- r.is :d, :w, :f do |d, w, f|
31
- "dwf#{d}#{w}#{f}"
32
- end
33
- end
34
- end
35
-
36
- status.must_equal 404
37
- body("/1").must_equal 'd1'
38
- body("/11232135").must_equal 'd11232135'
39
- body("/a").must_equal 'wa'
40
- body("/1az0").must_equal 'w1az0'
41
- body("/f").must_equal 'ff'
42
- body("/ffffffffffffffff").must_equal 'fffffffffffffffff'
43
- status("/-").must_equal 404
44
- body("/1/1a/f").must_equal 'dwf11af'
45
- body("/12/1azy/fffff").must_equal 'dwf121azyfffff'
46
- status("/1/f/a").must_equal 404
47
- body("/q/a/b/c/d//f/g").must_equal 'resta/b/c/d//f/g'
48
- body('/q/').must_equal 'rest'
49
- body('/thing2/q').must_equal 'thing2q'
50
- end
51
- end
@@ -1,25 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "symbol_status plugin" do
4
- it "accepts a symbol" do
5
- app(:symbol_status) do |r|
6
- r.on do
7
- response.status = :unauthorized
8
- nil
9
- end
10
- end
11
-
12
- status.must_equal 401
13
- end
14
-
15
- it "accepts a fixnum" do
16
- app(:symbol_status) do |r|
17
- r.on do
18
- response.status = 204
19
- nil
20
- end
21
- end
22
-
23
- status.must_equal 204
24
- end
25
- end
@@ -1,32 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "symbol_views plugin" do
4
- before do
5
- app(:bare) do
6
- plugin :symbol_views
7
-
8
- def view(s)
9
- "v#{s}"
10
- end
11
-
12
- route do |r|
13
- r.root do
14
- :sym
15
- end
16
-
17
- r.is "string" do
18
- 'string'
19
- end
20
- end
21
- end
22
- end
23
-
24
- it "should call view with the symbol" do
25
- body.must_equal "vsym"
26
- end
27
-
28
- it "should not affect other return types" do
29
- body("/string").must_equal 'string'
30
- body("/foo").must_equal ''
31
- end
32
- end
@@ -1,85 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "timestamp_public plugin" do
4
- it "adds r.timestamp_public for serving static files from timestamp_public folder" do
5
- app(:bare) do
6
- plugin :timestamp_public, :root=>'spec/views'
7
-
8
- route do |r|
9
- r.timestamp_public
10
- end
11
- end
12
-
13
- status("/about/_test.erb\0").must_equal 404
14
- status("/about/_test.erb").must_equal 404
15
- status("/static/a/about/_test.erb").must_equal 404
16
- status("/static/1/about/_test.erb\0").must_equal 404
17
- body("/static/1/about/_test.erb").must_equal File.read('spec/views/about/_test.erb')
18
- end
19
-
20
- it "adds r.timestamp_public for serving static files from timestamp_public folder" do
21
- app(:bare) do
22
- plugin :timestamp_public, :root=>'spec/views', :prefix=>'foo'
23
-
24
- route do |r|
25
- r.timestamp_public
26
- end
27
- end
28
-
29
- body("/foo/1/about/_test.erb").must_equal File.read('spec/views/about/_test.erb')
30
- end
31
-
32
- it "adds r.timestamp_public for serving static files from timestamp_public folder" do
33
- app(:bare) do
34
- plugin :timestamp_public, :root=>'spec/plugin'
35
-
36
- route do |r|
37
- r.timestamp_public
38
- timestamp_path('../views/about/_test.erb')
39
- end
40
- end
41
-
42
- mtime = File.mtime('spec/views/about/_test.erb')
43
- body.must_equal "/static/#{sprintf("%i%06i", mtime.to_i, mtime.usec)}/../views/about/_test.erb"
44
- status("/static/1/../views/about/_test.erb").must_equal 404
45
- end
46
-
47
- it "respects the application's :root option" do
48
- app(:bare) do
49
- opts[:root] = File.expand_path('../../', __FILE__)
50
- plugin :timestamp_public, :root=>'views'
51
-
52
- route do |r|
53
- r.timestamp_public
54
- end
55
- end
56
-
57
- body('/static/1/about/_test.erb').must_equal File.read('spec/views/about/_test.erb')
58
- end
59
-
60
- it "handles serving gzip files in gzip mode if client supports gzip" do
61
- app(:bare) do
62
- plugin :timestamp_public, :root=>'spec/views', :gzip=>true
63
-
64
- route do |r|
65
- r.timestamp_public
66
- end
67
- end
68
-
69
- body('/static/1/about/_test.erb').must_equal File.read('spec/views/about/_test.erb')
70
- header('Content-Encoding', '/about/_test.erb').must_be_nil
71
-
72
- body('/static/1/about.erb').must_equal File.read('spec/views/about.erb')
73
- header('Content-Encoding', '/about.erb').must_be_nil
74
-
75
- body('/static/1/about/_test.erb', 'HTTP_ACCEPT_ENCODING'=>'deflate, gzip').must_equal File.binread('spec/views/about/_test.erb.gz')
76
- h = req('/static/1/about/_test.erb', 'HTTP_ACCEPT_ENCODING'=>'deflate, gzip')[1]
77
- h['Content-Encoding'].must_equal 'gzip'
78
- h['Content-Type'].must_equal 'text/plain'
79
-
80
- body('/static/1/about/_test.css', 'HTTP_ACCEPT_ENCODING'=>'deflate, gzip').must_equal File.binread('spec/views/about/_test.css.gz')
81
- h = req('/static/1/about/_test.css', 'HTTP_ACCEPT_ENCODING'=>'deflate, gzip')[1]
82
- h['Content-Encoding'].must_equal 'gzip'
83
- h['Content-Type'].must_equal 'text/css'
84
- end
85
- end
@@ -1,348 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../spec_helper"
4
-
5
- describe "type_routing plugin" do
6
- before do
7
- app(:type_routing) do |r|
8
- r.is 'a' do
9
- r.html{ "HTML: #{r.requested_type}" }
10
- r.json{ "JSON: #{r.requested_type}" }
11
- r.xml{ "XML: #{r.requested_type}" }
12
- "No match"
13
- end
14
- end
15
- end
16
-
17
- it "uses the file extension in the path" do
18
- body('/a').must_equal 'HTML: html'
19
- header('Content-Type', '/a').must_equal 'text/html'
20
-
21
- body('/a.html').must_equal 'HTML: html'
22
- header('Content-Type', '/a.html').must_equal 'text/html'
23
-
24
- body('/a.json').must_equal 'JSON: json'
25
- header('Content-Type', '/a.json').must_equal 'application/json'
26
-
27
- body('/a.xml').must_equal 'XML: xml'
28
- header('Content-Type', '/a.xml').must_equal 'application/xml'
29
-
30
- status('/a.yadda').must_equal 404
31
- end
32
-
33
- it "uses the Accept header value" do
34
- body('/a', 'HTTP_ACCEPT' => 'text/html').must_equal 'HTML: html'
35
- header('Content-Type', '/a', 'HTTP_ACCEPT' => 'text/html').must_equal 'text/html'
36
-
37
- body('/a', 'HTTP_ACCEPT' => 'application/json').must_equal 'JSON: json'
38
- header('Content-Type', '/a', 'HTTP_ACCEPT' => 'application/json').must_equal 'application/json'
39
-
40
- body('/a', 'HTTP_ACCEPT' => 'application/xml').must_equal 'XML: xml'
41
- header('Content-Type', '/a', 'HTTP_ACCEPT' => 'application/xml').must_equal 'application/xml'
42
-
43
- body('/a', 'HTTP_ACCEPT' => 'some/thing').must_equal 'HTML: html'
44
- header('Content-Type', '/a', 'HTTP_ACCEPT' => 'some/thing').must_equal 'text/html'
45
- end
46
-
47
- it "favors the file extension over the Accept header" do
48
- body('/a.json', 'HTTP_ACCEPT' => 'text/html').must_equal 'JSON: json'
49
- body('/a.xml', 'HTTP_ACCEPT' => 'application/json').must_equal 'XML: xml'
50
- body('/a.html', 'HTTP_ACCEPT' => 'application/xml').must_equal 'HTML: html'
51
- end
52
-
53
- it "works correctly in sub apps" do
54
- sup_app = app
55
- @app = Class.new(sup_app)
56
- app.route do |r|
57
- r.run(sup_app)
58
- end
59
-
60
- body('/a', 'HTTP_ACCEPT' => 'text/html').must_equal 'HTML: html'
61
- body('/a.json', 'HTTP_ACCEPT' => 'text/html').must_equal 'JSON: json'
62
- body('/a.xml', 'HTTP_ACCEPT' => 'application/json').must_equal 'XML: xml'
63
- body('/a.html', 'HTTP_ACCEPT' => 'application/xml').must_equal 'HTML: html'
64
- end
65
-
66
- it "works correctly in sub apps when sub app also handles extensions on empty paths" do
67
- sup_app = app
68
- @app = Class.new(sup_app)
69
- sup_app.route do |r|
70
- r.is do
71
- r.get do
72
- r.html { 'a' }
73
- r.json { '{b:1}' }
74
- end
75
- end
76
-
77
- r.on 'test' do
78
- r.get do
79
- r.html { 'c' }
80
- r.json { '{d:2}' }
81
- end
82
- end
83
- end
84
- app.route do |r|
85
- r.on "subpath" do
86
- r.run(sup_app)
87
- end
88
- end
89
-
90
- body('/subpath').must_equal 'a'
91
- body('/subpath.html').must_equal 'a'
92
- body('/subpath.json').must_equal '{b:1}'
93
- body('/subpath/test').must_equal 'c'
94
- body('/subpath/test.html').must_equal 'c'
95
- body('/subpath/test.json').must_equal '{d:2}'
96
- end
97
-
98
- it "uses the default if neither file extension nor Accept header are given" do
99
- body('/a').must_equal 'HTML: html'
100
- header('Content-Type', '/a').must_equal 'text/html'
101
- end
102
- end
103
-
104
- describe "type_routing plugin" do
105
- it "does not use the file extension if its disabled" do
106
- app(:bare) do
107
- plugin :type_routing, :use_extension => false
108
-
109
- route do |r|
110
- r.is 'a' do
111
- r.html{ "HTML" }
112
- r.json{ "JSON" }
113
- end
114
- end
115
- end
116
-
117
- status('/a.json').must_equal 404
118
- status('/a.html').must_equal 404
119
- body('/a', 'HTTP_ACCEPT' => 'text/html').must_equal 'HTML'
120
- body('/a', 'HTTP_ACCEPT' => 'application/json').must_equal 'JSON'
121
- end
122
-
123
- it "does not use the Accept header if its disabled" do
124
- app(:bare) do
125
- plugin :type_routing, :use_header => false
126
-
127
- route do |r|
128
- r.is 'a' do
129
- r.html{ "HTML" }
130
- r.json{ "JSON" }
131
- end
132
- end
133
- end
134
-
135
- body('/a', 'HTTP_ACCEPT' => 'text/html').must_equal 'HTML'
136
- body('/a', 'HTTP_ACCEPT' => 'application/json').must_equal 'HTML'
137
- body('/a.html', 'HTTP_ACCEPT' => 'application/json').must_equal 'HTML'
138
- body('/a.json', 'HTTP_ACCEPT' => 'text/html').must_equal 'JSON'
139
- end
140
-
141
- it "only eats known file extensions" do
142
- app(:bare) do
143
- plugin :type_routing
144
-
145
- route do |r|
146
- r.is 'a' do
147
- r.html{ "HTML" }
148
- r.json{ "JSON" }
149
- r.xml{ "XML" }
150
- raise "Mismatch!"
151
- end
152
-
153
- r.is 'a.jpg' do
154
- "Okay"
155
- end
156
- end
157
- end
158
-
159
- body('/a.html').must_equal 'HTML'
160
- body('/a.json').must_equal 'JSON'
161
- body('/a.xml').must_equal 'XML'
162
- body('/a.jpg').must_equal 'Okay'
163
- end
164
-
165
- it "uses custom data types" do
166
- app(:bare) do
167
- plugin :type_routing, :types => { :yaml => 'application/x-yaml' }
168
-
169
- route do |r|
170
- r.is 'a' do
171
- r.html{ "HTML" }
172
- r.yaml{ "YAML" }
173
- raise "Mismatch!"
174
- end
175
- end
176
- end
177
-
178
- body('/a.html').must_equal 'HTML'
179
- body('/a.yaml').must_equal 'YAML'
180
- header('Content-Type', '/a.yaml').must_equal 'application/x-yaml'
181
- end
182
-
183
- it "handles response-specific type information when using custom types" do
184
- app(:bare) do
185
- plugin :type_routing, :exclude=>:html, :default_type=>:json, :types => { :html => 'text/html; charset=utf-8' }
186
-
187
- route do |r|
188
- r.is 'a' do
189
- r.json{ "JSON" }
190
- r.html{ "HTML" }
191
- raise "Mismatch!"
192
- end
193
- end
194
- end
195
-
196
- body('/a').must_equal 'JSON'
197
- body('/a.html').must_equal 'HTML'
198
- header('Content-Type', '/a.html').must_equal 'text/html; charset=utf-8'
199
- header('Content-Type', '/a', 'HTTP_ACCEPT' => 'text/html').must_equal 'text/html; charset=utf-8'
200
- end
201
-
202
- it "Handle nil content type when using custom types" do
203
- app(:bare) do
204
- plugin :type_routing, :exclude=>:html, :default_type=>:json, :types => { :html => nil}
205
-
206
- route do |r|
207
- r.is 'a' do
208
- r.html{ "HTML" }
209
- r.json{ "JSON" }
210
- raise "Mismatch!"
211
- end
212
- end
213
- end
214
-
215
- body('/a').must_equal 'JSON'
216
- body('/a.html').must_equal 'HTML'
217
- header('Content-Type', '/a.html').must_equal 'text/html'
218
- header('Content-Type', '/a', 'HTTP_ACCEPT' => 'text/html').must_equal 'application/json'
219
- end
220
-
221
- it "uses custom default type" do
222
- app(:bare) do
223
- plugin :type_routing, :default_type => :json
224
-
225
- route do |r|
226
- r.is 'a' do
227
- r.html{ "HTML" }
228
- r.json{ "JSON" }
229
- raise "Mismatch!"
230
- end
231
- end
232
- end
233
-
234
- body('/a').must_equal 'JSON'
235
- body('/a.html').must_equal 'HTML'
236
- body('/a.json').must_equal 'JSON'
237
- end
238
-
239
- it "supports nil default type" do
240
- app(:bare) do
241
- plugin :type_routing, :default_type => nil
242
-
243
- route do |r|
244
- r.is 'a' do
245
- r.html{ "HTML" }
246
- r.json{ "JSON" }
247
- "None"
248
- end
249
- end
250
- end
251
-
252
- body('/a').must_equal 'None'
253
- body('/a.html').must_equal 'HTML'
254
- body('/a.json').must_equal 'JSON'
255
- end
256
-
257
- it "excludes given types" do
258
- app(:bare) do
259
- plugin :type_routing, :exclude => [ :xml ]
260
-
261
- route do |r|
262
- r.is 'a' do
263
- r.html{ "HTML" }
264
- r.json{ "JSON" }
265
- r.xml{ raise "Mismatch!" }
266
- raise "Mismatch"
267
- end
268
- end
269
- end
270
-
271
- body('/a.html').must_equal 'HTML'
272
- body('/a.json').must_equal 'JSON'
273
- status('/a.xml').must_equal 404
274
-
275
- body('/a', 'HTTP_ACCEPT' => 'text/xml').must_equal 'HTML'
276
- body('/a', 'HTTP_ACCEPT' => 'application/json').must_equal 'JSON'
277
- body('/a', 'HTTP_ACCEPT' => 'text/xml').must_equal 'HTML'
278
- body('/a', 'HTTP_ACCEPT' => 'application/xml').must_equal 'HTML'
279
- end
280
-
281
- it "handles loading the plugin multiple times correctly" do
282
- app(:bare) do
283
- plugin :type_routing, :default_type => :json
284
- plugin :type_routing
285
-
286
- route do |r|
287
- r.is 'a' do
288
- r.html{ "HTML" }
289
- r.json{ "JSON" }
290
- raise "Mismatch!"
291
- end
292
- end
293
- end
294
-
295
- body('/a').must_equal 'JSON'
296
- body('/a.html').must_equal 'HTML'
297
- body('/a.json').must_equal 'JSON'
298
- end
299
-
300
- it "removes the handled part from r.remaining_path" do
301
- app(:bare) do
302
- plugin :type_routing
303
-
304
- route do |r|
305
- r.is 'a' do
306
- r.html{ r.remaining_path }
307
- end
308
- end
309
- end
310
-
311
- body('/a.html').must_equal ''
312
- end
313
-
314
- it "overrides r.real_remaining_path correctly" do
315
- app(:bare) do
316
- plugin :type_routing
317
-
318
- route do |r|
319
- r.is 'a' do
320
- r.html{ r.real_remaining_path }
321
- end
322
- end
323
- end
324
-
325
- body('/a.html').must_equal '.html'
326
- end
327
-
328
- it "takes the longest file extension first, when ambiguous" do
329
- app(:bare) do
330
- plugin :type_routing, :types => {
331
- :gz => 'application/octet-stream',
332
- :'tar.gz' => 'application/octet-stream',
333
- }
334
-
335
- route do |r|
336
- r.is 'a' do
337
- r.on_type(:gz) { 'GZ' }
338
- r.on_type(:'tar.gz') { 'TAR.GZ' }
339
- "NO"
340
- end
341
- end
342
- end
343
-
344
- body('/a').must_equal "NO"
345
- body('/a.gz').must_equal 'GZ'
346
- body('/a.tar.gz').must_equal 'TAR.GZ'
347
- end
348
- end