roda 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +34 -0
  3. data/Rakefile +22 -46
  4. data/doc/release_notes/2.3.0.txt +109 -0
  5. data/lib/roda/plugins/assets.rb +2 -1
  6. data/lib/roda/plugins/caching.rb +1 -1
  7. data/lib/roda/plugins/chunked.rb +1 -1
  8. data/lib/roda/plugins/error_email.rb +1 -1
  9. data/lib/roda/plugins/head.rb +6 -0
  10. data/lib/roda/plugins/heartbeat.rb +40 -0
  11. data/lib/roda/plugins/json.rb +23 -3
  12. data/lib/roda/plugins/json_parser.rb +72 -0
  13. data/lib/roda/plugins/mailer.rb +22 -5
  14. data/lib/roda/plugins/named_templates.rb +2 -2
  15. data/lib/roda/plugins/path_rewriter.rb +82 -0
  16. data/lib/roda/plugins/precompile_templates.rb +87 -0
  17. data/lib/roda/plugins/render.rb +111 -43
  18. data/lib/roda/plugins/render_each.rb +1 -1
  19. data/lib/roda/plugins/shared_vars.rb +1 -1
  20. data/lib/roda/plugins/view_options.rb +28 -3
  21. data/lib/roda/version.rb +1 -1
  22. data/spec/composition_spec.rb +3 -3
  23. data/spec/env_spec.rb +1 -1
  24. data/spec/freeze_spec.rb +6 -6
  25. data/spec/integration_spec.rb +16 -15
  26. data/spec/matchers_spec.rb +110 -110
  27. data/spec/opts_spec.rb +8 -8
  28. data/spec/plugin/_erubis_escaping_spec.rb +34 -3
  29. data/spec/plugin/all_verbs_spec.rb +8 -8
  30. data/spec/plugin/assets_spec.rb +164 -150
  31. data/spec/plugin/backtracking_array_spec.rb +18 -18
  32. data/spec/plugin/caching_spec.rb +70 -70
  33. data/spec/plugin/chunked_spec.rb +38 -38
  34. data/spec/plugin/class_level_routing_spec.rb +78 -78
  35. data/spec/plugin/content_for_spec.rb +2 -2
  36. data/spec/plugin/cookies_spec.rb +4 -4
  37. data/spec/plugin/csrf_spec.rb +8 -8
  38. data/spec/plugin/default_headers_spec.rb +6 -6
  39. data/spec/plugin/delay_build_spec.rb +7 -6
  40. data/spec/plugin/delegate_spec.rb +2 -2
  41. data/spec/plugin/delete_empty_headers_spec.rb +2 -2
  42. data/spec/plugin/drop_body_spec.rb +6 -6
  43. data/spec/plugin/empty_root_spec.rb +3 -3
  44. data/spec/plugin/environments_spec.rb +7 -7
  45. data/spec/plugin/error_email_spec.rb +23 -23
  46. data/spec/plugin/error_handler_spec.rb +14 -14
  47. data/spec/plugin/flash_spec.rb +30 -29
  48. data/spec/plugin/h_spec.rb +1 -1
  49. data/spec/plugin/halt_spec.rb +16 -16
  50. data/spec/plugin/hash_matcher_spec.rb +5 -5
  51. data/spec/plugin/head_spec.rb +10 -10
  52. data/spec/plugin/header_matchers_spec.rb +13 -13
  53. data/spec/plugin/heartbeat_spec.rb +74 -0
  54. data/spec/plugin/hooks_spec.rb +20 -20
  55. data/spec/plugin/indifferent_params_spec.rb +1 -1
  56. data/spec/plugin/json_parser_spec.rb +72 -0
  57. data/spec/plugin/json_spec.rb +22 -9
  58. data/spec/plugin/mailer_spec.rb +72 -58
  59. data/spec/plugin/match_affix_spec.rb +2 -2
  60. data/spec/plugin/middleware_spec.rb +7 -7
  61. data/spec/plugin/module_include_spec.rb +4 -4
  62. data/spec/plugin/multi_route_spec.rb +66 -66
  63. data/spec/plugin/multi_run_spec.rb +21 -21
  64. data/spec/plugin/named_templates_spec.rb +6 -6
  65. data/spec/plugin/not_allowed_spec.rb +17 -17
  66. data/spec/plugin/not_found_spec.rb +14 -14
  67. data/spec/plugin/padrino_render_spec.rb +2 -2
  68. data/spec/plugin/param_matchers_spec.rb +6 -6
  69. data/spec/plugin/partials_spec.rb +3 -3
  70. data/spec/plugin/pass_spec.rb +7 -7
  71. data/spec/plugin/path_matchers_spec.rb +6 -6
  72. data/spec/plugin/path_rewriter_spec.rb +37 -0
  73. data/spec/plugin/path_spec.rb +41 -40
  74. data/spec/plugin/per_thread_caching_spec.rb +6 -6
  75. data/spec/plugin/precompile_templates_spec.rb +74 -0
  76. data/spec/plugin/render_each_spec.rb +4 -4
  77. data/spec/plugin/render_spec.rb +179 -76
  78. data/spec/plugin/shared_vars_spec.rb +4 -4
  79. data/spec/plugin/sinatra_helpers_spec.rb +121 -121
  80. data/spec/plugin/slash_path_empty_spec.rb +10 -10
  81. data/spec/plugin/static_spec.rb +4 -4
  82. data/spec/plugin/streaming_spec.rb +11 -11
  83. data/spec/plugin/symbol_matchers_spec.rb +24 -24
  84. data/spec/plugin/symbol_views_spec.rb +3 -3
  85. data/spec/plugin/view_options_spec.rb +10 -10
  86. data/spec/plugin_spec.rb +2 -2
  87. data/spec/redirect_spec.rb +10 -10
  88. data/spec/request_spec.rb +8 -8
  89. data/spec/response_spec.rb +23 -23
  90. data/spec/session_spec.rb +4 -4
  91. data/spec/spec_helper.rb +5 -19
  92. data/spec/version_spec.rb +4 -4
  93. data/spec/views/iv.erb +1 -0
  94. metadata +16 -5
