roda 2.29.0 → 3.0.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 (170) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +52 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +51 -109
  5. data/Rakefile +7 -14
  6. data/doc/conventions.rdoc +4 -4
  7. data/doc/release_notes/1.2.0.txt +1 -1
  8. data/doc/release_notes/3.0.0.txt +84 -0
  9. data/lib/roda.rb +25 -79
  10. data/lib/roda/plugins/assets.rb +25 -58
  11. data/lib/roda/plugins/assets_preloading.rb +0 -5
  12. data/lib/roda/plugins/backtracking_array.rb +0 -5
  13. data/lib/roda/plugins/branch_locals.rb +3 -3
  14. data/lib/roda/plugins/caching.rb +5 -38
  15. data/lib/roda/plugins/chunked.rb +7 -25
  16. data/lib/roda/plugins/class_level_routing.rb +2 -2
  17. data/lib/roda/plugins/content_for.rb +7 -10
  18. data/lib/roda/plugins/cookies.rb +3 -3
  19. data/lib/roda/plugins/csrf.rb +2 -2
  20. data/lib/roda/plugins/delegate.rb +3 -3
  21. data/lib/roda/plugins/drop_body.rb +0 -7
  22. data/lib/roda/plugins/empty_root.rb +0 -3
  23. data/lib/roda/plugins/error_email.rb +4 -6
  24. data/lib/roda/plugins/error_handler.rb +1 -2
  25. data/lib/roda/plugins/error_mail.rb +3 -6
  26. data/lib/roda/plugins/flash.rb +0 -4
  27. data/lib/roda/plugins/h.rb +5 -0
  28. data/lib/roda/plugins/hash_matcher.rb +4 -2
  29. data/lib/roda/plugins/head.rb +5 -7
  30. data/lib/roda/plugins/header_matchers.rb +12 -33
  31. data/lib/roda/plugins/heartbeat.rb +2 -7
  32. data/lib/roda/plugins/indifferent_params.rb +2 -2
  33. data/lib/roda/plugins/json.rb +6 -14
  34. data/lib/roda/plugins/json_parser.rb +2 -13
  35. data/lib/roda/plugins/mailer.rb +29 -39
  36. data/lib/roda/plugins/match_affix.rb +0 -5
  37. data/lib/roda/plugins/middleware.rb +10 -15
  38. data/lib/roda/plugins/multi_route.rb +8 -5
  39. data/lib/roda/plugins/multi_run.rb +1 -0
  40. data/lib/roda/plugins/named_templates.rb +2 -2
  41. data/lib/roda/plugins/optimized_string_matchers.rb +0 -3
  42. data/lib/roda/plugins/padrino_render.rb +6 -9
  43. data/lib/roda/plugins/param_matchers.rb +6 -6
  44. data/lib/roda/plugins/params_capturing.rb +15 -35
  45. data/lib/roda/plugins/partials.rb +3 -8
  46. data/lib/roda/plugins/path.rb +5 -5
  47. data/lib/roda/plugins/path_matchers.rb +3 -3
  48. data/lib/roda/plugins/path_rewriter.rb +4 -9
  49. data/lib/roda/plugins/placeholder_string_matchers.rb +1 -1
  50. data/lib/roda/plugins/precompile_templates.rb +10 -20
  51. data/lib/roda/plugins/public.rb +6 -9
  52. data/lib/roda/plugins/render.rb +50 -171
  53. data/lib/roda/plugins/render_each.rb +4 -7
  54. data/lib/roda/plugins/render_locals.rb +6 -20
  55. data/lib/roda/plugins/request_headers.rb +2 -4
  56. data/lib/roda/plugins/run_append_slash.rb +1 -4
  57. data/lib/roda/plugins/run_handler.rb +4 -7
  58. data/lib/roda/plugins/shared_vars.rb +3 -6
  59. data/lib/roda/plugins/sinatra_helpers.rb +11 -40
  60. data/lib/roda/plugins/slash_path_empty.rb +0 -3
  61. data/lib/roda/plugins/static.rb +2 -2
  62. data/lib/roda/plugins/static_routing.rb +2 -3
  63. data/lib/roda/plugins/streaming.rb +15 -108
  64. data/lib/roda/plugins/strip_path_prefix.rb +1 -1
  65. data/lib/roda/plugins/symbol_matchers.rb +7 -23
  66. data/lib/roda/plugins/type_routing.rb +4 -9
  67. data/lib/roda/plugins/view_options.rb +10 -66
  68. data/lib/roda/version.rb +2 -2
  69. data/spec/all.rb +0 -2
  70. data/spec/composition_spec.rb +1 -1
  71. data/spec/env_spec.rb +1 -1
  72. data/spec/freeze_spec.rb +1 -1
  73. data/spec/integration_spec.rb +1 -1
  74. data/spec/matchers_spec.rb +26 -70
  75. data/spec/opts_spec.rb +1 -1
  76. data/spec/plugin/all_verbs_spec.rb +1 -1
  77. data/spec/plugin/assets_preloading_spec.rb +1 -1
  78. data/spec/plugin/assets_spec.rb +43 -27
  79. data/spec/plugin/backtracking_array_spec.rb +1 -1
  80. data/spec/plugin/branch_locals_spec.rb +1 -1
  81. data/spec/plugin/caching_spec.rb +1 -1
  82. data/spec/plugin/chunked_spec.rb +1 -1
  83. data/spec/plugin/class_level_routing_spec.rb +1 -1
  84. data/spec/plugin/class_matchers_spec.rb +1 -1
  85. data/spec/plugin/content_for_spec.rb +2 -7
  86. data/spec/plugin/cookies_spec.rb +1 -1
  87. data/spec/plugin/csrf_spec.rb +1 -1
  88. data/spec/plugin/default_headers_spec.rb +1 -1
  89. data/spec/plugin/default_status_spec.rb +1 -1
  90. data/spec/plugin/delay_build_spec.rb +1 -1
  91. data/spec/plugin/delegate_spec.rb +1 -1
  92. data/spec/plugin/delete_empty_headers_spec.rb +1 -1
  93. data/spec/plugin/disallow_file_uploads_spec.rb +2 -2
  94. data/spec/plugin/drop_body_spec.rb +1 -1
  95. data/spec/plugin/empty_root_spec.rb +1 -1
  96. data/spec/plugin/environments_spec.rb +1 -1
  97. data/spec/plugin/error_email_spec.rb +1 -1
  98. data/spec/plugin/error_handler_spec.rb +1 -1
  99. data/spec/plugin/error_mail_spec.rb +2 -2
  100. data/spec/plugin/flash_spec.rb +1 -1
  101. data/spec/plugin/h_spec.rb +1 -1
  102. data/spec/plugin/halt_spec.rb +2 -2
  103. data/spec/plugin/hash_matcher_spec.rb +1 -1
  104. data/spec/plugin/head_spec.rb +1 -1
  105. data/spec/plugin/header_matchers_spec.rb +4 -47
  106. data/spec/plugin/heartbeat_spec.rb +1 -1
  107. data/spec/plugin/hooks_spec.rb +1 -1
  108. data/spec/plugin/indifferent_params_spec.rb +1 -1
  109. data/spec/plugin/json_parser_spec.rb +12 -1
  110. data/spec/plugin/json_spec.rb +8 -1
  111. data/spec/plugin/mailer_spec.rb +1 -1
  112. data/spec/plugin/match_affix_spec.rb +1 -1
  113. data/spec/plugin/middleware_spec.rb +15 -1
  114. data/spec/plugin/module_include_spec.rb +1 -1
  115. data/spec/plugin/multi_route_spec.rb +5 -3
  116. data/spec/plugin/multi_run_spec.rb +1 -1
  117. data/spec/plugin/multi_view_spec.rb +1 -1
  118. data/spec/plugin/named_templates_spec.rb +1 -1
  119. data/spec/plugin/not_allowed_spec.rb +1 -1
  120. data/spec/plugin/not_found_spec.rb +1 -1
  121. data/spec/plugin/optimized_string_matchers_spec.rb +1 -1
  122. data/spec/plugin/padrino_render_spec.rb +1 -1
  123. data/spec/plugin/param_matchers_spec.rb +1 -1
  124. data/spec/plugin/params_capturing_spec.rb +6 -22
  125. data/spec/plugin/partials_spec.rb +1 -1
  126. data/spec/plugin/pass_spec.rb +1 -1
  127. data/spec/plugin/path_matchers_spec.rb +1 -1
  128. data/spec/plugin/path_rewriter_spec.rb +1 -1
  129. data/spec/plugin/path_spec.rb +1 -1
  130. data/spec/plugin/placeholder_string_matchers_spec.rb +3 -36
  131. data/spec/plugin/precompile_templates_spec.rb +1 -17
  132. data/spec/plugin/public_spec.rb +3 -4
  133. data/spec/plugin/render_each_spec.rb +1 -1
  134. data/spec/plugin/render_locals_spec.rb +1 -1
  135. data/spec/plugin/render_spec.rb +28 -114
  136. data/spec/plugin/request_headers_spec.rb +1 -1
  137. data/spec/plugin/response_request_spec.rb +1 -1
  138. data/spec/plugin/run_append_slash_spec.rb +1 -1
  139. data/spec/plugin/run_handler_spec.rb +1 -1
  140. data/spec/plugin/shared_vars_spec.rb +1 -1
  141. data/spec/plugin/sinatra_helpers_spec.rb +1 -1
  142. data/spec/plugin/slash_path_empty_spec.rb +1 -1
  143. data/spec/plugin/static_routing_spec.rb +1 -1
  144. data/spec/plugin/static_spec.rb +1 -1
  145. data/spec/plugin/status_303_spec.rb +1 -1
  146. data/spec/plugin/status_handler_spec.rb +1 -1
  147. data/spec/plugin/streaming_spec.rb +1 -106
  148. data/spec/plugin/strip_path_prefix_spec.rb +1 -1
  149. data/spec/plugin/symbol_matchers_spec.rb +1 -77
  150. data/spec/plugin/symbol_status_spec.rb +1 -1
  151. data/spec/plugin/symbol_views_spec.rb +1 -1
  152. data/spec/plugin/type_routing_spec.rb +1 -1
  153. data/spec/plugin/unescape_path_spec.rb +1 -1
  154. data/spec/plugin/view_options_spec.rb +16 -110
  155. data/spec/plugin_spec.rb +1 -1
  156. data/spec/redirect_spec.rb +1 -1
  157. data/spec/request_spec.rb +1 -1
  158. data/spec/response_spec.rb +1 -1
  159. data/spec/session_spec.rb +1 -1
  160. data/spec/spec_helper.rb +1 -3
  161. data/spec/version_spec.rb +1 -1
  162. metadata +6 -26
  163. data/lib/roda/plugins/_erubis_escaping.rb +0 -59
  164. data/lib/roda/plugins/per_thread_caching.rb +0 -71
  165. data/lib/roda/plugins/static_path_info.rb +0 -12
  166. data/lib/roda/plugins/view_subdirs.rb +0 -7
  167. data/lib/roda/plugins/websockets.rb +0 -107
  168. data/spec/plugin/_erubis_escaping_spec.rb +0 -97
  169. data/spec/plugin/per_thread_caching_spec.rb +0 -28
  170. data/spec/plugin/websockets_spec.rb +0 -84
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "heartbeat plugin" do
4
4
  it "should return heartbeat response for heartbeat paths only" do
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "hooks plugin" do
4
4
  before do
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "indifferent_params plugin" do
4
4
  it "allows indifferent access to request params via params method" do
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "json_parser plugin" do
4
4
  before do
