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.
- checksums.yaml +4 -4
- data/CHANGELOG +52 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +51 -109
- data/Rakefile +7 -14
- data/doc/conventions.rdoc +4 -4
- data/doc/release_notes/1.2.0.txt +1 -1
- data/doc/release_notes/3.0.0.txt +84 -0
- data/lib/roda.rb +25 -79
- data/lib/roda/plugins/assets.rb +25 -58
- data/lib/roda/plugins/assets_preloading.rb +0 -5
- data/lib/roda/plugins/backtracking_array.rb +0 -5
- data/lib/roda/plugins/branch_locals.rb +3 -3
- data/lib/roda/plugins/caching.rb +5 -38
- data/lib/roda/plugins/chunked.rb +7 -25
- data/lib/roda/plugins/class_level_routing.rb +2 -2
- data/lib/roda/plugins/content_for.rb +7 -10
- data/lib/roda/plugins/cookies.rb +3 -3
- data/lib/roda/plugins/csrf.rb +2 -2
- data/lib/roda/plugins/delegate.rb +3 -3
- data/lib/roda/plugins/drop_body.rb +0 -7
- data/lib/roda/plugins/empty_root.rb +0 -3
- data/lib/roda/plugins/error_email.rb +4 -6
- data/lib/roda/plugins/error_handler.rb +1 -2
- data/lib/roda/plugins/error_mail.rb +3 -6
- data/lib/roda/plugins/flash.rb +0 -4
- data/lib/roda/plugins/h.rb +5 -0
- data/lib/roda/plugins/hash_matcher.rb +4 -2
- data/lib/roda/plugins/head.rb +5 -7
- data/lib/roda/plugins/header_matchers.rb +12 -33
- data/lib/roda/plugins/heartbeat.rb +2 -7
- data/lib/roda/plugins/indifferent_params.rb +2 -2
- data/lib/roda/plugins/json.rb +6 -14
- data/lib/roda/plugins/json_parser.rb +2 -13
- data/lib/roda/plugins/mailer.rb +29 -39
- data/lib/roda/plugins/match_affix.rb +0 -5
- data/lib/roda/plugins/middleware.rb +10 -15
- data/lib/roda/plugins/multi_route.rb +8 -5
- data/lib/roda/plugins/multi_run.rb +1 -0
- data/lib/roda/plugins/named_templates.rb +2 -2
- data/lib/roda/plugins/optimized_string_matchers.rb +0 -3
- data/lib/roda/plugins/padrino_render.rb +6 -9
- data/lib/roda/plugins/param_matchers.rb +6 -6
- data/lib/roda/plugins/params_capturing.rb +15 -35
- data/lib/roda/plugins/partials.rb +3 -8
- data/lib/roda/plugins/path.rb +5 -5
- data/lib/roda/plugins/path_matchers.rb +3 -3
- data/lib/roda/plugins/path_rewriter.rb +4 -9
- data/lib/roda/plugins/placeholder_string_matchers.rb +1 -1
- data/lib/roda/plugins/precompile_templates.rb +10 -20
- data/lib/roda/plugins/public.rb +6 -9
- data/lib/roda/plugins/render.rb +50 -171
- data/lib/roda/plugins/render_each.rb +4 -7
- data/lib/roda/plugins/render_locals.rb +6 -20
- data/lib/roda/plugins/request_headers.rb +2 -4
- data/lib/roda/plugins/run_append_slash.rb +1 -4
- data/lib/roda/plugins/run_handler.rb +4 -7
- data/lib/roda/plugins/shared_vars.rb +3 -6
- data/lib/roda/plugins/sinatra_helpers.rb +11 -40
- data/lib/roda/plugins/slash_path_empty.rb +0 -3
- data/lib/roda/plugins/static.rb +2 -2
- data/lib/roda/plugins/static_routing.rb +2 -3
- data/lib/roda/plugins/streaming.rb +15 -108
- data/lib/roda/plugins/strip_path_prefix.rb +1 -1
- data/lib/roda/plugins/symbol_matchers.rb +7 -23
- data/lib/roda/plugins/type_routing.rb +4 -9
- data/lib/roda/plugins/view_options.rb +10 -66
- data/lib/roda/version.rb +2 -2
- data/spec/all.rb +0 -2
- data/spec/composition_spec.rb +1 -1
- data/spec/env_spec.rb +1 -1
- data/spec/freeze_spec.rb +1 -1
- data/spec/integration_spec.rb +1 -1
- data/spec/matchers_spec.rb +26 -70
- data/spec/opts_spec.rb +1 -1
- data/spec/plugin/all_verbs_spec.rb +1 -1
- data/spec/plugin/assets_preloading_spec.rb +1 -1
- data/spec/plugin/assets_spec.rb +43 -27
- data/spec/plugin/backtracking_array_spec.rb +1 -1
- data/spec/plugin/branch_locals_spec.rb +1 -1
- data/spec/plugin/caching_spec.rb +1 -1
- data/spec/plugin/chunked_spec.rb +1 -1
- data/spec/plugin/class_level_routing_spec.rb +1 -1
- data/spec/plugin/class_matchers_spec.rb +1 -1
- data/spec/plugin/content_for_spec.rb +2 -7
- data/spec/plugin/cookies_spec.rb +1 -1
- data/spec/plugin/csrf_spec.rb +1 -1
- data/spec/plugin/default_headers_spec.rb +1 -1
- data/spec/plugin/default_status_spec.rb +1 -1
- data/spec/plugin/delay_build_spec.rb +1 -1
- data/spec/plugin/delegate_spec.rb +1 -1
- data/spec/plugin/delete_empty_headers_spec.rb +1 -1
- data/spec/plugin/disallow_file_uploads_spec.rb +2 -2
- data/spec/plugin/drop_body_spec.rb +1 -1
- data/spec/plugin/empty_root_spec.rb +1 -1
- data/spec/plugin/environments_spec.rb +1 -1
- data/spec/plugin/error_email_spec.rb +1 -1
- data/spec/plugin/error_handler_spec.rb +1 -1
- data/spec/plugin/error_mail_spec.rb +2 -2
- data/spec/plugin/flash_spec.rb +1 -1
- data/spec/plugin/h_spec.rb +1 -1
- data/spec/plugin/halt_spec.rb +2 -2
- data/spec/plugin/hash_matcher_spec.rb +1 -1
- data/spec/plugin/head_spec.rb +1 -1
- data/spec/plugin/header_matchers_spec.rb +4 -47
- data/spec/plugin/heartbeat_spec.rb +1 -1
- data/spec/plugin/hooks_spec.rb +1 -1
- data/spec/plugin/indifferent_params_spec.rb +1 -1
- data/spec/plugin/json_parser_spec.rb +12 -1
- data/spec/plugin/json_spec.rb +8 -1
- data/spec/plugin/mailer_spec.rb +1 -1
- data/spec/plugin/match_affix_spec.rb +1 -1
- data/spec/plugin/middleware_spec.rb +15 -1
- data/spec/plugin/module_include_spec.rb +1 -1
- data/spec/plugin/multi_route_spec.rb +5 -3
- data/spec/plugin/multi_run_spec.rb +1 -1
- data/spec/plugin/multi_view_spec.rb +1 -1
- data/spec/plugin/named_templates_spec.rb +1 -1
- data/spec/plugin/not_allowed_spec.rb +1 -1
- data/spec/plugin/not_found_spec.rb +1 -1
- data/spec/plugin/optimized_string_matchers_spec.rb +1 -1
- data/spec/plugin/padrino_render_spec.rb +1 -1
- data/spec/plugin/param_matchers_spec.rb +1 -1
- data/spec/plugin/params_capturing_spec.rb +6 -22
- data/spec/plugin/partials_spec.rb +1 -1
- data/spec/plugin/pass_spec.rb +1 -1
- data/spec/plugin/path_matchers_spec.rb +1 -1
- data/spec/plugin/path_rewriter_spec.rb +1 -1
- data/spec/plugin/path_spec.rb +1 -1
- data/spec/plugin/placeholder_string_matchers_spec.rb +3 -36
- data/spec/plugin/precompile_templates_spec.rb +1 -17
- data/spec/plugin/public_spec.rb +3 -4
- data/spec/plugin/render_each_spec.rb +1 -1
- data/spec/plugin/render_locals_spec.rb +1 -1
- data/spec/plugin/render_spec.rb +28 -114
- data/spec/plugin/request_headers_spec.rb +1 -1
- data/spec/plugin/response_request_spec.rb +1 -1
- data/spec/plugin/run_append_slash_spec.rb +1 -1
- data/spec/plugin/run_handler_spec.rb +1 -1
- data/spec/plugin/shared_vars_spec.rb +1 -1
- data/spec/plugin/sinatra_helpers_spec.rb +1 -1
- data/spec/plugin/slash_path_empty_spec.rb +1 -1
- data/spec/plugin/static_routing_spec.rb +1 -1
- data/spec/plugin/static_spec.rb +1 -1
- data/spec/plugin/status_303_spec.rb +1 -1
- data/spec/plugin/status_handler_spec.rb +1 -1
- data/spec/plugin/streaming_spec.rb +1 -106
- data/spec/plugin/strip_path_prefix_spec.rb +1 -1
- data/spec/plugin/symbol_matchers_spec.rb +1 -77
- data/spec/plugin/symbol_status_spec.rb +1 -1
- data/spec/plugin/symbol_views_spec.rb +1 -1
- data/spec/plugin/type_routing_spec.rb +1 -1
- data/spec/plugin/unescape_path_spec.rb +1 -1
- data/spec/plugin/view_options_spec.rb +16 -110
- data/spec/plugin_spec.rb +1 -1
- data/spec/redirect_spec.rb +1 -1
- data/spec/request_spec.rb +1 -1
- data/spec/response_spec.rb +1 -1
- data/spec/session_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -3
- data/spec/version_spec.rb +1 -1
- metadata +6 -26
- data/lib/roda/plugins/_erubis_escaping.rb +0 -59
- data/lib/roda/plugins/per_thread_caching.rb +0 -71
- data/lib/roda/plugins/static_path_info.rb +0 -12
- data/lib/roda/plugins/view_subdirs.rb +0 -7
- data/lib/roda/plugins/websockets.rb +0 -107
- data/spec/plugin/_erubis_escaping_spec.rb +0 -97
- data/spec/plugin/per_thread_caching_spec.rb +0 -28
- data/spec/plugin/websockets_spec.rb +0 -84
data/spec/plugin/hooks_spec.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
data/spec/plugin/json_spec.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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'
|
data/spec/plugin/mailer_spec.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
180
|
+
proc{body}.must_raise Roda::RodaError
|
|
181
|
+
proc{body('/a')}.must_raise Roda::RodaError
|
|
180
182
|
end
|
|
181
183
|
end
|
|
182
184
|
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
|
|
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[
|
|
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[
|
|
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[
|
|
16
|
+
"y-#{r.params['y']}-#{r.params['x']}-#{q}-#{y}-#{x}-#{r.params['captures'].length}"
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
"y-#{r[
|
|
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[
|
|
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
|
data/spec/plugin/pass_spec.rb
CHANGED
data/spec/plugin/path_spec.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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[
|
|
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[
|
|
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
|
-
|
|
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'
|
data/spec/plugin/public_spec.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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.
|
|
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'
|
data/spec/plugin/render_spec.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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", :
|
|
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
|
-
|
|
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].
|
|
347
|
+
app.render_opts[:cache][:a].must_be_nil
|
|
390
348
|
body('/b').strip.must_equal "a"
|
|
391
|
-
app.render_opts[:cache].
|
|
349
|
+
app.render_opts[:cache][:a].wont_be_nil
|
|
392
350
|
body('/c').strip.must_equal "a"
|
|
393
|
-
app.render_opts[:cache].
|
|
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
|
|
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[:
|
|
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
|
|
488
|
+
it "should use a copy of superclass's cache when subclassing" do
|
|
534
489
|
c = Class.new(Roda)
|
|
535
|
-
c.plugin :render
|
|
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].
|
|
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].
|
|
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
|
|
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
|
|
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
|
|
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
|
|
623
|
+
warn "tilt 2 or erubi not installed, skipping render :escape=>true test"
|
|
710
624
|
else
|
|
711
|
-
describe "
|
|
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
|