@@ -18,10 +18,10 @@ describe "error_handler plugin" do
18
18
  end
19
19
  end
20
20
 
21
- body("/a").should == 'found'
22
- status("/a").should == 200
23
- body.should == 'bad idea'
24
- status.should == 500
21
+ body("/a").must_equal 'found'
22
+ status("/a").must_equal 200
23
+ body.must_equal 'bad idea'
24
+ status.must_equal 500
25
25
  end
26
26
 
27
27
  it "executes on SyntaxError exceptions" do
@@ -41,10 +41,10 @@ describe "error_handler plugin" do
41
41
  end
42
42
  end
43
43
 
44
- body("/a").should == 'found'
45
- status("/a").should == 200
46
- body.should == 'bad idea'
47
- status.should == 500
44
+ body("/a").must_equal 'found'
45
+ status("/a").must_equal 200
46
+ body.must_equal 'bad idea'
47
+ status.must_equal 500
48
48
  end
49
49
 
50
50
  it "can override status inside error block" do
@@ -59,7 +59,7 @@ describe "error_handler plugin" do
59
59
  end
60
60
  end
61
61
 
62
- status.should == 501
62
+ status.must_equal 501
63
63
  end
64
64
 
65
65
  it "calculates correct Content-Length" do
@@ -73,7 +73,7 @@ describe "error_handler plugin" do
73
73
  end
74
74
  end
75
75
 
76
- header('Content-Length').should == "1"
76
+ header('Content-Length').must_equal "1"
77
77
  end
78
78
 
79
79
  it "clears existing headers" do
@@ -89,8 +89,8 @@ describe "error_handler plugin" do
89
89
  end
90
90
  end
91
91
 
92
- header('Content-Type').should == 'text/html'
93
- header('Foo').should == nil
92
+ header('Content-Type').must_equal 'text/html'
93
+ header('Foo').must_equal nil
94
94
  end
95
95
 
96
96
  it "can set error via the plugin block" do
@@ -104,7 +104,7 @@ describe "error_handler plugin" do
104
104
  end