@@ -69,4 +69,15 @@ describe "json_parser plugin" do
69
69
  end
70
70
  body('rack.input'=>StringIO.new('{}'), 'CONTENT_TYPE'=>'text/json', 'REQUEST_METHOD'=>'POST').must_equal '{}:/'
71
71
  end
72
+
73
+ it "supports resetting :include_request option to false" do
74
+ app(:bare) do
75
+ plugin :json_parser, :include_request => true
76
+ plugin :json_parser, :include_request => false
77
+ route do |r|
78
+ r.params['a']['b'].to_s
79
+ end
80
+ end
81
+ body('rack.input'=>StringIO.new('{"a":{"b":1}}'), 'CONTENT_TYPE'=>'text/json', 'REQUEST_METHOD'=>'POST').must_equal '1'
82
+ end
72
83
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "json plugin" do
4
4
  before do
@@ -69,6 +69,13 @@ describe "json plugin" do
69
69
  body("/hash").must_equal 'b:/hash'
70
70
  end
71
71
 
72
+ it "should allow resetting :include_request to false" do
73
+ app.plugin :json, :include_request => true
74
+ app.plugin :json, :include_request => false
75
+
76
+ body("/hash").must_equal '{"a":"b"}'
77
+ end
78
+
72
79
  it "should allow custom content type for a response" do
