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.
- 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/flash_spec.rb
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
require_relative "../spec_helper"
|
2
|
-
|
3
|
-
describe "flash plugin" do
|
4
|
-
include CookieJar
|
5
|
-
|
6
|
-
[lambda{send(*DEFAULT_SESSION_ARGS); plugin :flash},
|
7
|
-
lambda{plugin :flash; send(*DEFAULT_SESSION_ARGS)}].each do |config|
|
8
|
-
|
9
|
-
it "flash.now[] sets flash for current page" do
|
10
|
-
app(:bare) do
|
11
|
-
instance_exec(&config)
|
12
|
-
|
13
|
-
route do |r|
|
14
|
-
r.on do
|
15
|
-
flash.now['a'] = 'b'
|
16
|
-
flash['a']
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
body.must_equal 'b'
|
22
|
-
end
|
23
|
-
|
24
|
-
it "flash[] sets flash for next page" do
|
25
|
-
app(:bare) do
|
26
|
-
instance_exec(&config)
|
27
|
-
|
28
|
-
route do |r|
|
29
|
-
r.get('a'){"c#{flash['a']}"}
|
30
|
-
r.get('f'){flash; session['_flash'].inspect}
|
31
|
-
|
32
|
-
flash['a'] = "b#{flash['a']}"
|
33
|
-
flash['a'] || ''
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
body.must_equal ''
|
38
|
-
body.must_equal 'b'
|
39
|
-
body.must_equal 'bb'
|
40
|
-
|
41
|
-
body('/a').must_equal 'cbbb'
|
42
|
-
body.must_equal ''
|
43
|
-
body.must_equal 'b'
|
44
|
-
body.must_equal 'bb'
|
45
|
-
|
46
|
-
body('/f').must_equal '{"a"=>"bbb"}'
|
47
|
-
body('/f').must_equal 'nil'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "FlashHash" do
|
53
|
-
before do
|
54
|
-
require 'roda/plugins/flash'
|
55
|
-
@h = Roda::RodaPlugins::Flash::FlashHash.new
|
56
|
-
end
|
57
|
-
|
58
|
-
it ".new should accept nil for empty hash" do
|
59
|
-
@h = Roda::RodaPlugins::Flash::FlashHash.new(nil)
|
60
|
-
@h.now.must_equal({})
|
61
|
-
@h.next.must_equal({})
|
62
|
-
end
|
63
|
-
|
64
|
-
it ".new should accept a hash" do
|
65
|
-
@h = Roda::RodaPlugins::Flash::FlashHash.new(1=>2)
|
66
|
-
@h.now.must_equal(1=>2)
|
67
|
-
@h.next.must_equal({})
|
68
|
-
end
|
69
|
-
|
70
|
-
it "#[]= assigns to next flash" do
|
71
|
-
@h[1] = 2
|
72
|
-
@h.now.must_equal({})
|
73
|
-
@h.next.must_equal(1=>2)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "#discard removes given key from next hash" do
|
77
|
-
@h[1] = 2
|
78
|
-
@h[nil] = 3
|
79
|
-
@h.next.must_equal(1=>2, nil=>3)
|
80
|
-
@h.discard(nil)
|
81
|
-
@h.next.must_equal(1=>2)
|
82
|
-
@h.discard(1)
|
83
|
-
@h.next.must_equal({})
|
84
|
-
end
|
85
|
-
|
86
|
-
it "#discard removes all entries from next hash with no arguments" do
|
87
|
-
@h[1] = 2
|
88
|
-
@h[nil] = 3
|
89
|
-
@h.next.must_equal(1=>2, nil=>3)
|
90
|
-
@h.discard
|
91
|
-
@h.next.must_equal({})
|
92
|
-
end
|
93
|
-
|
94
|
-
it "#keep copies entry for key from current hash to next hash" do
|
95
|
-
@h.now[1] = 2
|
96
|
-
@h.now[nil] = 3
|
97
|
-
@h.next.must_equal({})
|
98
|
-
@h.keep(nil)
|
99
|
-
@h.next.must_equal(nil=>3)
|
100
|
-
@h.keep(1)
|
101
|
-
@h.next.must_equal(1=>2, nil=>3)
|
102
|
-
end
|
103
|
-
|
104
|
-
it "#keep copies all entries from current hash to next hash" do
|
105
|
-
@h.now[1] = 2
|
106
|
-
@h.now[nil] = 3
|
107
|
-
@h.next.must_equal({})
|
108
|
-
@h.keep
|
109
|
-
@h.next.must_equal(1=>2, nil=>3)
|
110
|
-
end
|
111
|
-
|
112
|
-
it "#sweep replaces current hash with next hash" do
|
113
|
-
@h[1] = 2
|
114
|
-
@h[nil] = 3
|
115
|
-
@h.next.must_equal(1=>2, nil=>3)
|
116
|
-
@h.now.must_equal({})
|
117
|
-
@h.sweep.must_equal(1=>2, nil=>3)
|
118
|
-
@h.next.must_equal({})
|
119
|
-
@h.now.must_equal(1=>2, nil=>3)
|
120
|
-
end
|
121
|
-
end
|
data/spec/plugin/h_spec.rb
DELETED
data/spec/plugin/halt_spec.rb
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
require_relative "../spec_helper"
|
2
|
-
|
3
|
-
describe "halt plugin" do
|
4
|
-
it "should still have halt return rack response as argument given it as argument" do
|
5
|
-
app(:halt) do |r|
|
6
|
-
r.halt [200, {}, ['foo']]
|
7
|
-
end
|
8
|
-
|
9
|
-
body.must_equal "foo"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should consider string argument as response body" do
|
13
|
-
app(:halt) do |r|
|
14
|
-
r.halt "foo"
|
15
|
-
end
|
16
|
-
|
17
|
-
body.must_equal "foo"
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should consider integer argument as response status" do
|
21
|
-
app(:halt) do |r|
|
22
|
-
r.halt 300
|
23
|
-
end
|
24
|
-
|
25
|
-
status.must_equal 300
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should consider other single arguments similar to block bodies" do
|
29
|
-
app(:bare) do
|
30
|
-
plugin :halt
|
31
|
-
plugin :json
|
32
|
-
route do |r|
|
33
|
-
r.halt({'a'=>1})
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
body.must_equal '{"a":1}'
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should consider 2 arguments as response status and body" do
|
41
|
-
app(:halt) do |r|
|
42
|
-
r.halt 300, "foo"
|
43
|
-
end
|
44
|
-
|
45
|
-
status.must_equal 300
|
46
|
-
body.must_equal "foo"
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should handle 2nd of 2 arguments similar to block bodies" do
|
50
|
-
app(:bare) do
|
51
|
-
plugin :halt
|
52
|
-
plugin :json
|
53
|
-
route do |r|
|
54
|
-
r.halt(300, {'a'=>1})
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
status.must_equal 300
|
59
|
-
body.must_equal '{"a":1}'
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should consider 3 arguments as response" do
|
63
|
-
app(:halt) do |r|
|
64
|
-
r.halt 300, {'a'=>'b'}, "foo"
|
65
|
-
end
|
66
|
-
|
67
|
-
status.must_equal 300
|
68
|
-
header('a').must_equal 'b'
|
69
|
-
body.must_equal "foo"
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should consider an array as a rack response" do
|
73
|
-
app(:halt) do |r|
|
74
|
-
r.halt [300, {'a'=>'b'}, ["foo"]]
|
75
|
-
end
|
76
|
-
|
77
|
-
status.must_equal 300
|
78
|
-
header('a').must_equal 'b'
|
79
|
-
body.must_equal "foo"
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should handle 3rd of 3 arguments similar to block bodies" do
|
83
|
-
app(:bare) do
|
84
|
-
plugin :halt
|
85
|
-
plugin :json
|
86
|
-
route do |r|
|
87
|
-
r.halt(300, {'a'=>'b'}, {'a'=>1})
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
status.must_equal 300
|
92
|
-
header('a').must_equal 'b'
|
93
|
-
body.must_equal '{"a":1}'
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should raise an error for too many arguments" do
|
97
|
-
app(:halt) do |r|
|
98
|
-
r.halt 300, {'a'=>'b'}, "foo", 1
|
99
|
-
end
|
100
|
-
|
101
|
-
proc{req}.must_raise(Roda::RodaError)
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should raise an error for single argument not integer, String, or Array" do
|
105
|
-
app(:halt) do |r|
|
106
|
-
r.halt nil
|
107
|
-
end
|
108
|
-
|
109
|
-
proc{req}.must_raise(Roda::RodaError)
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should raise an error for single argument not integer, String, or Array" do
|
113
|
-
app(:halt) do |r|
|
114
|
-
r.halt('a'=>'b')
|
115
|
-
end
|
116
|
-
|
117
|
-
proc{req}.must_raise(Roda::RodaError)
|
118
|
-
end
|
119
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require_relative "../spec_helper"
|
2
|
-
|
3
|
-
describe "hash_matcher plugin" do
|
4
|
-
it "should enable the handling of arbitrary hash keys" do
|
5
|
-
app(:bare) do
|
6
|
-
plugin :hash_matcher
|
7
|
-
hash_matcher(:foos){|v| consume(self.class.cached_matcher(:"foos-#{v}"){/((?:foo){#{v}})/})}
|
8
|
-
route do |r|
|
9
|
-
r.is :foos=>1 do |f|
|
10
|
-
"1#{f}"
|
11
|
-
end
|
12
|
-
r.is :foos=>2 do |f|
|
13
|
-
"2#{f}"
|
14
|
-
end
|
15
|
-
r.is :foos=>3 do |f|
|
16
|
-
"3#{f}"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
body("/foo").must_equal '1foo'
|
22
|
-
body("/foofoo").must_equal '2foofoo'
|
23
|
-
body("/foofoofoo").must_equal '3foofoofoo'
|
24
|
-
status("/foofoofoofoo").must_equal 404
|
25
|
-
status.must_equal 404
|
26
|
-
end
|
27
|
-
end
|
@@ -1,535 +0,0 @@
|
|
1
|
-
require_relative "../spec_helper"
|
2
|
-
|
3
|
-
describe "hash_routes plugin - hash_routes DSL" do
|
4
|
-
before do
|
5
|
-
app(:bare) do
|
6
|
-
plugin :hash_routes
|
7
|
-
|
8
|
-
hash_routes "" do
|
9
|
-
on "a" do |r|
|
10
|
-
r.is "" do
|
11
|
-
"a0"
|
12
|
-
end
|
13
|
-
|
14
|
-
r.is "a" do
|
15
|
-
"a1"
|
16
|
-
end
|
17
|
-
|
18
|
-
r.hash_branches
|
19
|
-
|
20
|
-
"a2"
|
21
|
-
end
|
22
|
-
|
23
|
-
on "b" do |r|
|
24
|
-
r.is "" do
|
25
|
-
"b0"
|
26
|
-
end
|
27
|
-
|
28
|
-
r.is "a" do
|
29
|
-
"b1"
|
30
|
-
end
|
31
|
-
|
32
|
-
"b2"
|
33
|
-
end
|
34
|
-
|
35
|
-
is "c" do |r|
|
36
|
-
"c#{r.request_method}"
|
37
|
-
end
|
38
|
-
|
39
|
-
get 'd' do
|
40
|
-
'dg'
|
41
|
-
end
|
42
|
-
|
43
|
-
post 'e' do
|
44
|
-
'ep'
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
hash_routes "/a" do |hr|
|
49
|
-
hr.dispatch_from(:p, "r")
|
50
|
-
|
51
|
-
hr.dispatch_from(:p, "s") do |r|
|
52
|
-
r.is "a" do
|
53
|
-
"psa1"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
hr.on "b" do |r|
|
58
|
-
r.is "" do
|
59
|
-
"ab0"
|
60
|
-
end
|
61
|
-
|
62
|
-
r.is "a" do
|
63
|
-
"ab1"
|
64
|
-
end
|
65
|
-
|
66
|
-
r.hash_branches
|
67
|
-
|
68
|
-
"ab2"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
phr = hash_routes(:p)
|
73
|
-
|
74
|
-
phr.is true do
|
75
|
-
"pi"
|
76
|
-
end
|
77
|
-
|
78
|
-
phr.on "x" do |r|
|
79
|
-
r.is do
|
80
|
-
'px'
|
81
|
-
end
|
82
|
-
|
83
|
-
'pnx'
|
84
|
-
end
|
85
|
-
|
86
|
-
route do |r|
|
87
|
-
r.hash_routes
|
88
|
-
|
89
|
-
r.on 'p' do
|
90
|
-
r.hash_routes(:p)
|
91
|
-
|
92
|
-
r.hash_routes("")
|
93
|
-
|
94
|
-
"p"
|
95
|
-
end
|
96
|
-
|
97
|
-
"n"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
it "adds support for routing via r.hash_routes" do
|
103
|
-
body.must_equal 'n'
|
104
|
-
body('/a').must_equal 'a2'
|
105
|
-
body('/a/').must_equal 'a0'
|
106
|
-
body('/a/a').must_equal 'a1'
|
107
|
-
body('/a/b').must_equal 'ab2'
|
108
|
-
body('/a/b/').must_equal 'ab0'
|
109
|
-
body('/a/b/a').must_equal 'ab1'
|
110
|
-
body('/b').must_equal 'b2'
|
111
|
-
body('/b/').must_equal 'b0'
|
112
|
-
body('/b/a').must_equal 'b1'
|
113
|
-
body('/c').must_equal 'cGET'
|
114
|
-
body('/c', 'REQUEST_METHOD'=>'POST').must_equal 'cPOST'
|
115
|
-
body('/c/').must_equal 'n'
|
116
|
-
body('/d').must_equal 'dg'
|
117
|
-
body('/d', 'REQUEST_METHOD'=>'POST').must_equal ''
|
118
|
-
body('/d/').must_equal 'n'
|
119
|
-
body('/e').must_equal ''
|
120
|
-
body('/e', 'REQUEST_METHOD'=>'POST').must_equal 'ep'
|
121
|
-
body('/e/').must_equal 'n'
|
122
|
-
body('/p').must_equal 'pi'
|
123
|
-
body('/p/x').must_equal 'px'
|
124
|
-
body('/p/x/1').must_equal 'pnx'
|
125
|
-
|
126
|
-
body('/p/a').must_equal 'a2'
|
127
|
-
body('/p/a/').must_equal 'a0'
|
128
|
-
body('/p/a/a').must_equal 'a1'
|
129
|
-
body('/p/a/b').must_equal 'a2'
|
130
|
-
body('/p/a/b/').must_equal 'a2'
|
131
|
-
body('/p/a/b/a').must_equal 'a2'
|
132
|
-
body('/p/b').must_equal 'b2'
|
133
|
-
body('/p/b/').must_equal 'b0'
|
134
|
-
body('/p/b/a').must_equal 'b1'
|
135
|
-
body('/p/c').must_equal 'cGET'
|
136
|
-
body('/p/c', 'REQUEST_METHOD'=>'POST').must_equal 'cPOST'
|
137
|
-
body('/p/c/').must_equal 'p'
|
138
|
-
body('/p/d').must_equal 'dg'
|
139
|
-
body('/p/d', 'REQUEST_METHOD'=>'POST').must_equal ''
|
140
|
-
body('/p/d/').must_equal 'p'
|
141
|
-
body('/p/e').must_equal ''
|
142
|
-
body('/p/e', 'REQUEST_METHOD'=>'POST').must_equal 'ep'
|
143
|
-
body('/p/e/').must_equal 'p'
|
144
|
-
body('/p/p').must_equal 'p'
|
145
|
-
body('/p/p/x').must_equal 'p'
|
146
|
-
body('/p/p/x/1').must_equal 'p'
|
147
|
-
|
148
|
-
body('/p/r/b').must_equal 'ab2'
|
149
|
-
body('/p/r/b/').must_equal 'ab0'
|
150
|
-
body('/p/r/b/a').must_equal 'ab1'
|
151
|
-
|
152
|
-
body('/p/s/a').must_equal 'psa1'
|
153
|
-
body('/p/s/b').must_equal 'ab2'
|
154
|
-
body('/p/s/b/').must_equal 'ab0'
|
155
|
-
body('/p/s/b/a').must_equal 'ab1'
|
156
|
-
end
|
157
|
-
|
158
|
-
it "works when freezing the app" do
|
159
|
-
app.freeze
|
160
|
-
body.must_equal 'n'
|
161
|
-
body('/a').must_equal 'a2'
|
162
|
-
body('/a/').must_equal 'a0'
|
163
|
-
proc{app.hash_branch("foo"){}}.must_raise
|
164
|
-
end
|
165
|
-
|
166
|
-
it "works when subclassing the app" do
|
167
|
-
old_app = app
|
168
|
-
@app = Class.new(app)
|
169
|
-
@app.route(&old_app.route_block)
|
170
|
-
body.must_equal 'n'
|
171
|
-
body('/a').must_equal 'a2'
|
172
|
-
body('/a/').must_equal 'a0'
|
173
|
-
body('/p/x').must_equal 'px'
|
174
|
-
end
|
175
|
-
|
176
|
-
it "handles loading the plugin multiple times correctly" do
|
177
|
-
app.plugin :hash_routes
|
178
|
-
body.must_equal 'n'
|
179
|
-
body('/a').must_equal 'a2'
|
180
|
-
body('/a/').must_equal 'a0'
|
181
|
-
body('/p/x').must_equal 'px'
|
182
|
-
end
|
183
|
-
|
184
|
-
it "r.hash_routes with verb handles loading the same route more than once" do
|
185
|
-
app.hash_routes "" do
|
186
|
-
get 'd' do
|
187
|
-
'dg'
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
body('/d').must_equal 'dg'
|
192
|
-
body('/d', 'REQUEST_METHOD'=>'POST').must_equal ''
|
193
|
-
body('/d/').must_equal 'n'
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
describe "hash_routes plugin - hash_branch" do
|
198
|
-
before do
|
199
|
-
app(:bare) do
|
200
|
-
plugin :hash_routes
|
201
|
-
|
202
|
-
hash_branch("a") do |r|
|
203
|
-
r.is "" do
|
204
|
-
"a0"
|
205
|
-
end
|
206
|
-
|
207
|
-
r.is "a" do
|
208
|
-
"a1"
|
209
|
-
end
|
210
|
-
|
211
|
-
r.hash_branches
|
212
|
-
|
213
|
-
"a2"
|
214
|
-
end
|
215
|
-
|
216
|
-
hash_branch("/a", "b") do |r|
|
217
|
-
r.is "" do
|
218
|
-
"ab0"
|
219
|
-
end
|
220
|
-
|
221
|
-
r.is "a" do
|
222
|
-
"ab1"
|
223
|
-
end
|
224
|
-
|
225
|
-
r.hash_branches
|
226
|
-
|
227
|
-
"ab2"
|
228
|
-
end
|
229
|
-
|
230
|
-
hash_branch("", "b") do |r|
|
231
|
-
r.is "" do
|
232
|
-
"b0"
|
233
|
-
end
|
234
|
-
|
235
|
-
r.is "a" do
|
236
|
-
"b1"
|
237
|
-
end
|
238
|
-
|
239
|
-
"b2"
|
240
|
-
end
|
241
|
-
|
242
|
-
hash_branch(:p, "x") do |r|
|
243
|
-
r.is do
|
244
|
-
'px'
|
245
|
-
end
|
246
|
-
|
247
|
-
'pnx'
|
248
|
-
end
|
249
|
-
|
250
|
-
route do |r|
|
251
|
-
r.hash_branches
|
252
|
-
|
253
|
-
r.on 'p' do
|
254
|
-
r.hash_branches(:p)
|
255
|
-
|
256
|
-
r.hash_branches("")
|
257
|
-
|
258
|
-
"p"
|
259
|
-
end
|
260
|
-
|
261
|
-
"n"
|
262
|
-
end
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
it "adds support for routing via r.hash_branches" do
|
267
|
-
body.must_equal 'n'
|
268
|
-
body('/a').must_equal 'a2'
|
269
|
-
body('/a/').must_equal 'a0'
|
270
|
-
body('/a/a').must_equal 'a1'
|
271
|
-
body('/a/b').must_equal 'ab2'
|
272
|
-
body('/a/b/').must_equal 'ab0'
|
273
|
-
body('/a/b/a').must_equal 'ab1'
|
274
|
-
body('/b').must_equal 'b2'
|
275
|
-
body('/b/').must_equal 'b0'
|
276
|
-
body('/b/a').must_equal 'b1'
|
277
|
-
body('/p').must_equal 'p'
|
278
|
-
body('/p/x').must_equal 'px'
|
279
|
-
body('/p/x/1').must_equal 'pnx'
|
280
|
-
|
281
|
-
body('/p/a').must_equal 'a2'
|
282
|
-
body('/p/a/').must_equal 'a0'
|
283
|
-
body('/p/a/a').must_equal 'a1'
|
284
|
-
body('/p/a/b').must_equal 'a2'
|
285
|
-
body('/p/a/b/').must_equal 'a2'
|
286
|
-
body('/p/a/b/a').must_equal 'a2'
|
287
|
-
body('/p/b').must_equal 'b2'
|
288
|
-
body('/p/b/').must_equal 'b0'
|
289
|
-
body('/p/b/a').must_equal 'b1'
|
290
|
-
body('/p/p').must_equal 'p'
|
291
|
-
body('/p/p/x').must_equal 'p'
|
292
|
-
body('/p/p/x/1').must_equal 'p'
|
293
|
-
end
|
294
|
-
|
295
|
-
it "works when freezing the app" do
|
296
|
-
app.freeze
|
297
|
-
body.must_equal 'n'
|
298
|
-
body('/a').must_equal 'a2'
|
299
|
-
body('/a/').must_equal 'a0'
|
300
|
-
proc{app.hash_branch("foo"){}}.must_raise
|
301
|
-
end
|
302
|
-
|
303
|
-
it "works when subclassing the app" do
|
304
|
-
old_app = app
|
305
|
-
@app = Class.new(app)
|
306
|
-
@app.route(&old_app.route_block)
|
307
|
-
body.must_equal 'n'
|
308
|
-
body('/a').must_equal 'a2'
|
309
|
-
body('/a/').must_equal 'a0'
|
310
|
-
body('/p/x').must_equal 'px'
|
311
|
-
end
|
312
|
-
|
313
|
-
it "handles loading the plugin multiple times correctly" do
|
314
|
-
app.plugin :hash_routes
|
315
|
-
body.must_equal 'n'
|
316
|
-
body('/a').must_equal 'a2'
|
317
|
-
body('/a/').must_equal 'a0'
|
318
|
-
body('/p/x').must_equal 'px'
|
319
|
-
end
|
320
|
-
|
321
|
-
it "r.hash_branch handles loading the same route more than once" do
|
322
|
-
app.hash_branch(:p, "x") do |r|
|
323
|
-
'px'
|
324
|
-
end
|
325
|
-
|
326
|
-
body('/p').must_equal 'p'
|
327
|
-
body('/p/x').must_equal 'px'
|
328
|
-
end
|
329
|
-
end
|
330
|
-
|
331
|
-
describe "hash_routes plugin - hash_path" do
|
332
|
-
before do
|
333
|
-
app(:bare) do
|
334
|
-
plugin :hash_routes
|
335
|
-
|
336
|
-
hash_path("/a") do |r|
|
337
|
-
r.get{"a"}
|
338
|
-
r.post{"ap"}
|
339
|
-
end
|
340
|
-
|
341
|
-
hash_path("", "/b") do |_|
|
342
|
-
"b"
|
343
|
-
end
|
344
|
-
|
345
|
-
hash_path("/c", "/b") do |_|
|
346
|
-
"cb"
|
347
|
-
end
|
348
|
-
|
349
|
-
hash_path(:p, "/x") do |_|
|
350
|
-
'px'
|
351
|
-
end
|
352
|
-
|
353
|
-
route do |r|
|
354
|
-
r.hash_paths
|
355
|
-
|
356
|
-
r.on 'p' do
|
357
|
-
r.hash_paths(:p)
|
358
|
-
|
359
|
-
r.hash_paths("")
|
360
|
-
|
361
|
-
"p"
|
362
|
-
end
|
363
|
-
|
364
|
-
r.on "c" do
|
365
|
-
r.hash_paths
|
366
|
-
|
367
|
-
"c"
|
368
|
-
end
|
369
|
-
|
370
|
-
"n"
|
371
|
-
end
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
it "adds support for routing via r.hash_paths" do
|
376
|
-
body.must_equal 'n'
|
377
|
-
body('/a').must_equal 'a'
|
378
|
-
body('/a', 'REQUEST_METHOD'=>'POST').must_equal 'ap'
|
379
|
-
body('/a/').must_equal 'n'
|
380
|
-
body('/b').must_equal 'b'
|
381
|
-
body('/b/').must_equal 'n'
|
382
|
-
body('/c').must_equal 'c'
|
383
|
-
body('/c/').must_equal 'c'
|
384
|
-
body('/c/b').must_equal 'cb'
|
385
|
-
body('/c/b/').must_equal 'c'
|
386
|
-
body('/p').must_equal 'p'
|
387
|
-
body('/p/x').must_equal 'px'
|
388
|
-
body('/p/x/1').must_equal 'p'
|
389
|
-
end
|
390
|
-
|
391
|
-
it "works when freezing the app" do
|
392
|
-
app.freeze
|
393
|
-
body.must_equal 'n'
|
394
|
-
body('/a').must_equal 'a'
|
395
|
-
body('/a/').must_equal 'n'
|
396
|
-
body('/p/x').must_equal 'px'
|
397
|
-
proc{app.hash_path("foo"){}}.must_raise
|
398
|
-
end
|
399
|
-
|
400
|
-
it "works when subclassing the app" do
|
401
|
-
old_app = app
|
402
|
-
@app = Class.new(app)
|
403
|
-
@app.route(&old_app.route_block)
|
404
|
-
body.must_equal 'n'
|
405
|
-
body('/a').must_equal 'a'
|
406
|
-
body('/a/').must_equal 'n'
|
407
|
-
body('/p/x').must_equal 'px'
|
408
|
-
end
|
409
|
-
|
410
|
-
it "handles loading the plugin multiple times correctly" do
|
411
|
-
app.plugin :hash_routes
|
412
|
-
body.must_equal 'n'
|
413
|
-
body('/a').must_equal 'a'
|
414
|
-
body('/a/').must_equal 'n'
|
415
|
-
body('/p/x').must_equal 'px'
|
416
|
-
end
|
417
|
-
|
418
|
-
it "r.hash_path handles loading the same route more than once" do
|
419
|
-
app.hash_path(:p, "x") do |r|
|
420
|
-
'px'
|
421
|
-
end
|
422
|
-
|
423
|
-
body('/p').must_equal 'p'
|
424
|
-
body('/p/x').must_equal 'px'
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
describe "hash_routes plugin" do
|
429
|
-
it "should work with route_block_args" do
|
430
|
-
app(:bare) do
|
431
|
-
plugin :hash_routes
|
432
|
-
plugin :route_block_args do
|
433
|
-
[request, response]
|
434
|
-
end
|
435
|
-
|
436
|
-
hash_branch 'a' do |r, res|
|
437
|
-
r.hash_paths
|
438
|
-
|
439
|
-
res.write('a')
|
440
|
-
end
|
441
|
-
|
442
|
-
hash_path '/a', '/b' do |r, res|
|
443
|
-
res.write('b')
|
444
|
-
end
|
445
|
-
|
446
|
-
route do |r|
|
447
|
-
r.hash_branches
|
448
|
-
|
449
|
-
'n'
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
body.must_equal 'n'
|
454
|
-
body('/a').must_equal 'a'
|
455
|
-
body('/a/').must_equal 'a'
|
456
|
-
body('/a/b').must_equal 'b'
|
457
|
-
body('/a/b/').must_equal 'a'
|
458
|
-
end
|
459
|
-
|
460
|
-
it "should have r.hash_routes dispatch to both hash_paths and hash_branches" do
|
461
|
-
app(:bare) do
|
462
|
-
plugin :hash_routes
|
463
|
-
plugin :route_block_args do
|
464
|
-
[request, response]
|
465
|
-
end
|
466
|
-
|
467
|
-
hash_branch 'a' do |r|
|
468
|
-
r.root do
|
469
|
-
'ar'
|
470
|
-
end
|
471
|
-
|
472
|
-
'ab'
|
473
|
-
end
|
474
|
-
|
475
|
-
hash_path '/a' do |_|
|
476
|
-
'ap'
|
477
|
-
end
|
478
|
-
|
479
|
-
hash_branch 'b' do |_|
|
480
|
-
'b'
|
481
|
-
end
|
482
|
-
|
483
|
-
hash_path '/c' do |_|
|
484
|
-
'c'
|
485
|
-
end
|
486
|
-
|
487
|
-
route do |r|
|
488
|
-
r.hash_routes
|
489
|
-
|
490
|
-
'n'
|
491
|
-
end
|
492
|
-
end
|
493
|
-
|
494
|
-
body.must_equal 'n'
|
495
|
-
body('/a').must_equal 'ap'
|
496
|
-
body('/a/').must_equal 'ar'
|
497
|
-
body('/a/b').must_equal 'ab'
|
498
|
-
body('/a').must_equal 'ap'
|
499
|
-
body('/b').must_equal 'b'
|
500
|
-
body('/b/').must_equal 'b'
|
501
|
-
body('/c').must_equal 'c'
|
502
|
-
body('/c/').must_equal 'n'
|
503
|
-
end
|
504
|
-
end
|
505
|
-
|
506
|
-
begin
|
507
|
-
require 'tilt/erb'
|
508
|
-
rescue LoadError
|
509
|
-
warn "tilt not installed, skipping hash_routes plugin views test"
|
510
|
-
else
|
511
|
-
describe "hash routes plugin" do
|
512
|
-
it "supports easy rendering of multiple views by name" do
|
513
|
-
app(:bare) do
|
514
|
-
plugin :render, :views=>'spec/views', :layout=>'layout-yield'
|
515
|
-
plugin :hash_routes
|
516
|
-
|
517
|
-
hash_routes '/d' do
|
518
|
-
view true, 'a'
|
519
|
-
view '', 'b'
|
520
|
-
views %w'c'
|
521
|
-
end
|
522
|
-
|
523
|
-
route do |r|
|
524
|
-
r.on 'd' do
|
525
|
-
r.hash_routes
|
526
|
-
end
|
527
|
-
end
|
528
|
-
end
|
529
|
-
|
530
|
-
body('/d').gsub(/\s+/, '').must_equal "HeaderaFooter"
|
531
|
-
body('/d/').gsub(/\s+/, '').must_equal "HeaderbFooter"
|
532
|
-
body('/d/c').gsub(/\s+/, '').must_equal "HeadercFooter"
|
533
|
-
end
|
534
|
-
end
|
535
|
-
end
|