105
105
  end
106
106
 
107
- body.should == 'bad idea'
107
+ body.must_equal 'bad idea'
108
108
  end
109
109
 
110
110
  it "has default error handler also raise" do
@@ -116,6 +116,6 @@ describe "error_handler plugin" do
116
116
  end
117
117
  end
118
118
 
119
- proc{req}.should raise_error(ArgumentError)
119
+ proc{req}.must_raise(ArgumentError)
120
120
  end
121
121
  end
@@ -14,7 +14,7 @@ describe "flash plugin" do
14
14
  end
15
15
  end
16
16
 
17
- body.should == 'b'
17
+ body.must_equal 'b'
18
18
  end
19
19
 
20
20
  it "flash[] sets flash for next page" do
@@ -36,88 +36,89 @@ describe "flash plugin" do
36
36
 
37
37
  env = proc{|h| h['Set-Cookie'] ? {'HTTP_COOKIE'=>h['Set-Cookie'].sub("; path=/; HttpOnly", '')} : {}}
38
38
  _, h, b = req
39
- b.join.should == ''
39
+ b.join.must_equal ''
40
40
  _, h, b = req(env[h])
41
- b.join.should == 'b'
41
+ b.join.must_equal 'b'
42
42
  _, h, b = req(env[h])
43
- b.join.should == 'bb'
43
+ b.join.must_equal 'bb'
44
44
  _, h, b = req('/a', env[h])
45
- b.join.should == 'cbbb'
45
+ b.join.must_equal 'cbbb'
46
46
  _, h, b = req(env[h])
47
- b.join.should == ''
47
+ b.join.must_equal ''
48
48
  _, h, b = req(env[h])
49
- b.join.should == 'b'
49
+ b.join.must_equal 'b'
50
50
  _, h, b = req(env[h])
51
- b.join.should == 'bb'
51
+ b.join.must_equal 'bb'
52
52
  end
53
53
  end
54
54
 
55
55
  describe "FlashHash" do
56
56
  before do
57
+ require 'roda/plugins/flash'
57
58
  @h = Roda::RodaPlugins::Flash::FlashHash.new
58
59
  end
59
60
 
60
61
  it ".new should accept nil for empty hash" do
61
62
  @h = Roda::RodaPlugins::Flash::FlashHash.new(nil)
62
- @h.now.should == {}
63
- @h.next.should == {}
63
+ @h.now.must_equal({})
64
+ @h.next.must_equal({})
64
65
  end
65
66
 
66
67
  it ".new should accept a hash" do
67
68
  @h = Roda::RodaPlugins::Flash::FlashHash.new(1=>2)
68
- @h.now.should == {1=>2}
69
- @h.next.should == {}
69
+ @h.now.must_equal(1=>2)
70
+ @h.next.must_equal({})
70
71
  end
71
72
 
72
73
  it "#[]= assigns to next flash" do
73
74
  @h[1] = 2
74
- @h.now.should == {}
75
- @h.next.should == {1=>2}
75
+ @h.now.must_equal({})
76
+ @h.next.must_equal(1=>2)
76
77
  end
77
78
 
78
79
  it "#discard removes given key from next hash" do
79
80
  @h[1] = 2
80
81
  @h[nil] = 3
81
- @h.next.should == {1=>2, nil=>3}
82
+ @h.next.must_equal(1=>2, nil=>3)
82
83
  @h.discard(nil)
83
- @h.next.should == {1=>2}
84
+ @h.next.must_equal(1=>2)
84
85
  @h.discard(1)
85
- @h.next.should == {}
86
+ @h.next.must_equal({})
86
87
  end
87
88
 
88
89
  it "#discard removes all entries from next hash with no arguments" do
89
90
  @h[1] = 2
90
91
  @h[nil] = 3
91
- @h.next.should == {1=>2, nil=>3}
92
+ @h.next.must_equal(1=>2, nil=>3)
92
93
  @h.discard
93
- @h.next.should == {}
94
+ @h.next.must_equal({})
94
95
  end
95
96
 