73
80
  app.plugin :json, :content_type => "application/xml"
74
81
  header('Content-Type', "/array").must_equal 'application/xml'
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  begin
4
4
  require 'mail'
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "match_affix plugin" do
4
4
  it "allows changing the match prefix/suffix" do
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "middleware plugin" do
4
4
  it "turns Roda app into middlware" do
@@ -57,6 +57,20 @@ describe "middleware plugin" do
57
57
  body.must_equal 'a'
58
58
  end
59
59
 
60
+ it "makes middleware always use a subclass of the app" do
61
+ app(:middleware) do |r|
62
+ r.get{opts[:a]}
63
+ end
64
+ app.opts[:a] = 'a'
65
+ a = app
66
+ app(:bare) do
67
+ use a
68
+ route{}
69
+ end
70
+ a.opts[:a] = 'b'
71
+ body.must_equal 'a'
72
+ end
73
+
60
74
  it "should raise error if attempting to use options for Roda application that does not support configurable middleware" do
61
75
  a1 = app(:bare){plugin :middleware}
62
76
  proc{app(:bare){use a1, :foo; route{}; build_rack_app}}.must_raise Roda::RodaError
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "module_include plugin" do
4
4
  it "must_include given module in request or response class" do
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "multi_route plugin" do
4
4
  before do
