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,69 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "param_matchers plugin" do
4
- it "param! matcher should yield a param only if given and not empty" do
5
- app(:param_matchers) do |r|
6
- r.get "signup", :param! => "email" do |email|
7
- email
8
- end
9
-
10
- "No email"
11
- end
12
-
13
- io = StringIO.new
14
- body("/signup", "rack.input" => io, "QUERY_STRING" => "email=john@doe.com").must_equal 'john@doe.com'
15
- body("/signup", "rack.input" => io, "QUERY_STRING" => "").must_equal 'No email'
16
- body("/signup", "rack.input" => io, "QUERY_STRING" => "email=").must_equal 'No email'
17
- end
18
-
19
- it "param matcher should yield a param only if given" do
20
- app(:param_matchers) do |r|
21
- r.get "signup", :param=>"email" do |email|
22
- email
23
- end
24
-
25
- "No email"
26
- end
27
-
28
- io = StringIO.new
29
- body("/signup", "rack.input" => io, "QUERY_STRING" => "email=john@doe.com").must_equal 'john@doe.com'
30
- body("/signup", "rack.input" => io, "QUERY_STRING" => "").must_equal 'No email'
31
- body("/signup", "rack.input" => io, "QUERY_STRING" => "email=").must_equal ''
32
- end
33
-
34
- it "params! matcher should yield the params only if all are given and not empty" do
35
- app(:param_matchers) do |r|
36
- r.get "signup", :params! => %w"em ail" do |em, ail|
37
- em + ail
38
- end
39
-
40
- "No email"
41
- end
42
-
43
- io = StringIO.new
44
- body("/signup", "rack.input" => io, "QUERY_STRING" => "em=foo&ail=john@doe.com").must_equal 'foojohn@doe.com'
45
- body("/signup", "rack.input" => io, "QUERY_STRING" => "em=&ail=john@doe.com").must_equal 'No email'
46
- body("/signup", "rack.input" => io, "QUERY_STRING" => "em=foo&ail=").must_equal 'No email'
47
- body("/signup", "rack.input" => io, "QUERY_STRING" => "em=&ail=").must_equal 'No email'
48
- body("/signup", "rack.input" => io, "QUERY_STRING" => "em=foo").must_equal 'No email'
49
- body("/signup", "rack.input" => io, "QUERY_STRING" => "ail=john@doe.com").must_equal 'No email'
50
- end
51
-
52
- it "params matcher should yield the params only if all are given" do
53
- app(:param_matchers) do |r|
54
- r.get "signup", :params=>%w"em ail" do |em, ail|
55
- em + ail
56
- end
57
-
58
- "No email"
59
- end
60
-
61
- io = StringIO.new
62
- body("/signup", "rack.input" => io, "QUERY_STRING" => "em=foo&ail=john@doe.com").must_equal 'foojohn@doe.com'
63
- body("/signup", "rack.input" => io, "QUERY_STRING" => "em=&ail=john@doe.com").must_equal 'john@doe.com'
64
- body("/signup", "rack.input" => io, "QUERY_STRING" => "em=foo&ail=").must_equal 'foo'
65
- body("/signup", "rack.input" => io, "QUERY_STRING" => "em=&ail=").must_equal ''
66
- body("/signup", "rack.input" => io, "QUERY_STRING" => "em=foo").must_equal 'No email'
67
- body("/signup", "rack.input" => io, "QUERY_STRING" => "ail=john@doe.com").must_equal 'No email'
68
- end
69
- end
@@ -1,33 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "params_capturing plugin" do
4
- it "should add captures to r.params for symbol matchers" do
5
- app(:params_capturing) do |r|
6
- r.on('foo', :y, :z, :w) do |y, z, w|
7
- (r.params.values_at('y', 'z', 'w') + [y, z, w, r.params['captures'].length]).join('-')
8
- end
9
-
10
- r.on(/(quux)/, /(foo)(bar)/) do |q, foo, bar|
11
- "y-#{r.params['captures'].join}-#{q}-#{foo}-#{bar}"
12
- end
13
-
14
- r.on(/(quux)/, :y) do |q, y|
15
- r.on(:x) do |x|
16
- "y-#{r.params['y']}-#{r.params['x']}-#{q}-#{y}-#{x}-#{r.params['captures'].length}"
17
- end
18
-
19
- "y-#{r.params['y']}-#{q}-#{y}-#{r.params['captures'].length}"
20
- end
21
-
22
- r.on(:x) do |x|
23
- "x-#{x}-#{r.params['x']}-#{r.params['captures'].length}"
24
- end
25
- end
26
-
27
- body('/blarg', 'rack.input'=>StringIO.new).must_equal 'x-blarg-blarg-1'
28
- body('/foo/1/2/3', 'rack.input'=>StringIO.new).must_equal '1-2-3-1-2-3-3'
29
- body('/quux/foobar', 'rack.input'=>StringIO.new).must_equal 'y-quuxfoobar-quux-foo-bar'
30
- body('/quux/asdf', 'rack.input'=>StringIO.new).must_equal 'y--quux-asdf-2'
31
- body('/quux/asdf/890', 'rack.input'=>StringIO.new).must_equal 'y--890-quux-asdf-890-3'
32
- end
33
- end
@@ -1,43 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- begin
4
- require 'tilt/erb'
5
- rescue LoadError
6
- warn "tilt not installed, skipping partials plugin test"
7
- else
8
- describe "partials plugin" do
9
- before do
10
- app(:bare) do
11
- plugin :partials, :views=>"./spec/views"
12
-
13
- route do |r|
14
- r.is "partial" do
15
- partial("test", :locals=>{:title => "About Roda"})
16
- end
17
-
18
- r.is "partial/subdir" do
19
- partial("about/test", :locals=>{:title => "About Roda"})
20
- end
21
-
22
- r.is "partial/inline" do
23
- partial(:inline=>"Hello <%= name %>", :locals=>{:name => "Agent Smith"})
24
- end
25
-
26
- end
27
- end
28
- end
29
-
30
- it "partial renders without layout, and prepends _ to template" do
31
- body("/partial").strip.must_equal "<h1>About Roda</h1>"
32
- end
33
-
34
- it "partial renders without layout, and prepends _ to template" do
35
- body("/partial/subdir").strip.must_equal "<h1>Subdir: About Roda</h1>"
36
- end
37
-
38
- it "partial handles inline partials" do
39
- body("/partial/inline").strip.must_equal "Hello Agent Smith"
40
- end
41
-
42
- end
43
- end
@@ -1,29 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "pass plugin" do
4
- it "skips the current block if pass is called" do
5
- app(:pass) do |r|
6
- r.root do
7
- r.pass if env['FOO']
8
- 'root'
9
- end
10
-
11
- r.on :id do |id|
12
- r.pass if id == 'foo'
13
- id
14
- end
15
-
16
- r.on :x, :y do |x, y|
17
- x + y
18
- end
19
- end
20
-
21
- body.must_equal 'root'
22
- status('FOO'=>true).must_equal 404
23
- body("/a").must_equal 'a'
24
- body("/a/b").must_equal 'a'
25
- body("/foo/a").must_equal 'fooa'
26
- body("/foo/a/b").must_equal 'fooa'
27
- status("/foo").must_equal 404
28
- end
29
- end
@@ -1,42 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "path_matchers plugin" do
4
- it ":extension matcher should match given file extension" do
5
- app(:path_matchers) do |r|
6
- r.on "css" do
7
- r.on :extension=>"css" do |file|
8
- file
9
- end
10
- end
11
- end
12
-
13
- body("/css/reset.css").must_equal 'reset'
14
- status("/css/reset.bar").must_equal 404
15
- end
16
-
17
- it ":suffix matcher should match given suffix" do
18
- app(:path_matchers) do |r|
19
- r.on "css" do
20
- r.on :suffix=>".css" do |file|
21
- file
22
- end
23
- end
24
- end
25
-
26
- body("/css/reset.css").must_equal 'reset'
27
- status("/css/reset.bar").must_equal 404
28
- end
29
-
30
- it ":prefix matcher should match given prefix" do
31
- app(:path_matchers) do |r|
32
- r.on "css" do
33
- r.on :prefix=>"reset" do |file|
34
- file
35
- end
36
- end
37
- end
38
-
39
- body("/css/reset.css").must_equal '.css'
40
- status("/css/foo.bar").must_equal 404
41
- end
42
- end
@@ -1,45 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "path_rewriter plugin" do
4
- it "allows rewriting remaining path or PATH_INFO" do
5
- app(:bare) do
6
- plugin :path_rewriter
7
- rewrite_path '/1', '/a'
8
- rewrite_path '/a', '/b'
9
- rewrite_path '/c', '/d', :path_info=>true
10
- rewrite_path '/2', '/1', :path_info=>true
11
- rewrite_path '/3', '/h'
12
- rewrite_path '/3', '/g', :path_info=>true
13
- rewrite_path(/\A\/e\z/, '/f')
14
- rewrite_path(/\A\/(dynamic1)/){|match| "/#{match[1].capitalize}"}
15
- rewrite_path(/\A\/(dynamic2)/, :path_info=>true){|match| "/#{match[1].capitalize}"}
16
- proc{rewrite_path('/a', '/z'){|match| "/x"}}.must_raise(Roda::RodaError)
17
- proc{rewrite_path('/a', {:path_info=>true}, :path_info=>true)}.must_raise(Roda::RodaError)
18
- proc{rewrite_path('/a', {:path_info=>true}, :path_info=>true){|match| "/x"}}.must_raise(Roda::RodaError)
19
-
20
- route do |r|
21
- "#{r.path_info}:#{r.remaining_path}"
22
- end
23
- end
24
-
25
- body('/a').must_equal '/a:/b'
26
- body('/a/f').must_equal '/a/f:/b/f'
27
- body('/b').must_equal '/b:/b'
28
- body('/c').must_equal '/d:/d'
29
- body('/c/f').must_equal '/d/f:/d/f'
30
- body('/d').must_equal '/d:/d'
31
- body('/e').must_equal '/e:/f'
32
- body('/e/g').must_equal '/e/g:/e/g'
33
- body('/1').must_equal '/1:/b'
34
- body('/1/f').must_equal '/1/f:/b/f'
35
- body('/2').must_equal '/1:/b'
36
- body('/2/f').must_equal '/1/f:/b/f'
37
- body('/3').must_equal '/g:/g'
38
- body('/dynamic1').must_equal '/dynamic1:/Dynamic1'
39
- body('/dynamic2').must_equal '/Dynamic2:/Dynamic2'
40
-
41
- app.freeze
42
- body('/a').must_equal '/a:/b'
43
- proc{app.rewrite_path '/a', '/b'}.must_raise
44
- end
45
- end
@@ -1,222 +0,0 @@
1
- require_relative "../spec_helper"
2
-
3
- describe "path plugin" do
4
- def path_app(*args, &block)
5
- app(:bare) do
6
- plugin :path
7
- path(*args, &block)
8
- route{|r| send(r.path_info)}
9
- end
10
- end
11
-
12
- def path_script_name_app(*args, &block)
13
- app(:bare) do
14
- opts[:add_script_name] = true
15
- plugin :path
16
- path(*args, &block)
17
- route{|r| send(r.path_info)}
18
- end
19
- end
20
-
21
- def path_block_app(b, *args, &block)
22
- path_app(*args, &block)
23
- app.route{|r| send(r.path_info, &b)}
24
- end
25
-
26
- it "adds path method for defining named paths" do
27
- app(:bare) do
28
- plugin :path
29
- path :foo, "/foo"
30
- path :bar do |o|
31
- "/bar/#{o}"
32
- end
33
- path :baz do |&block|
34
- "/baz/#{block.call}"
35
- end
36
-
37
- route do |r|
38
- "#{foo_path}#{bar_path('a')}#{baz_path{'b'}}"
39
- end
40
- end
41
-
42
- body.must_equal '/foo/bar/a/baz/b'
43
- end
44
-
45
- it "raises if both path and block are given" do
46
- app.plugin :path
47
- proc{app.path(:foo, '/foo'){}}.must_raise(Roda::RodaError)
48
- end
49
-
50
- it "raises if neither path nor block are given" do
51
- app.plugin :path
52
- proc{app.path(:foo)}.must_raise(Roda::RodaError)
53
- end
54
-
55
- it "raises if two options hashes are given" do
56
- app.plugin :path
57
- proc{app.path(:foo, {:name=>'a'}, :add_script_name=>true)}.must_raise(Roda::RodaError)
58
- end
59
-
60
- it "supports :name option for naming the method" do
61
- path_app(:foo, :name=>'foobar_route'){"/bar/foo"}
62
- body("foobar_route").must_equal "/bar/foo"
63
- end
64
-
65
- it "supports :add_script_name option for automatically adding the script name" do
66
- path_app(:foo, :add_script_name=>true){"/bar/foo"}
67
- body("foo_path", 'SCRIPT_NAME'=>'/baz').must_equal "/baz/bar/foo"
68
- end
69
-
70
- it "respects :add_script_name app option for automatically adding the script name" do
71
- path_script_name_app(:foo){"/bar/foo"}
72
- body("foo_path", 'SCRIPT_NAME'=>'/baz').must_equal "/baz/bar/foo"
73
- end
74
-
75
- it "supports :add_script_name=>false option for not automatically adding the script name" do
76
- path_script_name_app(:foo, :add_script_name=>false){"/bar/foo"}
77
- body("foo_path", 'SCRIPT_NAME'=>'/baz').must_equal "/bar/foo"
78
- end
79
-
80
- it "supports path method accepting a block when using :add_script_name" do
81
- path_block_app(lambda{"c"}, :foo, :add_script_name=>true){|&block| "/bar/foo/#{block.call}"}
82
- body("foo_path", 'SCRIPT_NAME'=>'/baz').must_equal "/baz/bar/foo/c"
83
- end
84
-
85
- it "supports :url option for also creating a *_url method" do
86
- path_app(:foo, :url=>true){"/bar/foo"}
87
- body("foo_path", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).must_equal "/bar/foo"
88
- body("foo_url", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).must_equal "http://example.org/bar/foo"
89
- end
90
-
91
- it "supports url method accepting a block when using :url" do
92
- path_block_app(lambda{"c"}, :foo, :url=>true){|&block| "/bar/foo/#{block.call}"}
93
- body("foo_url", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).must_equal "http://example.org/bar/foo/c"
94
- end
95
-
96
- it "supports url method name specified in :url option" do
97
- path_app(:foo, :url=>:foobar_uri){"/bar/foo"}
98
- body("foo_path", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).must_equal "/bar/foo"
99
- body("foobar_uri", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).must_equal "http://example.org/bar/foo"
100
- end
101
-
102
- it "supports :url_only option for not creating a path method" do
103
- path_app(:foo, :url_only=>true){"/bar/foo"}
104
- proc{body("foo_path")}.must_raise(NoMethodError)
105
- body("foo_url", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).must_equal "http://example.org/bar/foo"
106
- end
107
-
108
- it "handles non-default ports in url methods" do
109
- path_app(:foo, :url=>true){"/bar/foo"}
110
- body("foo_url", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>81).must_equal "http://example.org:81/bar/foo"
111
- end
112
- end
113
-
114
- describe "path plugin" do
115
- before do
116
- app(:bare) do
117
- plugin :path
118
- route{|r| path(*env['path'])}
119
- end
120
-
121
-
122
- c = Class.new{attr_accessor :a}
123
- app.path(c){|obj, *args| "/d/#{obj.a}/#{File.join(*args)}"}
124
- @obj = c.new
125
- @obj.a = 1
126
- end
127
-
128
- it "Roda#path respects classes and symbols registered via Roda.path" do
129
- # Strings
130
- body('path'=>'/foo/bar').must_equal '/foo/bar'
131
-
132
- # Classes
133
- body('path'=>@obj).must_equal '/d/1/'
134
- body('path'=>[@obj, 'foo']).must_equal '/d/1/foo'
135
- body('path'=>[@obj, 'foo', 'bar']).must_equal '/d/1/foo/bar'
136
- end
137
-
138
- it "Roda#path raises an error for an unrecognized class" do
139
- # Strings
140
- proc{body('path'=>:foo)}.must_raise(Roda::RodaError)
141
- end
142
-
143
- it "Roda#path respects :add_script_name app option" do
144
- app.opts[:add_script_name] = true
145
-
146
- # Strings
147
- body('path'=>'/foo/bar', 'SCRIPT_NAME'=>'/baz').must_equal '/baz/foo/bar'
148
-
149
- # Classes
150
- body('path'=>@obj, 'SCRIPT_NAME'=>'/baz').must_equal '/baz/d/1/'
151
- body('path'=>[@obj, 'foo'], 'SCRIPT_NAME'=>'/baz').must_equal '/baz/d/1/foo'
152
- body('path'=>[@obj, 'foo', 'bar'], 'SCRIPT_NAME'=>'/baz').must_equal '/baz/d/1/foo/bar'
153
- end
154
-
155
- it "Roda#path works in subclasses" do
156
- old_app = @app
157
- @app = Class.new(@app)
158
- @app.route{|r| path('/a')}
159
- body.must_equal '/a'
160
-
161
- @app.path(String){|b| "/foo#{b}"}
162
- body.must_equal '/foo/a'
163
-
164
- @app = old_app
165
- body('path'=>'/a').must_equal '/a'
166
- end
167
-
168
- it "registers classes by reference by default" do
169
- c1 = Class.new
170
- def c1.name; 'C'; end
171
- c2 = Class.new
172
- def c2.name; 'C'; end
173
- @app.path(c1){'/c'}
174
- @app.route{|r| path(r.env['c'])}
175
- body('c'=>c1.new).must_equal '/c'
176
- proc{body('c'=>c2.new)}.must_raise(Roda::RodaError)
177
- end
178
-
179
- it ":by_name => option registers classes by name" do
180
- c1 = Class.new
181
- def c1.name; 'C'; end
182
- c2 = Class.new
183
- def c2.name; 'C'; end
184
- @app.plugin :path, :by_name=>true
185
- @app.path(c1){'/c'}
186
- @app.route{|r| path(r.env['c'])}
187
- body('c'=>c1.new).must_equal '/c'
188
- body('c'=>c2.new).must_equal '/c'
189
- end
190
-
191
- it ":by_name defaults to true in development" do
192
- with_rack_env('development') do
193
- app(:path){}
194
- end
195
- app.opts[:path_class_by_name].must_equal true
196
- app(:path){}
197
- app.opts[:path_class_by_name].must_equal false
198
- end
199
-
200
- it "Roda.path_block returns the block used" do
201
- c = Class.new
202
- b = proc{|x| x.to_s}
203
- @app.path(c, &b)
204
- # Work around minitest bug
205
- app.path_block(c).must_equal b
206
- end
207
-
208
- it "Roda.path doesn't work with classes without blocks" do
209
- proc{app.path(Class.new)}.must_raise(Roda::RodaError)
210
- end
211
-
212
- it "Roda.path doesn't work with classes with paths or options" do
213
- proc{app.path(Class.new, '/a'){}}.must_raise(Roda::RodaError)
214
- proc{app.path(Class.new, nil, :a=>1){}}.must_raise(Roda::RodaError)
215
- end
216
-
217
- it "Roda.path doesn't work after freezing the app" do
218
- app.freeze
219
- proc{app.path(Class.new){|obj| ''}}.must_raise
220
- end
221
- end
222
-