96
97
  it "#keep copies entry for key from current hash to next hash" do
97
98
  @h.now[1] = 2
98
99
  @h.now[nil] = 3
99
- @h.next.should == {}
100
+ @h.next.must_equal({})
100
101
  @h.keep(nil)
101
- @h.next.should == {nil=>3}
102
+ @h.next.must_equal(nil=>3)
102
103
  @h.keep(1)
103
- @h.next.should == {1=>2, nil=>3}
104
+ @h.next.must_equal(1=>2, nil=>3)
104
105
  end
105
106
 
106
107
  it "#keep copies all entries from current hash to next hash" do
107
108
  @h.now[1] = 2
108
109
  @h.now[nil] = 3
109
- @h.next.should == {}
110
+ @h.next.must_equal({})
110
111
  @h.keep
111
- @h.next.should == {1=>2, nil=>3}
112
+ @h.next.must_equal(1=>2, nil=>3)
112
113
  end
113
114
 
114
115
  it "#sweep replaces current hash with next hash" do
115
116
  @h[1] = 2
116
117
  @h[nil] = 3
117
- @h.next.should == {1=>2, nil=>3}
118
- @h.now.should == {}
119
- @h.sweep.should == {1=>2, nil=>3}
120
- @h.next.should == {}
121
- @h.now.should == {1=>2, nil=>3}
118
+ @h.next.must_equal(1=>2, nil=>3)
119
+ @h.now.must_equal({})
120
+ @h.sweep.must_equal(1=>2, nil=>3)
121
+ @h.next.must_equal({})
122
+ @h.now.must_equal(1=>2, nil=>3)
122
123
  end
123
124
  end
@@ -6,6 +6,6 @@ describe "h plugin" do
6
6
  h("<form>") + h(:form)
7
7
  end
8
8
 
9
- body.should == '&lt;form&gt;form'
9
+ body.must_equal '&lt;form&gt;form'
10
10
  end
11
11
  end
@@ -6,7 +6,7 @@ describe "halt plugin" do
6
6
  r.halt [200, {}, ['foo']]
7
7
  end
8
8
 
9
- body.should == "foo"
9
+ body.must_equal "foo"
10
10
  end
11
11
 
12
12
  it "should consider string argument as response body" do
@@ -14,7 +14,7 @@ describe "halt plugin" do
14
14
  r.halt "foo"
15
15
  end
16
16
 
17
- body.should == "foo"
17
+ body.must_equal "foo"
18
18
  end
19
19
 
20
20
  it "should consider integer argument as response status" do
@@ -22,7 +22,7 @@ describe "halt plugin" do
22
22
  r.halt 300
23
23
  end
24
24
 
25
- status.should == 300
25
+ status.must_equal 300
26
26
  end
27
27
 
28
28
  it "should consider other single arguments similar to block bodies" do
@@ -34,7 +34,7 @@ describe "halt plugin" do
34
34
  end
35
35
  end
36
36
 
37
- body.should == '{"a":1}'
37
+ body.must_equal '{"a":1}'
38
38
  end
39
39
 
40
40
  it "should consider 2 arguments as response status and body" do
@@ -42,8 +42,8 @@ describe "halt plugin" do
42
42
  r.halt 300, "foo"
43
43
  end
44
44
 
45
- status.should == 300
46
- body.should == "foo"
45
+ status.must_equal 300
46
+ body.must_equal "foo"
47
47
  end
48
48
 
49
49
  it "should handle 2nd of 2 arguments similar to block bodies" do
@@ -55,8 +55,8 @@ describe "halt plugin" do
55
55
  end
56
56
  end
57
57
 
58
- status.should == 300
59
- body.should == '{"a":1}'
58
+ status.must_equal 300
59
+ body.must_equal '{"a":1}'
60
60
  end
61
61
 
62
62
  it "should consider 3 arguments as response" do
@@ -64,9 +64,9 @@ describe "halt plugin" do
64
64
  r.halt 300, {'a'=>'b'}, "foo"
65
65
  end
66
66
 