@@ -171,12 +171,14 @@ describe "multi_route plugin" do
171
171
  end
172
172
 
173
173
  describe "multi_route plugin" do
174
- deprecated "r.multi_route works even without routes defined" do
174
+ it "r.multi_route raises error for invalid namespace" do
175
175
  app(:multi_route) do |r|
176
+ r.is('a'){r.multi_route('foo')}
176
177
  r.multi_route
177
178
  'a'
178
179
  end
179
- body.must_equal 'a'
180
+ proc{body}.must_raise Roda::RodaError
181
+ proc{body('/a')}.must_raise Roda::RodaError
180
182
  end
181
183
  end
182
184
 
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "multi_run plugin" do
4
4
  it "adds Roda.run method for setting up prefix delegations to other rack apps" do
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  begin
4
4
  require 'tilt/erb'
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  begin
4
4
  require 'tilt/erb'
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "not_allowed plugin" do
4
4
  it "skips the current block if pass is called" do
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "not_found plugin" do
4
4
  it "executes on no arguments" do
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "optimized_string_matchers plugin" do
4
4
  it "should support on_branch and is_exactly match methods" do
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  begin
4
4
  require 'tilt/erb'
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "param_matchers plugin" do
4
4
  it "param! matcher should yield a param only if given and not empty" do
@@ -1,26 +1,26 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "params_capturing plugin" do
4
4
  it "should add captures to r.params for symbol matchers" do
5
5
  app(:params_capturing) do |r|
6
6
  r.on('foo', :y, :z, :w) do |y, z, w|
7
- (r.params.values_at('y', 'z', 'w') + [y, z, w, r[:captures].length]).join('-')
7
+ (r.params.values_at('y', 'z', 'w') + [y, z, w, r.params['captures'].length]).join('-')
8
8
  end
9
9
 
10
10
  r.on(/(quux)/, /(foo)(bar)/) do |q, foo, bar|
11
- "y-#{r[:captures].join}-#{q}-#{foo}-#{bar}"
11
+ "y-#{r.params['captures'].join}-#{q}-#{foo}-#{bar}"
12
12
  end
13
13
 
14
14
  r.on(/(quux)/, :y) do |q, y|
15
15
  r.on(:x) do |x|
16
- "y-#{r[:y]}-#{r[:x]}-#{q}-#{y}-#{x}-#{r[:captures].length}"
16
+ "y-#{r.params['y']}-#{r.params['x']}-#{q}-#{y}-#{x}-#{r.params['captures'].length}"
17
17
  end
18
18
 
19
- "y-#{r[:y]}-#{q}-#{y}-#{r[:captures].length}"
19
+ "y-#{r.params['y']}-#{q}-#{y}-#{r.params['captures'].length}"
20
20
  end
21
21
 
22
22
  r.on(:x) do |x|
23
- "x-#{x}-#{r[:x]}-#{r[:captures].length}"
23
+ "x-#{x}-#{r.params['x']}-#{r.params['captures'].length}"
24
24
  end
25
25
  end
26
26
 
@@ -30,20 +30,4 @@ describe "params_capturing plugin" do
30
30
  body('/quux/asdf', 'rack.input'=>StringIO.new).must_equal 'y--quux-asdf-2'
31
31
  body('/quux/asdf/890', 'rack.input'=>StringIO.new).must_equal 'y--890-quux-asdf-890-3'
32
32
  end
