roda 2.2.0 → 2.3.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 +34 -0
- data/Rakefile +22 -46
- data/doc/release_notes/2.3.0.txt +109 -0
- data/lib/roda/plugins/assets.rb +2 -1
- data/lib/roda/plugins/caching.rb +1 -1
- data/lib/roda/plugins/chunked.rb +1 -1
- data/lib/roda/plugins/error_email.rb +1 -1
- data/lib/roda/plugins/head.rb +6 -0
- data/lib/roda/plugins/heartbeat.rb +40 -0
- data/lib/roda/plugins/json.rb +23 -3
- data/lib/roda/plugins/json_parser.rb +72 -0
- data/lib/roda/plugins/mailer.rb +22 -5
- data/lib/roda/plugins/named_templates.rb +2 -2
- data/lib/roda/plugins/path_rewriter.rb +82 -0
- data/lib/roda/plugins/precompile_templates.rb +87 -0
- data/lib/roda/plugins/render.rb +111 -43
- data/lib/roda/plugins/render_each.rb +1 -1
- data/lib/roda/plugins/shared_vars.rb +1 -1
- data/lib/roda/plugins/view_options.rb +28 -3
- data/lib/roda/version.rb +1 -1
- data/spec/composition_spec.rb +3 -3
- data/spec/env_spec.rb +1 -1
- data/spec/freeze_spec.rb +6 -6
- data/spec/integration_spec.rb +16 -15
- data/spec/matchers_spec.rb +110 -110
- data/spec/opts_spec.rb +8 -8
- data/spec/plugin/_erubis_escaping_spec.rb +34 -3
- data/spec/plugin/all_verbs_spec.rb +8 -8
- data/spec/plugin/assets_spec.rb +164 -150
- data/spec/plugin/backtracking_array_spec.rb +18 -18
- data/spec/plugin/caching_spec.rb +70 -70
- data/spec/plugin/chunked_spec.rb +38 -38
- data/spec/plugin/class_level_routing_spec.rb +78 -78
- data/spec/plugin/content_for_spec.rb +2 -2
- data/spec/plugin/cookies_spec.rb +4 -4
- data/spec/plugin/csrf_spec.rb +8 -8
- data/spec/plugin/default_headers_spec.rb +6 -6
- data/spec/plugin/delay_build_spec.rb +7 -6
- data/spec/plugin/delegate_spec.rb +2 -2
- data/spec/plugin/delete_empty_headers_spec.rb +2 -2
- data/spec/plugin/drop_body_spec.rb +6 -6
- data/spec/plugin/empty_root_spec.rb +3 -3
- data/spec/plugin/environments_spec.rb +7 -7
- data/spec/plugin/error_email_spec.rb +23 -23
- data/spec/plugin/error_handler_spec.rb +14 -14
- data/spec/plugin/flash_spec.rb +30 -29
- data/spec/plugin/h_spec.rb +1 -1
- data/spec/plugin/halt_spec.rb +16 -16
- data/spec/plugin/hash_matcher_spec.rb +5 -5
- data/spec/plugin/head_spec.rb +10 -10
- data/spec/plugin/header_matchers_spec.rb +13 -13
- data/spec/plugin/heartbeat_spec.rb +74 -0
- data/spec/plugin/hooks_spec.rb +20 -20
- data/spec/plugin/indifferent_params_spec.rb +1 -1
- data/spec/plugin/json_parser_spec.rb +72 -0
- data/spec/plugin/json_spec.rb +22 -9
- data/spec/plugin/mailer_spec.rb +72 -58
- data/spec/plugin/match_affix_spec.rb +2 -2
- data/spec/plugin/middleware_spec.rb +7 -7
- data/spec/plugin/module_include_spec.rb +4 -4
- data/spec/plugin/multi_route_spec.rb +66 -66
- data/spec/plugin/multi_run_spec.rb +21 -21
- data/spec/plugin/named_templates_spec.rb +6 -6
- data/spec/plugin/not_allowed_spec.rb +17 -17
- data/spec/plugin/not_found_spec.rb +14 -14
- data/spec/plugin/padrino_render_spec.rb +2 -2
- data/spec/plugin/param_matchers_spec.rb +6 -6
- data/spec/plugin/partials_spec.rb +3 -3
- data/spec/plugin/pass_spec.rb +7 -7
- data/spec/plugin/path_matchers_spec.rb +6 -6
- data/spec/plugin/path_rewriter_spec.rb +37 -0
- data/spec/plugin/path_spec.rb +41 -40
- data/spec/plugin/per_thread_caching_spec.rb +6 -6
- data/spec/plugin/precompile_templates_spec.rb +74 -0
- data/spec/plugin/render_each_spec.rb +4 -4
- data/spec/plugin/render_spec.rb +179 -76
- data/spec/plugin/shared_vars_spec.rb +4 -4
- data/spec/plugin/sinatra_helpers_spec.rb +121 -121
- data/spec/plugin/slash_path_empty_spec.rb +10 -10
- data/spec/plugin/static_spec.rb +4 -4
- data/spec/plugin/streaming_spec.rb +11 -11
- data/spec/plugin/symbol_matchers_spec.rb +24 -24
- data/spec/plugin/symbol_views_spec.rb +3 -3
- data/spec/plugin/view_options_spec.rb +10 -10
- data/spec/plugin_spec.rb +2 -2
- data/spec/redirect_spec.rb +10 -10
- data/spec/request_spec.rb +8 -8
- data/spec/response_spec.rb +23 -23
- data/spec/session_spec.rb +4 -4
- data/spec/spec_helper.rb +5 -19
- data/spec/version_spec.rb +4 -4
- data/spec/views/iv.erb +1 -0
- metadata +16 -5
@@ -24,11 +24,11 @@ describe "padrino_render plugin" do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "render uses layout by default" do
|
27
|
-
body("/render").strip.
|
27
|
+
body("/render").strip.must_equal "<title>Roda: Home</title>\nbar"
|
28
28
|
end
|
29
29
|
|
30
30
|
it "render doesn't use layout if layout is nil" do
|
31
|
-
body("/render/nolayout").strip.
|
31
|
+
body("/render/nolayout").strip.must_equal "<h1>No Layout</h1>"
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -13,9 +13,9 @@ describe "param_matchers plugin" do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
io = StringIO.new
|
16
|
-
body("/signup", "rack.input" => io, "QUERY_STRING" => "email=john@doe.com").
|
17
|
-
body("/signup", "rack.input" => io, "QUERY_STRING" => "").
|
18
|
-
body("/signup", "rack.input" => io, "QUERY_STRING" => "email=").
|
16
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "email=john@doe.com").must_equal 'john@doe.com'
|
17
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "").must_equal 'No email'
|
18
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "email=").must_equal 'No email'
|
19
19
|
end
|
20
20
|
|
21
21
|
it "param matcheshould yield a param only if given" do
|
@@ -30,8 +30,8 @@ describe "param_matchers plugin" do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
io = StringIO.new
|
33
|
-
body("/signup", "rack.input" => io, "QUERY_STRING" => "email=john@doe.com").
|
34
|
-
body("/signup", "rack.input" => io, "QUERY_STRING" => "").
|
35
|
-
body("/signup", "rack.input" => io, "QUERY_STRING" => "email=").
|
33
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "email=john@doe.com").must_equal 'john@doe.com'
|
34
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "").must_equal 'No email'
|
35
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "email=").must_equal ''
|
36
36
|
end
|
37
37
|
end
|
@@ -28,15 +28,15 @@ else
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "partial renders without layout, and prepends _ to template" do
|
31
|
-
body("/partial").strip.
|
31
|
+
body("/partial").strip.must_equal "<h1>About Roda</h1>"
|
32
32
|
end
|
33
33
|
|
34
34
|
it "partial renders without layout, and prepends _ to template" do
|
35
|
-
body("/partial/subdir").strip.
|
35
|
+
body("/partial/subdir").strip.must_equal "<h1>Subdir: About Roda</h1>"
|
36
36
|
end
|
37
37
|
|
38
38
|
it "partial handles inline partials" do
|
39
|
-
body("/partial/inline").strip.
|
39
|
+
body("/partial/inline").strip.must_equal "Hello Agent Smith"
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
data/spec/plugin/pass_spec.rb
CHANGED
@@ -18,12 +18,12 @@ describe "pass plugin" do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
body.
|
22
|
-
status('FOO'=>true).
|
23
|
-
body("/a").
|
24
|
-
body("/a/b").
|
25
|
-
body("/foo/a").
|
26
|
-
body("/foo/a/b").
|
27
|
-
status("/foo").
|
21
|
+
body.must_equal 'root'
|
22
|
+
status('FOO'=>true).must_equal 404
|
23
|
+
body("/a").must_equal 'a'
|
24
|
+
body("/a/b").must_equal 'a'
|
25
|
+
body("/foo/a").must_equal 'fooa'
|
26
|
+
body("/foo/a/b").must_equal 'fooa'
|
27
|
+
status("/foo").must_equal 404
|
28
28
|
end
|
29
29
|
end
|
@@ -10,8 +10,8 @@ describe "path_matchers plugin" do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
body("/css/reset.css").
|
14
|
-
status("/css/reset.bar").
|
13
|
+
body("/css/reset.css").must_equal 'reset'
|
14
|
+
status("/css/reset.bar").must_equal 404
|
15
15
|
end
|
16
16
|
|
17
17
|
it ":suffix matcher should match given suffix" do
|
@@ -23,8 +23,8 @@ describe "path_matchers plugin" do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
body("/css/reset.css").
|
27
|
-
status("/css/reset.bar").
|
26
|
+
body("/css/reset.css").must_equal 'reset'
|
27
|
+
status("/css/reset.bar").must_equal 404
|
28
28
|
end
|
29
29
|
|
30
30
|
it ":prefix matcher should match given prefix" do
|
@@ -36,7 +36,7 @@ describe "path_matchers plugin" do
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
body("/css/reset.css").
|
40
|
-
status("/css/foo.bar").
|
39
|
+
body("/css/reset.css").must_equal '.css'
|
40
|
+
status("/css/foo.bar").must_equal 404
|
41
41
|
end
|
42
42
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
|
2
|
+
|
3
|
+
describe "path_rewriter plugin" do
|
4
|
+
it "allows rewriting remaining path or PATH_INFO" do
|
5
|
+
app(:bare) do
|
6
|
+
plugin :path_rewriter
|
7
|
+
rewrite_path '/1', '/a'
|
8
|
+
rewrite_path '/a', '/b'
|
9
|
+
rewrite_path '/c', '/d', :path_info=>true
|
10
|
+
rewrite_path '/2', '/1', :path_info=>true
|
11
|
+
rewrite_path '/3', '/h'
|
12
|
+
rewrite_path '/3', '/g', :path_info=>true
|
13
|
+
rewrite_path(/\A\/e\z/, '/f')
|
14
|
+
route do |r|
|
15
|
+
"#{r.path_info}:#{r.remaining_path}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
body('/a').must_equal '/a:/b'
|
20
|
+
body('/a/f').must_equal '/a/f:/b/f'
|
21
|
+
body('/b').must_equal '/b:/b'
|
22
|
+
body('/c').must_equal '/d:/d'
|
23
|
+
body('/c/f').must_equal '/d/f:/d/f'
|
24
|
+
body('/d').must_equal '/d:/d'
|
25
|
+
body('/e').must_equal '/e:/f'
|
26
|
+
body('/e/g').must_equal '/e/g:/e/g'
|
27
|
+
body('/1').must_equal '/1:/b'
|
28
|
+
body('/1/f').must_equal '/1/f:/b/f'
|
29
|
+
body('/2').must_equal '/1:/b'
|
30
|
+
body('/2/f').must_equal '/1/f:/b/f'
|
31
|
+
body('/3').must_equal '/g:/g'
|
32
|
+
|
33
|
+
app.freeze
|
34
|
+
body('/a').must_equal '/a:/b'
|
35
|
+
proc{app.rewrite_path '/a', '/b'}.must_raise FrozenError
|
36
|
+
end
|
37
|
+
end
|
data/spec/plugin/path_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe "path plugin" do
|
|
4
4
|
def path_app(*args, &block)
|
5
5
|
app(:bare) do
|
6
6
|
plugin :path
|
7
|
-
path
|
7
|
+
path(*args, &block)
|
8
8
|
route{|r| send(r.path_info)}
|
9
9
|
end
|
10
10
|
end
|
@@ -13,7 +13,7 @@ describe "path plugin" do
|
|
13
13
|
app(:bare) do
|
14
14
|
opts[:add_script_name] = true
|
15
15
|
plugin :path
|
16
|
-
path
|
16
|
+
path(*args, &block)
|
17
17
|
route{|r| send(r.path_info)}
|
18
18
|
end
|
19
19
|
end
|
@@ -39,75 +39,75 @@ describe "path plugin" do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
body.
|
42
|
+
body.must_equal '/foo/bar/a/baz/b'
|
43
43
|
end
|
44
44
|
|
45
45
|
it "raises if both path and block are given" do
|
46
46
|
app.plugin :path
|
47
|
-
proc{app.path(:foo, '/foo'){}}.
|
47
|
+
proc{app.path(:foo, '/foo'){}}.must_raise(Roda::RodaError)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "raises if neither path nor block are given" do
|
51
51
|
app.plugin :path
|
52
|
-
proc{app.path(:foo)}.
|
52
|
+
proc{app.path(:foo)}.must_raise(Roda::RodaError)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "raises if two options hashes are given" do
|
56
56
|
app.plugin :path
|
57
|
-
proc{app.path(:foo, {:name=>'a'}, :add_script_name=>true)}.
|
57
|
+
proc{app.path(:foo, {:name=>'a'}, :add_script_name=>true)}.must_raise(Roda::RodaError)
|
58
58
|
end
|
59
59
|
|
60
60
|
it "supports :name option for naming the method" do
|
61
61
|
path_app(:foo, :name=>'foobar_route'){"/bar/foo"}
|
62
|
-
body("foobar_route").
|
62
|
+
body("foobar_route").must_equal "/bar/foo"
|
63
63
|
end
|
64
64
|
|
65
65
|
it "supports :add_script_name option for automatically adding the script name" do
|
66
66
|
path_app(:foo, :add_script_name=>true){"/bar/foo"}
|
67
|
-
body("foo_path", 'SCRIPT_NAME'=>'/baz').
|
67
|
+
body("foo_path", 'SCRIPT_NAME'=>'/baz').must_equal "/baz/bar/foo"
|
68
68
|
end
|
69
69
|
|
70
70
|
it "respects :add_script_name app option for automatically adding the script name" do
|
71
71
|
path_script_name_app(:foo){"/bar/foo"}
|
72
|
-
body("foo_path", 'SCRIPT_NAME'=>'/baz').
|
72
|
+
body("foo_path", 'SCRIPT_NAME'=>'/baz').must_equal "/baz/bar/foo"
|
73
73
|
end
|
74
74
|
|
75
75
|
it "supports :add_script_name=>false option for not automatically adding the script name" do
|
76
76
|
path_script_name_app(:foo, :add_script_name=>false){"/bar/foo"}
|
77
|
-
body("foo_path", 'SCRIPT_NAME'=>'/baz').
|
77
|
+
body("foo_path", 'SCRIPT_NAME'=>'/baz').must_equal "/bar/foo"
|
78
78
|
end
|
79
79
|
|
80
80
|
it "supports path method accepting a block when using :add_script_name" do
|
81
81
|
path_block_app(lambda{"c"}, :foo, :add_script_name=>true){|&block| "/bar/foo/#{block.call}"}
|
82
|
-
body("foo_path", 'SCRIPT_NAME'=>'/baz').
|
82
|
+
body("foo_path", 'SCRIPT_NAME'=>'/baz').must_equal "/baz/bar/foo/c"
|
83
83
|
end
|
84
84
|
|
85
85
|
it "supports :url option for also creating a *_url method" do
|
86
86
|
path_app(:foo, :url=>true){"/bar/foo"}
|
87
|
-
body("foo_path", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).
|
88
|
-
body("foo_url", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).
|
87
|
+
body("foo_path", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).must_equal "/bar/foo"
|
88
|
+
body("foo_url", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).must_equal "http://example.org/bar/foo"
|
89
89
|
end
|
90
90
|
|
91
91
|
it "supports url method accepting a block when using :url" do
|
92
92
|
path_block_app(lambda{"c"}, :foo, :url=>true){|&block| "/bar/foo/#{block.call}"}
|
93
|
-
body("foo_url", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).
|
93
|
+
body("foo_url", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).must_equal "http://example.org/bar/foo/c"
|
94
94
|
end
|
95
95
|
|
96
96
|
it "supports url method name specified in :url option" do
|
97
97
|
path_app(:foo, :url=>:foobar_uri){"/bar/foo"}
|
98
|
-
body("foo_path", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).
|
99
|
-
body("foobar_uri", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).
|
98
|
+
body("foo_path", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).must_equal "/bar/foo"
|
99
|
+
body("foobar_uri", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).must_equal "http://example.org/bar/foo"
|
100
100
|
end
|
101
101
|
|
102
102
|
it "supports :url_only option for not creating a path method" do
|
103
103
|
path_app(:foo, :url_only=>true){"/bar/foo"}
|
104
|
-
proc{body("foo_path")}.
|
105
|
-
body("foo_url", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).
|
104
|
+
proc{body("foo_path")}.must_raise(NoMethodError)
|
105
|
+
body("foo_url", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>80).must_equal "http://example.org/bar/foo"
|
106
106
|
end
|
107
107
|
|
108
108
|
it "handles non-default ports in url methods" do
|
109
109
|
path_app(:foo, :url=>true){"/bar/foo"}
|
110
|
-
body("foo_url", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>81).
|
110
|
+
body("foo_url", 'HTTP_HOST'=>'example.org', "rack.url_scheme"=>'http', 'SERVER_PORT'=>81).must_equal "http://example.org:81/bar/foo"
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -127,42 +127,42 @@ describe "path plugin" do
|
|
127
127
|
|
128
128
|
it "Roda#path respects classes and symbols registered via Roda.path" do
|
129
129
|
# Strings
|
130
|
-
body('path'=>'/foo/bar').
|
130
|
+
body('path'=>'/foo/bar').must_equal '/foo/bar'
|
131
131
|
|
132
132
|
# Classes
|
133
|
-
body('path'=>@obj).
|
134
|
-
body('path'=>[@obj, 'foo']).
|
135
|
-
body('path'=>[@obj, 'foo', 'bar']).
|
133
|
+
body('path'=>@obj).must_equal '/d/1/'
|
134
|
+
body('path'=>[@obj, 'foo']).must_equal '/d/1/foo'
|
135
|
+
body('path'=>[@obj, 'foo', 'bar']).must_equal '/d/1/foo/bar'
|
136
136
|
end
|
137
137
|
|
138
138
|
it "Roda#path raises an error for an unrecognized class" do
|
139
139
|
# Strings
|
140
|
-
proc{body('path'=>:foo)}.
|
140
|
+
proc{body('path'=>:foo)}.must_raise(Roda::RodaError)
|
141
141
|
end
|
142
142
|
|
143
143
|
it "Roda#path respects :add_script_name app option" do
|
144
144
|
app.opts[:add_script_name] = true
|
145
145
|
|
146
146
|
# Strings
|
147
|
-
body('path'=>'/foo/bar', 'SCRIPT_NAME'=>'/baz').
|
147
|
+
body('path'=>'/foo/bar', 'SCRIPT_NAME'=>'/baz').must_equal '/baz/foo/bar'
|
148
148
|
|
149
149
|
# Classes
|
150
|
-
body('path'=>@obj, 'SCRIPT_NAME'=>'/baz').
|
151
|
-
body('path'=>[@obj, 'foo'], 'SCRIPT_NAME'=>'/baz').
|
152
|
-
body('path'=>[@obj, 'foo', 'bar'], 'SCRIPT_NAME'=>'/baz').
|
150
|
+
body('path'=>@obj, 'SCRIPT_NAME'=>'/baz').must_equal '/baz/d/1/'
|
151
|
+
body('path'=>[@obj, 'foo'], 'SCRIPT_NAME'=>'/baz').must_equal '/baz/d/1/foo'
|
152
|
+
body('path'=>[@obj, 'foo', 'bar'], 'SCRIPT_NAME'=>'/baz').must_equal '/baz/d/1/foo/bar'
|
153
153
|
end
|
154
154
|
|
155
155
|
it "Roda#path works in subclasses" do
|
156
156
|
old_app = @app
|
157
157
|
@app = Class.new(@app)
|
158
158
|
@app.route{|r| path('/a')}
|
159
|
-
body.
|
159
|
+
body.must_equal '/a'
|
160
160
|
|
161
161
|
@app.path(String){|b| "/foo#{b}"}
|
162
|
-
body.
|
162
|
+
body.must_equal '/foo/a'
|
163
163
|
|
164
164
|
@app = old_app
|
165
|
-
body('path'=>'/a').
|
165
|
+
body('path'=>'/a').must_equal '/a'
|
166
166
|
end
|
167
167
|
|
168
168
|
it "registers classes by reference by default" do
|
@@ -172,8 +172,8 @@ describe "path plugin" do
|
|
172
172
|
def c2.name; 'C'; end
|
173
173
|
@app.path(c1){'/c'}
|
174
174
|
@app.route{|r| path(r.env['c'])}
|
175
|
-
body('c'=>c1.new).
|
176
|
-
proc{body('c'=>c2.new)}.
|
175
|
+
body('c'=>c1.new).must_equal '/c'
|
176
|
+
proc{body('c'=>c2.new)}.must_raise(Roda::RodaError)
|
177
177
|
end
|
178
178
|
|
179
179
|
it ":by_name => option registers classes by name" do
|
@@ -184,29 +184,30 @@ describe "path plugin" do
|
|
184
184
|
@app.plugin :path, :by_name=>true
|
185
185
|
@app.path(c1){'/c'}
|
186
186
|
@app.route{|r| path(r.env['c'])}
|
187
|
-
body('c'=>c1.new).
|
188
|
-
body('c'=>c2.new).
|
187
|
+
body('c'=>c1.new).must_equal '/c'
|
188
|
+
body('c'=>c2.new).must_equal '/c'
|
189
189
|
end
|
190
190
|
|
191
191
|
it "Roda.path_block returns the block used" do
|
192
192
|
c = Class.new
|
193
193
|
b = proc{|x| x.to_s}
|
194
194
|
@app.path(c, &b)
|
195
|
-
|
195
|
+
# Work around minitest bug
|
196
|
+
assert_equal @app.path_block(c), b
|
196
197
|
end
|
197
198
|
|
198
199
|
it "Roda.path doesn't work with classes without blocks" do
|
199
|
-
proc{app.path(Class.new)}.
|
200
|
+
proc{app.path(Class.new)}.must_raise(Roda::RodaError)
|
200
201
|
end
|
201
202
|
|
202
203
|
it "Roda.path doesn't work with classes with paths or options" do
|
203
|
-
proc{app.path(Class.new, '/a'){}}.
|
204
|
-
proc{app.path(Class.new, nil, :a=>1){}}.
|
204
|
+
proc{app.path(Class.new, '/a'){}}.must_raise(Roda::RodaError)
|
205
|
+
proc{app.path(Class.new, nil, :a=>1){}}.must_raise(Roda::RodaError)
|
205
206
|
end
|
206
207
|
|
207
208
|
it "Roda.path doesn't work after freezing the app" do
|
208
209
|
app.freeze
|
209
|
-
proc{app.path(Class.new){|obj| ''}}.
|
210
|
+
proc{app.path(Class.new){|obj| ''}}.must_raise FrozenError
|
210
211
|
end
|
211
212
|
end
|
212
213
|
|
@@ -16,12 +16,12 @@ describe "per_thread_caching plugin" do
|
|
16
16
|
(0..10).map do |n|
|
17
17
|
Thread.new do
|
18
18
|
Thread.current[:n] = n
|
19
|
-
body('/a').
|
20
|
-
body('/a').
|
21
|
-
body('/a').
|
22
|
-
body('/b').
|
23
|
-
body('/b').
|
24
|
-
body('/b').
|
19
|
+
_(body('/a')).must_equal '2'
|
20
|
+
_(body('/a')).must_equal '22'
|
21
|
+
_(body('/a')).must_equal '222'
|
22
|
+
_(body('/b')).must_equal '2'
|
23
|
+
_(body('/b')).must_equal '22'
|
24
|
+
_(body('/b')).must_equal '222'
|
25
25
|
end
|
26
26
|
end.map{|t| t.join}
|
27
27
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'tilt/erb'
|
5
|
+
rescue LoadError
|
6
|
+
warn "tilt not installed, skipping precompiled_templates plugin test"
|
7
|
+
else
|
8
|
+
describe "precompile_templates plugin" do
|
9
|
+
it "adds support for template precompilation" do
|
10
|
+
app(:bare) do
|
11
|
+
plugin :render, :views=>'spec/views'
|
12
|
+
plugin :precompile_templates
|
13
|
+
route do |r|
|
14
|
+
@a = 1
|
15
|
+
render('iv')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].must_equal nil
|
20
|
+
app.precompile_templates 'spec/views/iv.erb'
|
21
|
+
app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].wont_equal nil
|
22
|
+
app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].instance_variable_get(:@compiled_method)[[]].wont_equal nil
|
23
|
+
body.strip.must_equal '1'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "adds support for template precompilation with :locals" do
|
27
|
+
app(:bare) do
|
28
|
+
plugin :render, :views=>'spec/views'
|
29
|
+
plugin :precompile_templates
|
30
|
+
route do |r|
|
31
|
+
render('about', :locals=>{:title=>'1'})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
app.render_opts[:cache][File.expand_path('spec/views/about.erb')].must_equal nil
|
36
|
+
app.precompile_templates 'spec/views/about.erb', :locals=>[:title]
|
37
|
+
app.render_opts[:cache][File.expand_path('spec/views/about.erb')].wont_equal nil
|
38
|
+
app.render_opts[:cache][File.expand_path('spec/views/about.erb')].instance_variable_get(:@compiled_method)[[:title]].wont_equal nil
|
39
|
+
body.strip.must_equal '<h1>1</h1>'
|
40
|
+
end
|
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_equal 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
|
+
it "adds support for template precompilation with :inline" do
|
59
|
+
app(:bare) do
|
60
|
+
plugin :render, :views=>'spec/views'
|
61
|
+
plugin :precompile_templates
|
62
|
+
route do |r|
|
63
|
+
render(:inline=>'a', :cache_key=>'a')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
app.render_opts[:cache]['a'].must_equal nil
|
68
|
+
app.precompile_templates :inline=>'a', :cache_key=>'a'
|
69
|
+
app.render_opts[:cache]['a'].wont_equal nil
|
70
|
+
app.render_opts[:cache]['a'].instance_variable_get(:@compiled_method)[[]].wont_equal nil
|
71
|
+
body.strip.must_equal "a"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|