roda 3.28.0 → 3.29.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +10 -0
- data/README.rdoc +10 -0
- data/doc/release_notes/3.29.0.txt +15 -0
- data/lib/roda.rb +1 -0
- data/lib/roda/plugins/caching.rb +2 -0
- data/lib/roda/plugins/common_logger.rb +1 -1
- data/lib/roda/plugins/exception_page.rb +7 -1
- data/lib/roda/plugins/indifferent_params.rb +2 -0
- data/lib/roda/version.rb +1 -1
- metadata +4 -214
- data/Rakefile +0 -108
- data/doc/release_notes/1.0.0.txt +0 -329
- data/doc/release_notes/1.1.0.txt +0 -226
- data/doc/release_notes/1.2.0.txt +0 -406
- data/doc/release_notes/1.3.0.txt +0 -109
- data/doc/release_notes/2.0.0.txt +0 -75
- data/doc/release_notes/2.1.0.txt +0 -124
- data/doc/release_notes/2.10.0.txt +0 -27
- data/doc/release_notes/2.11.0.txt +0 -70
- data/doc/release_notes/2.12.0.txt +0 -40
- data/doc/release_notes/2.13.0.txt +0 -10
- data/doc/release_notes/2.14.0.txt +0 -44
- data/doc/release_notes/2.15.0.txt +0 -53
- data/doc/release_notes/2.16.0.txt +0 -48
- data/doc/release_notes/2.17.0.txt +0 -62
- data/doc/release_notes/2.18.0.txt +0 -69
- data/doc/release_notes/2.19.0.txt +0 -30
- data/doc/release_notes/2.2.0.txt +0 -97
- data/doc/release_notes/2.20.0.txt +0 -5
- data/doc/release_notes/2.21.0.txt +0 -17
- data/doc/release_notes/2.22.0.txt +0 -41
- data/doc/release_notes/2.23.0.txt +0 -29
- data/doc/release_notes/2.24.0.txt +0 -65
- data/doc/release_notes/2.25.0.txt +0 -14
- data/doc/release_notes/2.26.0.txt +0 -13
- data/doc/release_notes/2.27.0.txt +0 -56
- data/doc/release_notes/2.28.0.txt +0 -17
- data/doc/release_notes/2.29.0.txt +0 -156
- data/doc/release_notes/2.3.0.txt +0 -109
- data/doc/release_notes/2.4.0.txt +0 -55
- data/doc/release_notes/2.5.0.txt +0 -23
- data/doc/release_notes/2.5.1.txt +0 -4
- data/doc/release_notes/2.6.0.txt +0 -21
- data/doc/release_notes/2.7.0.txt +0 -75
- data/doc/release_notes/2.8.0.txt +0 -44
- data/doc/release_notes/2.9.0.txt +0 -6
- data/spec/all.rb +0 -1
- data/spec/assets/css/app.scss +0 -1
- data/spec/assets/css/no_access.css +0 -1
- data/spec/assets/css/raw.css +0 -1
- data/spec/assets/js/head/app.js +0 -1
- data/spec/composition_spec.rb +0 -31
- data/spec/define_roda_method_spec.rb +0 -274
- data/spec/env_spec.rb +0 -11
- data/spec/freeze_spec.rb +0 -37
- data/spec/integration_spec.rb +0 -209
- data/spec/matchers_spec.rb +0 -832
- data/spec/opts_spec.rb +0 -42
- data/spec/plugin/_after_hook_spec.rb +0 -19
- data/spec/plugin/all_verbs_spec.rb +0 -29
- data/spec/plugin/assets_preloading_spec.rb +0 -98
- data/spec/plugin/assets_spec.rb +0 -745
- data/spec/plugin/backtracking_array_spec.rb +0 -42
- data/spec/plugin/branch_locals_spec.rb +0 -106
- data/spec/plugin/caching_spec.rb +0 -337
- data/spec/plugin/chunked_spec.rb +0 -201
- data/spec/plugin/class_level_routing_spec.rb +0 -164
- data/spec/plugin/class_matchers_spec.rb +0 -40
- data/spec/plugin/common_logger_spec.rb +0 -85
- data/spec/plugin/content_for_spec.rb +0 -162
- data/spec/plugin/content_security_policy_spec.rb +0 -175
- data/spec/plugin/cookies_spec.rb +0 -51
- data/spec/plugin/csrf_spec.rb +0 -111
- data/spec/plugin/default_headers_spec.rb +0 -82
- data/spec/plugin/default_status_spec.rb +0 -95
- data/spec/plugin/delay_build_spec.rb +0 -23
- data/spec/plugin/delegate_spec.rb +0 -23
- data/spec/plugin/delete_empty_headers_spec.rb +0 -27
- data/spec/plugin/direct_call_spec.rb +0 -28
- data/spec/plugin/disallow_file_uploads_spec.rb +0 -25
- data/spec/plugin/drop_body_spec.rb +0 -24
- data/spec/plugin/early_hints_spec.rb +0 -19
- data/spec/plugin/empty_root_spec.rb +0 -14
- data/spec/plugin/environments_spec.rb +0 -42
- data/spec/plugin/error_email_spec.rb +0 -97
- data/spec/plugin/error_handler_spec.rb +0 -216
- data/spec/plugin/error_mail_spec.rb +0 -93
- data/spec/plugin/exception_page_spec.rb +0 -168
- data/spec/plugin/flash_spec.rb +0 -121
- data/spec/plugin/h_spec.rb +0 -11
- data/spec/plugin/halt_spec.rb +0 -119
- data/spec/plugin/hash_matcher_spec.rb +0 -27
- data/spec/plugin/hash_routes_spec.rb +0 -535
- data/spec/plugin/head_spec.rb +0 -52
- data/spec/plugin/header_matchers_spec.rb +0 -98
- data/spec/plugin/heartbeat_spec.rb +0 -74
- data/spec/plugin/hooks_spec.rb +0 -152
- data/spec/plugin/indifferent_params_spec.rb +0 -14
- data/spec/plugin/json_parser_spec.rb +0 -141
- data/spec/plugin/json_spec.rb +0 -83
- data/spec/plugin/mail_processor_spec.rb +0 -451
- data/spec/plugin/mailer_spec.rb +0 -282
- data/spec/plugin/match_affix_spec.rb +0 -43
- data/spec/plugin/match_hook_spec.rb +0 -79
- data/spec/plugin/middleware_spec.rb +0 -237
- data/spec/plugin/middleware_stack_spec.rb +0 -81
- data/spec/plugin/module_include_spec.rb +0 -48
- data/spec/plugin/multi_route_spec.rb +0 -268
- data/spec/plugin/multi_run_spec.rb +0 -87
- data/spec/plugin/multi_view_spec.rb +0 -50
- data/spec/plugin/multibyte_string_matcher_spec.rb +0 -44
- data/spec/plugin/named_templates_spec.rb +0 -96
- data/spec/plugin/not_allowed_spec.rb +0 -69
- data/spec/plugin/not_found_spec.rb +0 -128
- data/spec/plugin/optimized_string_matchers_spec.rb +0 -43
- data/spec/plugin/padrino_render_spec.rb +0 -34
- data/spec/plugin/param_matchers_spec.rb +0 -69
- data/spec/plugin/params_capturing_spec.rb +0 -33
- data/spec/plugin/partials_spec.rb +0 -43
- data/spec/plugin/pass_spec.rb +0 -29
- data/spec/plugin/path_matchers_spec.rb +0 -42
- data/spec/plugin/path_rewriter_spec.rb +0 -45
- data/spec/plugin/path_spec.rb +0 -222
- data/spec/plugin/placeholder_string_matchers_spec.rb +0 -126
- data/spec/plugin/precompile_templates_spec.rb +0 -61
- data/spec/plugin/public_spec.rb +0 -85
- data/spec/plugin/render_each_spec.rb +0 -82
- data/spec/plugin/render_locals_spec.rb +0 -114
- data/spec/plugin/render_spec.rb +0 -912
- data/spec/plugin/request_aref_spec.rb +0 -51
- data/spec/plugin/request_headers_spec.rb +0 -39
- data/spec/plugin/response_request_spec.rb +0 -43
- data/spec/plugin/route_block_args_spec.rb +0 -86
- data/spec/plugin/route_csrf_spec.rb +0 -305
- data/spec/plugin/run_append_slash_spec.rb +0 -77
- data/spec/plugin/run_handler_spec.rb +0 -53
- data/spec/plugin/sessions_spec.rb +0 -452
- data/spec/plugin/shared_vars_spec.rb +0 -45
- data/spec/plugin/sinatra_helpers_spec.rb +0 -537
- data/spec/plugin/slash_path_empty_spec.rb +0 -22
- data/spec/plugin/static_routing_spec.rb +0 -192
- data/spec/plugin/static_spec.rb +0 -30
- data/spec/plugin/status_303_spec.rb +0 -28
- data/spec/plugin/status_handler_spec.rb +0 -158
- data/spec/plugin/streaming_spec.rb +0 -246
- data/spec/plugin/strip_path_prefix_spec.rb +0 -24
- data/spec/plugin/symbol_matchers_spec.rb +0 -51
- data/spec/plugin/symbol_status_spec.rb +0 -25
- data/spec/plugin/symbol_views_spec.rb +0 -32
- data/spec/plugin/timestamp_public_spec.rb +0 -85
- data/spec/plugin/type_routing_spec.rb +0 -348
- data/spec/plugin/typecast_params_spec.rb +0 -1370
- data/spec/plugin/unescape_path_spec.rb +0 -22
- data/spec/plugin/view_options_spec.rb +0 -170
- data/spec/plugin_spec.rb +0 -71
- data/spec/redirect_spec.rb +0 -41
- data/spec/request_spec.rb +0 -97
- data/spec/response_spec.rb +0 -199
- data/spec/route_spec.rb +0 -39
- data/spec/session_middleware_spec.rb +0 -129
- data/spec/session_spec.rb +0 -37
- data/spec/spec_helper.rb +0 -137
- data/spec/version_spec.rb +0 -14
- data/spec/views/_test.erb +0 -1
- data/spec/views/a.erb +0 -1
- data/spec/views/a.rdoc +0 -2
- data/spec/views/about.erb +0 -1
- data/spec/views/about.str +0 -1
- data/spec/views/about/_test.css.gz +0 -0
- data/spec/views/about/_test.erb +0 -1
- data/spec/views/about/_test.erb.gz +0 -0
- data/spec/views/about/comp_test.erb +0 -1
- data/spec/views/b.erb +0 -1
- data/spec/views/c.erb +0 -1
- data/spec/views/comp_layout.erb +0 -1
- data/spec/views/comp_test.erb +0 -1
- data/spec/views/content-yield.erb +0 -1
- data/spec/views/each.str +0 -1
- data/spec/views/home.erb +0 -2
- data/spec/views/home.str +0 -2
- data/spec/views/iv.erb +0 -1
- data/spec/views/layout-alternative.erb +0 -2
- data/spec/views/layout-yield.erb +0 -3
- data/spec/views/layout.erb +0 -2
- data/spec/views/layout.str +0 -2
- data/spec/views/multiple-layout.erb +0 -1
- data/spec/views/multiple.erb +0 -1
data/spec/plugin/chunked_spec.rb
DELETED
@@ -1,201 +0,0 @@
|
|
1
|
-
require_relative "../spec_helper"
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'tilt/erb'
|
5
|
-
rescue LoadError
|
6
|
-
warn "tilt not installed, skipping chunked plugin test"
|
7
|
-
else
|
8
|
-
describe "chunked plugin" do
|
9
|
-
def cbody(env={})
|
10
|
-
body({'HTTP_VERSION'=>'HTTP/1.1'}.merge(env))
|
11
|
-
end
|
12
|
-
|
13
|
-
it "streams templates in chunked encoding only if HTTP 1.1 is used" do
|
14
|
-
app(:chunked) do |r|
|
15
|
-
chunked(:inline=>'m', :layout=>{:inline=>'h<%= yield %>t'})
|
16
|
-
end
|
17
|
-
|
18
|
-
cbody.must_equal "1\r\nh\r\n1\r\nm\r\n1\r\nt\r\n0\r\n\r\n"
|
19
|
-
body.must_equal "hmt"
|
20
|
-
end
|
21
|
-
|
22
|
-
it "hex encodes chunk sizes" do
|
23
|
-
m = 'm' * 31
|
24
|
-
app(:chunked) do |r|
|
25
|
-
chunked(:inline=>m.dup, :layout=>{:inline=>'h<%= yield %>t'})
|
26
|
-
end
|
27
|
-
|
28
|
-
cbody.must_equal "1\r\nh\r\n1f\r\n#{m}\r\n1\r\nt\r\n0\r\n\r\n"
|
29
|
-
body.must_equal "h#{m}t"
|
30
|
-
end
|
31
|
-
|
32
|
-
it "accepts a block that is called after layout yielding but before content when streaming" do
|
33
|
-
app(:chunked) do |r|
|
34
|
-
@h = nil
|
35
|
-
chunked(:inline=>'m<%= @h %>', :layout=>{:inline=>'<%= @h %><%= yield %>t'}) do
|
36
|
-
@h = 'h'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
cbody.must_equal "2\r\nmh\r\n1\r\nt\r\n0\r\n\r\n"
|
41
|
-
body.must_equal "hmht"
|
42
|
-
end
|
43
|
-
|
44
|
-
it "has delay accept block that is called after layout yielding but before content when streaming" do
|
45
|
-
app(:chunked) do |r|
|
46
|
-
delay do
|
47
|
-
@h << 'i'
|
48
|
-
end
|
49
|
-
@h = String.new('h')
|
50
|
-
chunked(:inline=>'m<%= @h %>', :layout=>{:inline=>'<%= @h %><%= yield %>t'}) do
|
51
|
-
@h << 'j'
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
cbody.must_equal "1\r\nh\r\n4\r\nmhij\r\n1\r\nt\r\n0\r\n\r\n"
|
56
|
-
body.must_equal "hijmhijt"
|
57
|
-
end
|
58
|
-
|
59
|
-
it "has delay raise if not given a block" do
|
60
|
-
app(:chunked){|r| delay}
|
61
|
-
proc{body}.must_raise(Roda::RodaError)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "works when a layout is not used" do
|
65
|
-
app(:chunked) do |r|
|
66
|
-
chunked(:inline=>'m', :layout=>nil)
|
67
|
-
end
|
68
|
-
|
69
|
-
cbody.must_equal "1\r\nm\r\n0\r\n\r\n"
|
70
|
-
body.must_equal "m"
|
71
|
-
end
|
72
|
-
|
73
|
-
it "streams partial template responses if flush is used in content template" do
|
74
|
-
app(:chunked) do |r|
|
75
|
-
chunked(:inline=>'m<%= flush %>n', :layout=>{:inline=>'h<%= yield %>t'})
|
76
|
-
end
|
77
|
-
|
78
|
-
cbody.must_equal "1\r\nh\r\n1\r\nm\r\n1\r\nn\r\n1\r\nt\r\n0\r\n\r\n"
|
79
|
-
body.must_equal "hmnt"
|
80
|
-
end
|
81
|
-
|
82
|
-
it "streams partial template responses if flush is used in layout template" do
|
83
|
-
app(:chunked) do |r|
|
84
|
-
chunked(:inline=>'m', :layout=>{:inline=>'h<%= flush %>i<%= yield %>t'})
|
85
|
-
end
|
86
|
-
|
87
|
-
cbody.must_equal "1\r\nh\r\n1\r\ni\r\n1\r\nm\r\n1\r\nt\r\n0\r\n\r\n"
|
88
|
-
body.must_equal "himt"
|
89
|
-
end
|
90
|
-
|
91
|
-
it "does not stream if no_chunk! is used" do
|
92
|
-
app(:chunked) do |r|
|
93
|
-
no_chunk!
|
94
|
-
chunked(:inline=>'m', :layout=>{:inline=>'h<%= yield %>t'})
|
95
|
-
end
|
96
|
-
|
97
|
-
cbody.must_equal "hmt"
|
98
|
-
body.must_equal "hmt"
|
99
|
-
end
|
100
|
-
|
101
|
-
it "streams existing response body before call" do
|
102
|
-
app(:chunked) do |r|
|
103
|
-
response.write('a')
|
104
|
-
response.write chunked(:inline=>'m', :layout=>{:inline=>'h<%= yield %>t'})
|
105
|
-
end
|
106
|
-
|
107
|
-
cbody.must_equal "1\r\na\r\n1\r\nh\r\n1\r\nm\r\n1\r\nt\r\n0\r\n\r\n"
|
108
|
-
body.must_equal "ahmt"
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should not include Content-Length header even if body is already written to" do
|
112
|
-
app(:chunked) do |r|
|
113
|
-
response.write('a')
|
114
|
-
response.write chunked(:inline=>'m', :layout=>{:inline=>'h<%= yield %>t'})
|
115
|
-
end
|
116
|
-
|
117
|
-
header('Content-Length', 'HTTP_VERSION'=>'HTTP/1.1').must_be_nil
|
118
|
-
header('Content-Length', 'HTTP_VERSION'=>'HTTP/1.0').must_equal '4'
|
119
|
-
end
|
120
|
-
|
121
|
-
it "stream template responses for view if :chunk_by_default is used" do
|
122
|
-
app(:bare) do
|
123
|
-
plugin :chunked, :chunk_by_default=>true
|
124
|
-
route do |r|
|
125
|
-
view(:inline=>'m', :layout=>{:inline=>'h<%= yield %>t'})
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
cbody.must_equal "1\r\nh\r\n1\r\nm\r\n1\r\nt\r\n0\r\n\r\n"
|
130
|
-
body.must_equal "hmt"
|
131
|
-
end
|
132
|
-
|
133
|
-
it "uses Transfer-Encoding header when chunking" do
|
134
|
-
app(:chunked) do |r|
|
135
|
-
chunked(:inline=>'m', :layout=>{:inline=>'h<%= yield %>t'})
|
136
|
-
end
|
137
|
-
|
138
|
-
header('Transfer-Encoding', 'HTTP_VERSION'=>'HTTP/1.1').must_equal 'chunked'
|
139
|
-
header('Transfer-Encoding', 'HTTP_VERSION'=>'HTTP/1.0').must_be_nil
|
140
|
-
end
|
141
|
-
|
142
|
-
it "uses given :headers when chunking" do
|
143
|
-
app(:bare) do
|
144
|
-
plugin :chunked, :headers=>{'Foo'=>'bar'}
|
145
|
-
route do |r|
|
146
|
-
chunked(:inline=>'m', :layout=>{:inline=>'h<%= yield %>t'})
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
header('Foo', 'HTTP_VERSION'=>'HTTP/1.1').must_equal 'bar'
|
151
|
-
header('Foo', 'HTTP_VERSION'=>'HTTP/1.0').must_be_nil
|
152
|
-
end
|
153
|
-
|
154
|
-
it "handles multiple arguments to chunked" do
|
155
|
-
app(:bare) do
|
156
|
-
plugin :chunked, :chunk_by_default=>true
|
157
|
-
plugin :render, :views => "./spec/views"
|
158
|
-
route do |r|
|
159
|
-
chunked('about', :locals=>{:title=>'m'}, :layout=>{:inline=>'h<%= yield %>t'})
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
cbody.must_equal "1\r\nh\r\nb\r\n<h1>m</h1>\n\r\n1\r\nt\r\n0\r\n\r\n"
|
164
|
-
body.must_equal "h<h1>m</h1>\nt"
|
165
|
-
end
|
166
|
-
|
167
|
-
it "handles multiple hash arguments to chunked" do
|
168
|
-
app(:chunked) do |r|
|
169
|
-
chunked({:inline=>'m'}, :layout=>{:inline=>'h<%= yield %>t'})
|
170
|
-
end
|
171
|
-
|
172
|
-
cbody.must_equal "1\r\nh\r\n1\r\nm\r\n1\r\nt\r\n0\r\n\r\n"
|
173
|
-
body.must_equal "hmt"
|
174
|
-
end
|
175
|
-
|
176
|
-
it "handles :layout_opts option" do
|
177
|
-
app(:chunked) do |r|
|
178
|
-
chunked(:inline=>'m', :layout=>{:inline=>'<%= h %><%= yield %>t'}, :layout_opts=>{:locals=>{:h=>'h'}})
|
179
|
-
end
|
180
|
-
|
181
|
-
cbody.must_equal "1\r\nh\r\n1\r\nm\r\n1\r\nt\r\n0\r\n\r\n"
|
182
|
-
body.must_equal "hmt"
|
183
|
-
end
|
184
|
-
|
185
|
-
it "uses handle_chunk_error for handling errors when chunking" do
|
186
|
-
app(:chunked) do |r|
|
187
|
-
chunked(:inline=>'m', :layout=>{:inline=>'h<%= yield %><% raise %>'})
|
188
|
-
end
|
189
|
-
proc{cbody}.must_raise RuntimeError
|
190
|
-
proc{body}.must_raise RuntimeError
|
191
|
-
|
192
|
-
app.send(:define_method, :handle_chunk_error) do |v|
|
193
|
-
@_out_buf = 'e'
|
194
|
-
flush
|
195
|
-
end
|
196
|
-
|
197
|
-
cbody.must_equal "1\r\nh\r\n1\r\nm\r\n1\r\ne\r\n0\r\n\r\n"
|
198
|
-
proc{body}.must_raise RuntimeError
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
require_relative "../spec_helper"
|
2
|
-
|
3
|
-
describe "class_level_routing plugin" do
|
4
|
-
before do
|
5
|
-
app(:bare) do
|
6
|
-
plugin :class_level_routing
|
7
|
-
plugin :all_verbs
|
8
|
-
|
9
|
-
root do
|
10
|
-
'root'
|
11
|
-
end
|
12
|
-
|
13
|
-
on "foo" do
|
14
|
-
request.get "bar" do
|
15
|
-
"foobar"
|
16
|
-
end
|
17
|
-
|
18
|
-
"foo"
|
19
|
-
end
|
20
|
-
|
21
|
-
is "d", :d do |x|
|
22
|
-
request.get do
|
23
|
-
"bazget#{x}"
|
24
|
-
end
|
25
|
-
|
26
|
-
request.post do
|
27
|
-
"bazpost#{x}"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
meths = %w'get post delete head options patch put trace'
|
32
|
-
meths.concat(%w'link unlink') if ::Rack::Request.method_defined?("link?")
|
33
|
-
meths.each do |meth|
|
34
|
-
send(meth, :d) do |m|
|
35
|
-
"x-#{meth}-#{m}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
it "adds class methods for setting up routes" do
|
42
|
-
body.must_equal 'root'
|
43
|
-
body('/foo').must_equal 'foo'
|
44
|
-
body('/foo/bar').must_equal 'foobar'
|
45
|
-
body('/d/go').must_equal 'bazgetgo'
|
46
|
-
body('/d/go', 'REQUEST_METHOD'=>'POST').must_equal 'bazpostgo'
|
47
|
-
body('/bar').must_equal "x-get-bar"
|
48
|
-
body('/bar', 'REQUEST_METHOD'=>'POST').must_equal "x-post-bar"
|
49
|
-
body('/bar', 'REQUEST_METHOD'=>'DELETE').must_equal "x-delete-bar"
|
50
|
-
body('/bar', 'REQUEST_METHOD'=>'HEAD').must_equal "x-head-bar"
|
51
|
-
body('/bar', 'REQUEST_METHOD'=>'OPTIONS').must_equal "x-options-bar"
|
52
|
-
body('/bar', 'REQUEST_METHOD'=>'PATCH').must_equal "x-patch-bar"
|
53
|
-
body('/bar', 'REQUEST_METHOD'=>'PUT').must_equal "x-put-bar"
|
54
|
-
body('/bar', 'REQUEST_METHOD'=>'TRACE').must_equal "x-trace-bar"
|
55
|
-
if ::Rack::Request.method_defined?("link?")
|
56
|
-
body('/bar', 'REQUEST_METHOD'=>'LINK').must_equal "x-link-bar"
|
57
|
-
body('/bar', 'REQUEST_METHOD'=>'UNLINK').must_equal "x-unlink-bar"
|
58
|
-
end
|
59
|
-
|
60
|
-
status.must_equal 200
|
61
|
-
status("/asdfa/asdf").must_equal 404
|
62
|
-
|
63
|
-
@app = Class.new(app)
|
64
|
-
body.must_equal 'root'
|
65
|
-
body('/foo').must_equal 'foo'
|
66
|
-
body('/foo/bar').must_equal 'foobar'
|
67
|
-
body('/d/go').must_equal 'bazgetgo'
|
68
|
-
body('/d/go', 'REQUEST_METHOD'=>'POST').must_equal 'bazpostgo'
|
69
|
-
body('/bar').must_equal "x-get-bar"
|
70
|
-
body('/bar', 'REQUEST_METHOD'=>'POST').must_equal "x-post-bar"
|
71
|
-
body('/bar', 'REQUEST_METHOD'=>'DELETE').must_equal "x-delete-bar"
|
72
|
-
body('/bar', 'REQUEST_METHOD'=>'HEAD').must_equal "x-head-bar"
|
73
|
-
body('/bar', 'REQUEST_METHOD'=>'OPTIONS').must_equal "x-options-bar"
|
74
|
-
body('/bar', 'REQUEST_METHOD'=>'PATCH').must_equal "x-patch-bar"
|
75
|
-
body('/bar', 'REQUEST_METHOD'=>'PUT').must_equal "x-put-bar"
|
76
|
-
body('/bar', 'REQUEST_METHOD'=>'TRACE').must_equal "x-trace-bar"
|
77
|
-
end
|
78
|
-
|
79
|
-
it "only calls class level routes if routing tree doesn't handle request" do
|
80
|
-
app.route do |r|
|
81
|
-
r.root do
|
82
|
-
'iroot'
|
83
|
-
end
|
84
|
-
|
85
|
-
r.get 'foo' do
|
86
|
-
'ifoo'
|
87
|
-
end
|
88
|
-
|
89
|
-
r.on 'bar' do
|
90
|
-
r.get true do
|
91
|
-
response.status = 404
|
92
|
-
''
|
93
|
-
end
|
94
|
-
r.post true do
|
95
|
-
'ibar'
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
body.must_equal 'iroot'
|
101
|
-
body('/foo').must_equal 'ifoo'
|
102
|
-
body('/foo/bar').must_equal 'foobar'
|
103
|
-
body('/d/go').must_equal 'bazgetgo'
|
104
|
-
body('/d/go', 'REQUEST_METHOD'=>'POST').must_equal 'bazpostgo'
|
105
|
-
body('/bar').must_equal ""
|
106
|
-
body('/bar', 'REQUEST_METHOD'=>'POST').must_equal "ibar"
|
107
|
-
body('/bar', 'REQUEST_METHOD'=>'DELETE').must_equal "x-delete-bar"
|
108
|
-
body('/bar', 'REQUEST_METHOD'=>'HEAD').must_equal "x-head-bar"
|
109
|
-
body('/bar', 'REQUEST_METHOD'=>'OPTIONS').must_equal "x-options-bar"
|
110
|
-
body('/bar', 'REQUEST_METHOD'=>'PATCH').must_equal "x-patch-bar"
|
111
|
-
body('/bar', 'REQUEST_METHOD'=>'PUT').must_equal "x-put-bar"
|
112
|
-
body('/bar', 'REQUEST_METHOD'=>'TRACE').must_equal "x-trace-bar"
|
113
|
-
end
|
114
|
-
|
115
|
-
it "works with the not_found plugin if loaded before" do
|
116
|
-
app.plugin :not_found do
|
117
|
-
"nf"
|
118
|
-
end
|
119
|
-
|
120
|
-
body.must_equal 'root'
|
121
|
-
body('/foo').must_equal 'foo'
|
122
|
-
body('/foo/bar').must_equal 'foobar'
|
123
|
-
body('/d/go').must_equal 'bazgetgo'
|
124
|
-
body('/d/go', 'REQUEST_METHOD'=>'POST').must_equal 'bazpostgo'
|
125
|
-
body('/bar').must_equal "x-get-bar"
|
126
|
-
body('/bar', 'REQUEST_METHOD'=>'POST').must_equal "x-post-bar"
|
127
|
-
body('/bar', 'REQUEST_METHOD'=>'DELETE').must_equal "x-delete-bar"
|
128
|
-
body('/bar', 'REQUEST_METHOD'=>'HEAD').must_equal "x-head-bar"
|
129
|
-
body('/bar', 'REQUEST_METHOD'=>'OPTIONS').must_equal "x-options-bar"
|
130
|
-
body('/bar', 'REQUEST_METHOD'=>'PATCH').must_equal "x-patch-bar"
|
131
|
-
body('/bar', 'REQUEST_METHOD'=>'PUT').must_equal "x-put-bar"
|
132
|
-
body('/bar', 'REQUEST_METHOD'=>'TRACE').must_equal "x-trace-bar"
|
133
|
-
|
134
|
-
status.must_equal 200
|
135
|
-
status("/asdfa/asdf").must_equal 404
|
136
|
-
body("/asdfa/asdf").must_equal "nf"
|
137
|
-
end
|
138
|
-
|
139
|
-
it "works when freezing the app" do
|
140
|
-
app.freeze
|
141
|
-
body.must_equal 'root'
|
142
|
-
body('/foo').must_equal 'foo'
|
143
|
-
body('/foo/bar').must_equal 'foobar'
|
144
|
-
body('/d/go').must_equal 'bazgetgo'
|
145
|
-
body('/d/go', 'REQUEST_METHOD'=>'POST').must_equal 'bazpostgo'
|
146
|
-
body('/bar').must_equal "x-get-bar"
|
147
|
-
body('/bar', 'REQUEST_METHOD'=>'POST').must_equal "x-post-bar"
|
148
|
-
body('/bar', 'REQUEST_METHOD'=>'DELETE').must_equal "x-delete-bar"
|
149
|
-
body('/bar', 'REQUEST_METHOD'=>'HEAD').must_equal "x-head-bar"
|
150
|
-
body('/bar', 'REQUEST_METHOD'=>'OPTIONS').must_equal "x-options-bar"
|
151
|
-
body('/bar', 'REQUEST_METHOD'=>'PATCH').must_equal "x-patch-bar"
|
152
|
-
body('/bar', 'REQUEST_METHOD'=>'PUT').must_equal "x-put-bar"
|
153
|
-
body('/bar', 'REQUEST_METHOD'=>'TRACE').must_equal "x-trace-bar"
|
154
|
-
if ::Rack::Request.method_defined?("link?")
|
155
|
-
body('/bar', 'REQUEST_METHOD'=>'LINK').must_equal "x-link-bar"
|
156
|
-
body('/bar', 'REQUEST_METHOD'=>'UNLINK').must_equal "x-unlink-bar"
|
157
|
-
end
|
158
|
-
|
159
|
-
status.must_equal 200
|
160
|
-
status("/asdfa/asdf").must_equal 404
|
161
|
-
|
162
|
-
proc{app.on{}}.must_raise
|
163
|
-
end
|
164
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require_relative "../spec_helper"
|
2
|
-
require 'date'
|
3
|
-
|
4
|
-
describe "class_matchers plugin" do
|
5
|
-
it "allows class specific regexps with type conversion for class matchers" do
|
6
|
-
app(:bare) do
|
7
|
-
plugin :class_matchers
|
8
|
-
class_matcher(Date, /(\d\d\d\d)-(\d\d)-(\d\d)/){|y,m,d| [Date.new(y.to_i, m.to_i, d.to_i)]}
|
9
|
-
class_matcher(Array, /(\w+)\/(\w+)/){|a, b| [[a, 1], [b, 2]]}
|
10
|
-
class_matcher(Hash, /(\d+)\/(\d+)/){|a, b| [{a.to_i=>b.to_i}]}
|
11
|
-
|
12
|
-
route do |r|
|
13
|
-
r.on Array do |(a,b), (c,d)|
|
14
|
-
r.get Date do |date|
|
15
|
-
[date.year, date.month, date.day, a, b, c, d].join('-')
|
16
|
-
end
|
17
|
-
r.get Hash do |h|
|
18
|
-
[h.inspect, a, b, c, d].join('-')
|
19
|
-
end
|
20
|
-
r.get Array do |(a1,b1), (c1,d1)|
|
21
|
-
[a1, b1, c1, d1, a, b, c, d].join('-')
|
22
|
-
end
|
23
|
-
r.is do
|
24
|
-
[a, b, c, d].join('-')
|
25
|
-
end
|
26
|
-
"array"
|
27
|
-
end
|
28
|
-
""
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
body("/c").must_equal ''
|
33
|
-
body("/c/d").must_equal 'c-1-d-2'
|
34
|
-
body("/c/d/e").must_equal 'array'
|
35
|
-
body("/c/d/2009-10-a").must_equal 'array'
|
36
|
-
body("/c/d/2009-10-01").must_equal '2009-10-1-c-1-d-2'
|
37
|
-
body("/c/d/1/2").must_equal '{1=>2}-c-1-d-2'
|
38
|
-
body("/c/d/e/f").must_equal 'e-1-f-2-c-1-d-2'
|
39
|
-
end
|
40
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require_relative "../spec_helper"
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
|
5
|
-
describe "common_logger plugin" do
|
6
|
-
def cl_app(&block)
|
7
|
-
app(:common_logger, &block)
|
8
|
-
@logger = StringIO.new
|
9
|
-
@app.plugin :common_logger, @logger
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'logs requests to given logger/stream' do
|
13
|
-
cl_app(&:path_info)
|
14
|
-
|
15
|
-
body.must_equal '/'
|
16
|
-
@logger.rewind
|
17
|
-
@logger.read.must_match(/\A- - - \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "GET \/ " 200 1 0.\d\d\d\d\n\z/)
|
18
|
-
|
19
|
-
@logger.rewind
|
20
|
-
@logger.truncate(0)
|
21
|
-
body('', 'HTTP_X_FORWARDED_FOR'=>'1.1.1.1', 'REMOTE_USER'=>'je', 'REQUEST_METHOD'=>'POST', 'QUERY_STRING'=>'', "HTTP_VERSION"=>'HTTP/1.1').must_equal ''
|
22
|
-
@logger.rewind
|
23
|
-
@logger.read.must_match(/\A1\.1\.1\.1 - je \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "POST HTTP\/1.1" 200 - 0.\d\d\d\d\n\z/)
|
24
|
-
|
25
|
-
@logger.rewind
|
26
|
-
@logger.truncate(0)
|
27
|
-
body('/b', 'REMOTE_ADDR'=>'1.1.1.2', 'QUERY_STRING'=>'foo=bar', "HTTP_VERSION"=>'HTTP/1.0').must_equal '/b'
|
28
|
-
@logger.rewind
|
29
|
-
@logger.read.must_match(/\A1\.1\.1\.2 - - \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "GET \/b\?foo=bar HTTP\/1.0" 200 2 0.\d\d\d\d\n\z/)
|
30
|
-
|
31
|
-
@app.plugin :common_logger, Logger.new(@logger)
|
32
|
-
@logger.rewind
|
33
|
-
@logger.truncate(0)
|
34
|
-
body.must_equal '/'
|
35
|
-
@logger.rewind
|
36
|
-
@logger.read.must_match(/\A- - - \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "GET \/ " 200 1 0.\d\d\d\d\n\z/)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'skips timer information if not available' do
|
40
|
-
cl_app do |r|
|
41
|
-
@_request_timer = nil
|
42
|
-
r.path_info
|
43
|
-
end
|
44
|
-
|
45
|
-
body.must_equal '/'
|
46
|
-
@logger.rewind
|
47
|
-
@logger.read.must_match(/\A- - - \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "GET \/ " 200 1 -\n\z/)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'skips length information if not available' do
|
51
|
-
cl_app do |r|
|
52
|
-
r.halt [500, {}, []]
|
53
|
-
end
|
54
|
-
|
55
|
-
body.must_equal ''
|
56
|
-
@logger.rewind
|
57
|
-
@logger.read.must_match(/\A- - - \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "GET \/ " 500 - 0.\d\d\d\d\n\z/)
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'does not log if an error is raised' do
|
61
|
-
cl_app do |r|
|
62
|
-
raise "foo"
|
63
|
-
end
|
64
|
-
|
65
|
-
begin
|
66
|
-
body
|
67
|
-
rescue => e
|
68
|
-
end
|
69
|
-
e.must_be_instance_of(RuntimeError)
|
70
|
-
e.message.must_equal 'foo'
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'logs errors if used with error_handler' do
|
74
|
-
cl_app do |r|
|
75
|
-
raise "foo"
|
76
|
-
end
|
77
|
-
@app.plugin :error_handler do |_|
|
78
|
-
"bad"
|
79
|
-
end
|
80
|
-
|
81
|
-
body.must_equal 'bad'
|
82
|
-
@logger.rewind
|
83
|
-
@logger.read.must_match(/\A- - - \[\d\d\/[A-Z][a-z]{2}\/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\] "GET \/ " 500 3 0.\d\d\d\d\n\z/)
|
84
|
-
end
|
85
|
-
end
|