33
-
34
- deprecated "should add captures to r.params for string matchers" do
35
- app(:params_capturing) do |r|
36
- r.on("bar/:foo") do |foo|
37
- "b-#{foo}-#{r[:foo]}-#{r[:captures].length}"
38
- end
39
-
40
- r.on("baz/:bar", :foo) do |bar, foo|
41
- "b-#{bar}-#{foo}-#{r[:bar]}-#{r[:foo]}-#{r[:captures].length}"
42
- end
43
- end
44
- app.opts[:verbatim_string_matcher] = false
45
-
46
- body('/bar/banana', 'rack.input'=>StringIO.new).must_equal 'b-banana-banana-1'
47
- body('/baz/ban/ana', 'rack.input'=>StringIO.new).must_equal 'b-ban-ana-ban-ana-2'
48
- end
49
33
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  begin
4
4
  require 'tilt/erb'
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "pass plugin" do
4
4
  it "skips the current block if pass is called" do
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "path_matchers plugin" do
4
4
  it ":extension matcher should match given file extension" do
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "path_rewriter plugin" do
4
4
  it "allows rewriting remaining path or PATH_INFO" do
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "path plugin" do
4
4
  def path_app(*args, &block)
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "placeholder_string_matchers plugin" do
4
4
  it "should handle string with embedded param" do
@@ -57,11 +57,11 @@ describe "placeholder_string_matchers plugin" do
57
57
 
58
58
  route do |r|
59
59
  r.on("bar/:foo") do |foo|
60
- "b-#{foo}-#{r[:foo]}-#{r[:captures].length}"
60
+ "b-#{foo}-#{r.params['foo']}-#{r.params['captures'].length}"
61
61
  end
62
62
 
63
63
  r.on("baz/:bar", :foo) do |bar, foo|
64
- "b-#{bar}-#{foo}-#{r[:bar]}-#{r[:foo]}-#{r[:captures].length}"
64
+ "b-#{bar}-#{foo}-#{r.params['bar']}-#{r.params['foo']}-#{r.params['captures'].length}"
65
65
  end
66
66
  end
67
67
  end
@@ -123,37 +123,4 @@ describe "placeholder_string_matchers plugin" do
123
123
  body('/thing/q').must_equal 'thingq'
124
124
  body('/thing2/q').must_equal 'thing2q'
125
125
  end
126
-
127
- deprecated "works with symbol_matchers plugin and deprecated matchers" do
128
- app(:bare) do
129
- plugin :placeholder_string_matchers
130
- plugin :symbol_matchers
131
- symbol_matcher(:f, /(f+)/)
132
-
133
- route do |r|
134
- r.is "foo:optd" do |o|
135
- "foo#{o.inspect}"
136
- end
137
-
138
- r.is "bar:opt" do |o|
139
- "bar#{o.inspect}"
140
- end
141
-
142
- r.is "format:format" do |f|
143
- "format#{f.inspect}"
144
- end
145
- end
146
- end
147
-
148
- body("/foo").must_equal 'foonil'
149
- body("/foo/123").must_equal 'foo"123"'
150
- status("/foo/bar").must_equal 404
151
- status("/foo/123/a").must_equal 404
152
- body("/bar").must_equal 'barnil'
153
- body("/bar/foo").must_equal 'bar"foo"'
154
- status("/bar/foo/baz").must_equal 404
155
- body("/format").must_equal 'formatnil'
156
- body("/format.json").must_equal 'format"json"'
157
- status("/format.").must_equal 404
158
- end
159
126
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  begin
4
4
  require 'tilt/erb'
@@ -39,22 +39,6 @@ describe "precompile_templates plugin" do
39
39
  body.strip.must_equal '<h1>1</h1>'
40
40
  end
41
41
 
42
- it "adds support for template precompilation with sorting :locals" do
43
- app(:bare) do
44
- plugin :render, :views=>'spec/views'
45
- plugin :precompile_templates, :sort_locals=>true
46
- route do |r|
47
- render('home', :locals=>{:name => "Agent Smith", :title => "Home"})
48
- end
49
- end
50
-
51
- app.render_opts[:cache][File.expand_path('spec/views/home.erb')].must_be_nil
52
- app.precompile_templates 'spec/views/h*.erb', :locals=>[:title, :name]
53
- app.render_opts[:cache][File.expand_path('spec/views/home.erb')].wont_equal nil
54
- app.render_opts[:cache][File.expand_path('spec/views/home.erb')].instance_variable_get(:@compiled_method)[[:name, :title]].wont_equal nil
55
- body.strip.must_equal "<h1>Home</h1>\n<p>Hello Agent Smith</p>"
56
- end
57
-
58
42
  it "adds support for template precompilation with :inline" do
59
43
  app(:bare) do
60
44
  plugin :render, :views=>'spec/views'
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  describe "public plugin" do
4
4
  it "adds r.public for serving static files from public folder" do
@@ -48,13 +48,12 @@ describe "public plugin" do
48
48
  body('/about.erb').must_equal File.read('spec/views/about.erb')
49
49
  header('Content-Encoding', '/about.erb').must_be_nil
50
50
 