67
- status.should == 300
68
- header('a').should == 'b'
69
- body.should == "foo"
67
+ status.must_equal 300
68
+ header('a').must_equal 'b'
69
+ body.must_equal "foo"
70
70
  end
71
71
 
72
72
  it "should handle 3rd of 3 arguments similar to block bodies" do
@@ -78,9 +78,9 @@ describe "halt plugin" do
78
78
  end
79
79
  end
80
80
 
81
- status.should == 300
82
- header('a').should == 'b'
83
- body.should == '{"a":1}'
81
+ status.must_equal 300
82
+ header('a').must_equal 'b'
83
+ body.must_equal '{"a":1}'
84
84
  end
85
85
 
86
86
  it "should raise an error for too many arguments" do
@@ -88,7 +88,7 @@ describe "halt plugin" do
88
88
  r.halt 300, {'a'=>'b'}, "foo", 1
89
89
  end
90
90
 
91
- proc{req}.should raise_error(Roda::RodaError)
91
+ proc{req}.must_raise(Roda::RodaError)
92
92
  end
93
93
 
94
94
  it "should raise an error for single argument not integer, String, or Array" do
@@ -96,6 +96,6 @@ describe "halt plugin" do
96
96
  r.halt('a'=>'b')
97
97
  end
98
98
 
99
- proc{req}.should raise_error(Roda::RodaError)
99
+ proc{req}.must_raise(Roda::RodaError)
100
100
  end
101
101
  end
@@ -18,10 +18,10 @@ describe "hash_matcher plugin" do
18
18
  end
19
19
  end
20
20
 
21
- body("/foo").should == '1foo'
22
- body("/foofoo").should == '2foofoo'
23
- body("/foofoofoo").should == '3foofoofoo'
24
- status("/foofoofoofoo").should == 404
25
- status.should == 404
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
26
  end
27
27
  end
@@ -17,19 +17,19 @@ describe "head plugin" do
17
17
  end
18
18
 
19
19
  s, h, b = req
20
- s.should == 200
21
- h['Content-Length'].should == '4'
22
- b.should == ['root']
20
+ s.must_equal 200
21
+ h['Content-Length'].must_equal '4'
22
+ b.must_equal ['root']
23
23
 
24
24
  s, h, b = req('REQUEST_METHOD' => 'HEAD')
25
- s.should == 200
26
- h['Content-Length'].should == '4'
27
- b.should == []
25
+ s.must_equal 200
26
+ h['Content-Length'].must_equal '4'
27
+ b.must_equal []
28
28
 
29
- body('/a').should == 'a'
30
- status('/a', 'REQUEST_METHOD' => 'HEAD').should == 200
29
+ body('/a').must_equal 'a'
30
+ status('/a', 'REQUEST_METHOD' => 'HEAD').must_equal 200
31
31
 
32
- body('/b').should == 'b'
33
- status('/b', 'REQUEST_METHOD' => 'HEAD').should == 200
32
+ body('/b').must_equal 'b'
33
+ status('/b', 'REQUEST_METHOD' => 'HEAD').must_equal 200
34
34
  end
35
35
  end
@@ -8,8 +8,8 @@ describe "accept matcher" do
8
8
  end
9
9
  end
10
10
 
11
- body("HTTP_ACCEPT" => "application/xml").should == "application/xml"
12
- status.should == 404
11
+ body("HTTP_ACCEPT" => "application/xml").must_equal "application/xml"
12
+ status.must_equal 404
13
13
  end
14
14
  end
15
15
 
@@ -21,8 +21,8 @@ describe "header matcher" do
21
21
  end
22
22
  end
23
23
 
24
- body("HTTP_ACCEPT" => "application/xml").should == "bar"
25
- status.should == 404
24
+ body("HTTP_ACCEPT" => "application/xml").must_equal "bar"
25
+ status.must_equal 404
26
26
  end
27
27
 
28
28
  it "should yield the header value if :match_header_yield option is present" do
@@ -36,8 +36,8 @@ describe "header matcher" do
36
36
  end
37
37
  end
38
38
 