51
- meth = RUBY_VERSION >= '1.9' ? :binread : :read
52
- body('/about/_test.erb', 'HTTP_ACCEPT_ENCODING'=>'deflate, gzip').must_equal File.send(meth, 'spec/views/about/_test.erb.gz')
51
+ body('/about/_test.erb', 'HTTP_ACCEPT_ENCODING'=>'deflate, gzip').must_equal File.binread('spec/views/about/_test.erb.gz')
53
52
  h = req('/about/_test.erb', 'HTTP_ACCEPT_ENCODING'=>'deflate, gzip')[1]
54
53
  h['Content-Encoding'].must_equal 'gzip'
55
54
  h['Content-Type'].must_equal 'text/plain'
56
55
 
57
- body('/about/_test.css', 'HTTP_ACCEPT_ENCODING'=>'deflate, gzip').must_equal File.send(meth, 'spec/views/about/_test.css.gz')
56
+ body('/about/_test.css', 'HTTP_ACCEPT_ENCODING'=>'deflate, gzip').must_equal File.binread('spec/views/about/_test.css.gz')
58
57
  h = req('/about/_test.css', 'HTTP_ACCEPT_ENCODING'=>'deflate, gzip')[1]
59
58
  h['Content-Encoding'].must_equal 'gzip'
60
59
  h['Content-Type'].must_equal 'text/css'
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  begin
4
4
  require 'tilt/erb'
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  begin
4
4
  require 'tilt/erb'
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
1
+ require_relative "../spec_helper"
2
2
 
3
3
  begin
4
4
  require 'tilt/erb'
@@ -50,13 +50,6 @@ describe "render plugin" do
50
50
  body("/inline").strip.must_equal "Hello <%= name %>"
51
51
  end
52
52
 
53
- deprecated "with str as ext" do
54
- app.plugin :render, :ext => "str"
55
- body("/about").strip.must_equal "<h1>About Roda</h1>"
56
- body("/home").strip.must_equal "<title>Roda: Home</title>\n<h1>Home</h1>\n<p>Hello Agent Smith</p>"
57
- body("/inline").strip.must_equal "Hello <%= name %>"
58
- end
59
-
60
53
  it "custom default layout support" do
61
54
  app.plugin :render, :layout => "layout-alternative"
62
55
  body("/home").strip.must_equal "<title>Alternative Layout: Home</title>\n<h1>Home</h1>\n<p>Hello Agent Smith</p>"
@@ -68,30 +61,6 @@ describe "render plugin" do
68
61
  end
69
62
  end
70
63
 
71
- describe "render plugin with :layout_opts=>{:merge_locals=>true}" do
72
- deprecated "should choose method opts before plugin opts, and layout specific before locals" do
73
- app(:bare) do
74
- plugin :render, :views=>"./spec/views", :check_paths=>true, :locals=>{:a=>1, :b=>2, :c=>3, :d=>4, :e=>5}, :layout_opts=>{:inline=>'<%= a %>|<%= b %>|<%= c %>|<%= d %>|<%= e %>|<%= f %>|<%= yield %>', :merge_locals=>true, :locals=>{:a=>-1, :f=>6}}
75
-
76
- route do |r|
77
- r.on "base" do
78
- view(:inline=>'(<%= a %>|<%= b %>|<%= c %>|<%= d %>|<%= e %>)')
79
- end
80
- r.on "override" do
81
- view(:inline=>'(<%= a %>|<%= b %>|<%= c %>|<%= d %>|<%= e %>)', :locals=>{:b=>-2, :d=>-4, :f=>-6}, :layout_opts=>{:locals=>{:d=>0, :c=>-3, :e=>-5}})
82
- end
83
- r.on "no_merge" do
84
- view(:inline=>'(<%= a %>|<%= b %>|<%= c %>|<%= d %>|<%= e %>)', :locals=>{:b=>-2, :d=>-4, :f=>-6}, :layout_opts=>{:merge_locals=>false, :locals=>{:d=>0, :c=>-3, :e=>-5}})
85
- end
86
- end
87
- end
88
-
89
- body("/base").must_equal '-1|2|3|4|5|6|(1|2|3|4|5)'
90
- body("/override").must_equal '-1|-2|-3|0|-5|-6|(1|-2|3|-4|5)'
91
- body("/no_merge").must_equal '-1|2|-3|0|-5|6|(1|-2|3|-4|5)'
92
- end
93
- end
94
-
95
64
  describe "render plugin" do
96
65
  it "simple layout support" do
97
66
  app(:bare) do
@@ -144,21 +113,9 @@ describe "render plugin" do
144
113
  body.strip.must_equal "<title>Alternative Layout: Home</title>\n<h1>Home</h1>\n<p>Hello Agent Smith</p>"
145
114
  end
146
115
 
147
- deprecated "locals overrides" do
116
+ it ":layout=>true/false/string/hash/not-present respects plugin layout switch and template" do
148
117
  app(:bare) do
149
- plugin :render, :views=>"./spec/views", :locals=>{:title=>'Home', :b=>'B'}, :layout_opts=>{:template=>'multiple-layout', :locals=>{:title=>'Roda', :a=>'A'}}
150
-
151
- route do |r|
152
- view("multiple", :locals=>{:b=>"BB"}, :layout_opts=>{:locals=>{:a=>'AA'}})
153
- end
154
- end
155
-
156
- body.strip.must_equal "Roda:AA::Home:BB"
157
- end
158
-
159
- deprecated ":layout=>true/false/string/hash/not-present respects plugin layout switch and template" do
160
- app(:bare) do
161
- plugin :render, :views=>"./spec/views", :layout_opts=>{:template=>'layout-yield', :locals=>{:title=>'a'}}
118
+ plugin :render, :views=>"./spec/views", :layout_opts=>{:template=>'layout-yield'}
162
119
 
163
120
  route do |r|
164
121
  opts = {:content=>'bar'}
@@ -166,6 +123,7 @@ describe "render plugin" do
166
123
  opts[:layout] = false if r.path == '/f'
167
124
  opts[:layout] = 'layout' if r.path == '/s'
168
125
  opts[:layout] = {:template=>'layout'} if r.path == '/h'
126
+ opts[:layout_opts] = {:locals=>{:title=>'a'}}
169
127
  view(opts)
170
128
  end
171
129
  end
@@ -373,24 +331,24 @@ describe "render plugin" do
373
331
  app.render_opts[:explicit_cache].must_equal false
374
332
  end
375
333
 
376
- deprecated "Support :cache=>false plugin option to disable template caching, even when :cache=>true method option is given" do
334
+ it "Support :cache=>false plugin option to disable template caching by default, except :cache=>true method option is given" do
377
335
  app(:bare) do
378
336
  plugin :render, :views=>"./spec/views", :cache=>false
379
337
 
380
338
  route do |r|
381
339
  @a = 'a'
382
- r.is('a'){render('iv', :cache=>false)}
383
- r.is('b'){render('iv', :cache=>true)}
384
- render('iv')
340
+ r.is('a'){render('iv', :cache=>false, :cache_key=>:a)}
341
+ r.is('b'){render('iv', :cache=>true, :cache_key=>:a)}
342
+ render('iv', :cache_key=>:a)
385
343
  end
386
344
  end
387
345
 
388
346
  body('/a').strip.must_equal "a"
389
- app.render_opts[:cache].must_equal false
347
+ app.render_opts[:cache][:a].must_be_nil
390
348
  body('/b').strip.must_equal "a"
391
- app.render_opts[:cache].must_equal false
349
+ app.render_opts[:cache][:a].wont_be_nil
392
350
  body('/c').strip.must_equal "a"
393
- app.render_opts[:cache].must_equal false
351
+ app.render_opts[:cache][:a].wont_be_nil
394
352
  end
395
353
 
396
354
  it "Support :cache=>false option to disable template caching" do
@@ -519,20 +477,17 @@ describe "render plugin" do
519
477
  body.must_equal "1-2"
520
478
  end
521
479
 
522
- it "should dup render_opts when subclasses, including an empty cache" do
480
+ it "should dup render_opts when subclassing" do
523
481
  c = Class.new(Roda)
524
- c.plugin :render
525
- c.render_opts[:cache][:foo] = 1
482
+ c.plugin :render, :foo=>:bar
526
483
  sc = Class.new(c)
527
-
528
484
  c.render_opts.wont_be_same_as(sc.render_opts)
529
- c.render_opts[:cache].wont_be_same_as(sc.render_opts[:cache])
530
- sc.render_opts[:cache][:foo].must_be_nil
485
+ c.render_opts[:foo].must_equal :bar
531
486
  end
532
487
 
533
- it "should use a copy of superclass's cache when inheriting if :inherit_cache option is used" do
488
+ it "should use a copy of superclass's cache when subclassing" do
534
489
  c = Class.new(Roda)
535
- c.plugin :render, :inherit_cache=>true
490
+ c.plugin :render
536
491
  c.render_opts[:cache][:foo] = 1
537
492
  sc = Class.new(c)
538
493
 
@@ -545,13 +500,17 @@ describe "render plugin" do
545
500
  c = Class.new(Roda)
546
501
  c.plugin :render
547
502
  cache = c.render_opts[:cache]