39
- body("HTTP_ACCEPT" => "application/xml").should == "bar-application/xml"
40
- status.should == 404
39
+ body("HTTP_ACCEPT" => "application/xml").must_equal "bar-application/xml"
40
+ status.must_equal 404
41
41
  end
42
42
  end
43
43
 
@@ -49,8 +49,8 @@ describe "host matcher" do
49
49
  end
50
50
  end
51
51
 
52
- body("HTTP_HOST" => "example.com").should == 'worked'
53
- status("HTTP_HOST" => "foo.com").should == 404
52
+ body("HTTP_HOST" => "example.com").must_equal 'worked'
53
+ status("HTTP_HOST" => "foo.com").must_equal 404
54
54
  end
55
55
 
56
56
  it "should match a host with a regexp" do
@@ -60,8 +60,8 @@ describe "host matcher" do
60
60
  end
61
61
  end
62
62
 
63
- body("HTTP_HOST" => "example.com").should == 'worked'
64
- status("HTTP_HOST" => "foo.com").should == 404
63
+ body("HTTP_HOST" => "example.com").must_equal 'worked'
64
+ status("HTTP_HOST" => "foo.com").must_equal 404
65
65
  end
66
66
 
67
67
  it "doesn't yield HOST" do
@@ -71,7 +71,7 @@ describe "host matcher" do
71
71
  end
72
72
  end
73
73
 
74
- body("HTTP_HOST" => "example.com").should == '0'
74
+ body("HTTP_HOST" => "example.com").must_equal '0'
75
75
  end
76
76
  end
77
77
 
@@ -83,8 +83,8 @@ describe "user_agent matcher" do
83
83
  end
84
84
  end
85
85
 
86
- body("HTTP_USER_AGENT" => "chrome31").should == "a-chrome-31"
87
- status.should == 404
86
+ body("HTTP_USER_AGENT" => "chrome31").must_equal "a-chrome-31"
87
+ status.must_equal 404
88
88
  end
89
89
  end
90
90
 
@@ -0,0 +1,74 @@
1
+ require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
2
+
3
+ describe "heartbeat plugin" do
4
+ it "should return heartbeat response for heartbeat paths only" do
5
+ app(:bare) do
6
+ plugin :heartbeat
7
+ route do |r|
8
+ r.on 'a' do
9
+ "a"
10
+ end
11
+ end
12
+ end
13
+
14
+ body('/a').must_equal 'a'
15
+ status.must_equal 404
16
+ status('/heartbeat').must_equal 200
17
+ body('/heartbeat').must_equal 'OK'
18
+ end
19
+
20
+ it "should support custom heartbeat paths" do
21
+ app(:bare) do
22
+ plugin :heartbeat, :path=>'/heartbeat2'
23
+ route do |r|
24
+ r.on 'a' do
25
+ "a"
26
+ end
27
+ end
28
+ end
29
+
30
+ body('/a').must_equal 'a'
31
+ status.must_equal 404
32
+ status('/heartbeat').must_equal 404
33
+ status('/heartbeat2').must_equal 200
34
+ body('/heartbeat2').must_equal 'OK'
35
+ end
36
+
37
+ it "should work when using sessions" do
38
+ app(:bare) do
39
+ use Rack::Session::Cookie, :secret=>'foo'
40
+ plugin :heartbeat
41
+
42
+ route do |r|
43
+ session.clear
44
+ r.on "a" do
45
+ "a"
46
+ end
47
+ end
48
+ end
49
+
50
+ body('/a').must_equal 'a'
51
+ status.must_equal 404
52
+ status('/heartbeat').must_equal 200
53
+ body('/heartbeat').must_equal 'OK'
54
+ end
55
+
56
+ it "should work when redirecting" do
57
+ app(:bare) do
58
+ plugin :heartbeat
59
+
60
+ route do |r|
61
+ r.on "a" do
62
+ "a"
63
+ end
64
+ r.redirect '/a'
65
+ end
66
+ end
67
+
68
+ body('/a').must_equal 'a'
69
+ status.must_equal 302
70
+ status('/heartbeat').must_equal 200
71
+ body('/heartbeat').must_equal 'OK'
72
+ end
73
+ end
74
+