503
+ c.render_opts[:explicit_cache].must_equal false
548
504
  c.plugin :render
549
505
  c.render_opts[:cache].must_be_same_as cache
506
+ c.render_opts[:explicit_cache].must_equal false
550
507
 
551
508
  c.plugin :render, :cache=>false
552
- c.render_opts[:cache].must_equal false
509
+ c.render_opts[:cache].must_be_same_as cache
510
+ c.render_opts[:explicit_cache].must_equal true
553
511
  c.plugin :render
554
- c.render_opts[:cache].must_equal false
512
+ c.render_opts[:cache].must_be_same_as cache
513
+ c.render_opts[:explicit_cache].must_equal true
555
514
  end
556
515
 
557
516
  it "render plugin call should not override existing options" do
@@ -561,18 +520,17 @@ describe "render plugin" do
561
520
  c.render_opts[:layout].must_equal :foo
562
521
  end
563
522
 
564
- it "should not use cache in subclass if caching disabled in superclass" do
523
+ it "should not use cache by default in subclass if not caching by default in superclass" do
565
524
  app(:bare) do
566
525
  plugin :render, :views=>"./spec/views", :cache=>false
567
526
 
568
527
  route do |r|
569
- view(:inline=>"Hello <%= name %>: <%= render_opts[:cache] %>", :locals=>{:name => "Agent Smith"}, :layout=>nil)
528
+ view(:inline=>"Hello <%= name %>", :cache_key=>:a, :locals=>{:name => "Agent Smith"}, :layout=>nil)
570
529
  end
571
530
  end
572
531
 
573
- body("/inline").strip.must_equal "Hello Agent Smith: false"
574
-
575
- Class.new(app).render_opts[:cache].must_equal false
532
+ body("/inline").strip.must_equal "Hello Agent Smith"
533
+ Class.new(app).render_opts[:cache][:a].must_be_nil
576
534
  end
577
535
 
578
536
  it "with :check_paths=>true plugin option used" do
@@ -630,50 +588,6 @@ describe "render plugin" do
630
588
  req("/c")
631
589
  end
632
590
 
633
- deprecated "with :check_paths plugin option not set" do
634
- render_opts = {}
635
- app(:bare) do
636
- plugin :render, :views=>"./spec/views"
637
-
638
- route do |r|
639
- r.get 'a' do
640
- render("a", render_opts)
641
- end
642
-
643
- r.get 'c' do
644
- render("about/_test", :locals=>{:title=>'a'})
645
- end
646
-
647
- render("b", render_opts)
648
- end
649
- end
650
-
651
- body.strip.must_equal "b"
652
- body("/a").strip.must_equal 'a'
653
- body("/c").strip.must_equal "<h1>Subdir: a</h1>"
654
-
655
- app.plugin :render, :allowed_paths=>[]
656
- body.strip.must_equal "b"
657
- body("/a").strip.must_equal 'a'
658
- body("/c").strip.must_equal "<h1>Subdir: a</h1>"
659
-
660
- app.plugin :render, :allowed_paths=>['spec/views/about']
661
- body.strip.must_equal "b"
662
- body("/a").strip.must_equal 'a'
663
- body("/c").strip.must_equal "<h1>Subdir: a</h1>"
664
-
665
- app.plugin :render, :allowed_paths=>%w'spec/views/about spec/views/b'
666
- body.strip.must_equal "b"
667
- body("/a").strip.must_equal 'a'
668
- body("/c").strip.must_equal "<h1>Subdir: a</h1>"
669
-
670
- render_opts[:check_paths] = true
671
- app.plugin :render, :check_paths=>false
672
- body.strip.must_equal "b"
673
- proc{req("/a")}.must_raise Roda::RodaError
674
- body("/c").strip.must_equal "<h1>Subdir: a</h1>"
675
- end
676
-
677
591
  it "with a cache_class set" do
678
592
  app(:bare) do
679
593
  test_cache = Class.new(Roda::RodaCache) do
@@ -706,9 +620,9 @@ begin
706
620
  require 'tilt'
707
621
  require 'tilt/erubi'
708
622
  rescue LoadError
709
- warn "tilt 2 or erubi not installed, skipping render :escape=>:erubi test"
623
+ warn "tilt 2 or erubi not installed, skipping render :escape=>true test"
710
624
  else
711
- describe "_erubis_escaping plugin" do
625
+ describe ":render plugin :escape option" do
712
626
  before do
713
627
  if defined?(Tilt::ErubiTemplate) && ::Tilt['erb'] != Tilt::ErubiTemplate
714
628
  # Set erubi as default erb template handler