roda 0.9.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +62 -0
  3. data/README.rdoc +362 -167
  4. data/Rakefile +2 -2
  5. data/doc/release_notes/1.0.0.txt +329 -0
  6. data/lib/roda.rb +553 -180
  7. data/lib/roda/plugins/_erubis_escaping.rb +28 -0
  8. data/lib/roda/plugins/all_verbs.rb +7 -9
  9. data/lib/roda/plugins/backtracking_array.rb +92 -0
  10. data/lib/roda/plugins/content_for.rb +46 -0
  11. data/lib/roda/plugins/csrf.rb +60 -0
  12. data/lib/roda/plugins/flash.rb +53 -7
  13. data/lib/roda/plugins/halt.rb +8 -14
  14. data/lib/roda/plugins/head.rb +56 -0
  15. data/lib/roda/plugins/header_matchers.rb +2 -2
  16. data/lib/roda/plugins/json.rb +84 -0
  17. data/lib/roda/plugins/multi_route.rb +50 -10
  18. data/lib/roda/plugins/not_allowed.rb +140 -0
  19. data/lib/roda/plugins/pass.rb +13 -6
  20. data/lib/roda/plugins/per_thread_caching.rb +70 -0
  21. data/lib/roda/plugins/render.rb +20 -33
  22. data/lib/roda/plugins/render_each.rb +61 -0
  23. data/lib/roda/plugins/symbol_matchers.rb +79 -0
  24. data/lib/roda/plugins/symbol_views.rb +40 -0
  25. data/lib/roda/plugins/view_subdirs.rb +53 -0
  26. data/lib/roda/version.rb +3 -0
  27. data/spec/matchers_spec.rb +61 -5
  28. data/spec/plugin/_erubis_escaping_spec.rb +29 -0
  29. data/spec/plugin/backtracking_array_spec.rb +38 -0
  30. data/spec/plugin/content_for_spec.rb +34 -0
  31. data/spec/plugin/csrf_spec.rb +49 -0
  32. data/spec/plugin/flash_spec.rb +69 -5
  33. data/spec/plugin/head_spec.rb +35 -0
  34. data/spec/plugin/json_spec.rb +50 -0
  35. data/spec/plugin/multi_route_spec.rb +22 -6
  36. data/spec/plugin/not_allowed_spec.rb +55 -0
  37. data/spec/plugin/pass_spec.rb +8 -2
  38. data/spec/plugin/per_thread_caching_spec.rb +28 -0
  39. data/spec/plugin/render_each_spec.rb +30 -0
  40. data/spec/plugin/render_spec.rb +7 -1
  41. data/spec/plugin/symbol_matchers_spec.rb +68 -0
  42. data/spec/plugin/symbol_views_spec.rb +32 -0
  43. data/spec/plugin/view_subdirs_spec.rb +45 -0
  44. data/spec/plugin_spec.rb +11 -1
  45. data/spec/redirect_spec.rb +21 -4
  46. data/spec/request_spec.rb +9 -0
  47. metadata +49 -5
@@ -0,0 +1,28 @@
1
+ require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
2
+
3
+ describe "per_thread_caching plugin" do
4
+ it "should use a per thread cache instead of a shared cache" do
5
+ app(:bare) do
6
+ plugin :per_thread_caching
7
+ @c = thread_safe_cache
8
+ def self.c; @c end
9
+ route do |r|
10
+ r.on :id do |i|
11
+ ((self.class.c[i] ||= []) << 2).join
12
+ end
13
+ end
14
+ end
15
+
16
+ (0..10).map do |n|
17
+ Thread.new do
18
+ Thread.current[:n] = n
19
+ body('/a').should == '2'
20
+ body('/a').should == '22'
21
+ body('/a').should == '222'
22
+ body('/b').should == '2'
23
+ body('/b').should == '22'
24
+ body('/b').should == '222'
25
+ end
26
+ end.map{|t| t.join}
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
2
+
3
+ describe "render_each plugin" do
4
+ it "calls render with each argument, returning joined string with all results" do
5
+ app(:bare) do
6
+ plugin :render_each
7
+ def render(t, opts)
8
+ "r#{t}#{opts[:locals][:foo] if opts[:locals]}#{opts[:bar]} "
9
+ end
10
+
11
+ route do |r|
12
+ r.root do
13
+ render_each([1,2,3], :foo)
14
+ end
15
+
16
+ r.is 'a' do
17
+ render_each([1,2,3], :bar, :local=>:foo, :bar=>4)
18
+ end
19
+
20
+ r.is 'b' do
21
+ render_each([1,2,3], :bar, :local=>nil)
22
+ end
23
+ end
24
+ end
25
+
26
+ body.should == 'rfoo1 rfoo2 rfoo3 '
27
+ body("/a").should == 'rbar14 rbar24 rbar34 '
28
+ body("/b").should == 'rbar rbar rbar '
29
+ end
30
+ end
@@ -1,7 +1,8 @@
1
1
  require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
2
2
 
3
3
  begin
4
- require 'tilt'
4
+ require 'tilt/erb'
5
+ require 'tilt/string'
5
6
  rescue LoadError
6
7
  warn "tilt not installed, skipping render plugin test"
7
8
  else
@@ -27,6 +28,10 @@ describe "render plugin" do
27
28
  r.on "path" do
28
29
  render(:path=>"./spec/views/about.erb", :locals=>{:title => "Path"}, :layout_opts=>{:locals=>{:title=>"Home"}})
29
30
  end
31
+
32
+ r.on "content" do
33
+ view(:content=>'bar', :layout_opts=>{:locals=>{:title=>"Home"}})
34
+ end
30
35
  end
31
36
  end
32
37
  end
@@ -36,6 +41,7 @@ describe "render plugin" do
36
41
  body("/home").strip.should == "<title>Roda: Home</title>\n<h1>Home</h1>\n<p>Hello Agent Smith</p>"
37
42
  body("/inline").strip.should == "Hello Agent Smith"
38
43
  body("/path").strip.should == "<h1>Path</h1>"
44
+ body("/content").strip.should == "<title>Roda: Home</title>\nbar"
39
45
  end
40
46
 
41
47
  it "with str as engine" do
@@ -0,0 +1,68 @@
1
+ require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
2
+
3
+ describe "symbol_matchers plugin" do
4
+ it "allows symbol specific regexps" do
5
+ app(:bare) do
6
+ plugin :symbol_matchers
7
+ symbol_matcher(:f, /(f+)/)
8
+
9
+ route do |r|
10
+ r.is :d do |d|
11
+ "d#{d}"
12
+ end
13
+
14
+ r.is "foo:optd" do |o|
15
+ "foo#{o.inspect}"
16
+ end
17
+
18
+ r.is "bar:opt" do |o|
19
+ "bar#{o.inspect}"
20
+ end
21
+
22
+ r.is "format:format" do |f|
23
+ "format#{f.inspect}"
24
+ end
25
+
26
+ r.is :f do |f|
27
+ "f#{f}"
28
+ end
29
+
30
+ r.is 'q:rest' do |r|
31
+ "rest#{r}"
32
+ end
33
+
34
+ r.is :w do |w|
35
+ "w#{w}"
36
+ end
37
+
38
+ r.is ':d/:w/:f' do |d, w, f|
39
+ "dwf#{d}#{w}#{f}"
40
+ end
41
+ end
42
+ end
43
+
44
+ status.should == 404
45
+ body("/1").should == 'd1'
46
+ body("/11232135").should == 'd11232135'
47
+ body("/a").should == 'wa'
48
+ body("/1az0").should == 'w1az0'
49
+ body("/f").should == 'ff'
50
+ body("/foo").should == 'foonil'
51
+ body("/foo/123").should == 'foo"123"'
52
+ status("/foo/bar").should == 404
53
+ status("/foo/123/a").should == 404
54
+ body("/bar").should == 'barnil'
55
+ body("/bar/foo").should == 'bar"foo"'
56
+ status("/bar/foo/baz").should == 404
57
+ body("/format").should == 'formatnil'
58
+ body("/format.json").should == 'format"json"'
59
+ status("/format.").should == 404
60
+ body("/ffffffffffffffff").should == 'fffffffffffffffff'
61
+ status("/-").should == 404
62
+ body("/1/1a/f").should == 'dwf11af'
63
+ body("/12/1azy/fffff").should == 'dwf121azyfffff'
64
+ status("/1/f/a").should == 404
65
+ body("/qa/b/c/d//f/g").should == 'resta/b/c/d//f/g'
66
+ body('/q').should == 'rest'
67
+ end
68
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
2
+
3
+ describe "symbol_views plugin" do
4
+ before do
5
+ app(:bare) do
6
+ plugin :symbol_views
7
+
8
+ def view(s)
9
+ "v#{s}"
10
+ end
11
+
12
+ route do |r|
13
+ r.root do
14
+ :sym
15
+ end
16
+
17
+ r.is "string" do
18
+ 'string'
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ it "should call view with the symbol" do
25
+ body.should == "vsym"
26
+ end
27
+
28
+ it "should not affect other return types" do
29
+ body("/string").should == 'string'
30
+ body("/foo").should == ''
31
+ end
32
+ end
@@ -0,0 +1,45 @@
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 view_subdirs plugin test"
7
+ else
8
+ describe "view_subdirs plugin" do
9
+ before do
10
+ app(:bare) do
11
+ plugin :render
12
+ render_opts[:views] = "./spec"
13
+ plugin :view_subdirs
14
+
15
+ route do |r|
16
+ r.on "home" do
17
+ set_view_subdir 'views'
18
+ view("home", :locals=>{:name => "Agent Smith", :title => "Home"}, :layout_opts=>{:locals=>{:title=>"Home"}})
19
+ end
20
+
21
+ r.on "about" do
22
+ set_view_subdir 'views'
23
+ render("views/about", :locals=>{:title => "About Roda"})
24
+ end
25
+
26
+ r.on "path" do
27
+ render('views/about', :locals=>{:title => "Path"}, :layout_opts=>{:locals=>{:title=>"Home"}})
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ it "should use set subdir if template name does not contain a slash" do
34
+ body("/home").strip.should == "<title>Roda: Home</title>\n<h1>Home</h1>\n<p>Hello Agent Smith</p>"
35
+ end
36
+
37
+ it "should not use set subdir if template name contains a slash" do
38
+ body("/about").strip.should == "<h1>About Roda</h1>"
39
+ end
40
+
41
+ it "should not change behavior when subdir is not set" do
42
+ body("/path").strip.should == "<h1>Path</h1>"
43
+ end
44
+ end
45
+ end
@@ -15,10 +15,20 @@ describe "plugins" do
15
15
  end
16
16
  self::RequestMethods = Module.new do
17
17
  def hello(&block)
18
- on 'hello', &block
18
+ on self.class.hello, &block
19
+ end
20
+ end
21
+ self::RequestClassMethods = Module.new do
22
+ def hello(&block)
23
+ 'hello'
19
24
  end
20
25
  end
21
26
  self::ResponseMethods = Module.new do
27
+ def foobar
28
+ self.class.foobar
29
+ end
30
+ end
31
+ self::ResponseClassMethods = Module.new do
22
32
  def foobar
23
33
  "Default "
24
34
  end
@@ -3,14 +3,25 @@ require File.expand_path("spec_helper", File.dirname(__FILE__))
3
3
  describe "redirects" do
4
4
  it "should be immediately processed" do
5
5
  app do |r|
6
- r.on "about" do
7
- r.redirect "/hello", 301
6
+ r.root do
7
+ r.redirect "/hello"
8
8
  "Foo"
9
9
  end
10
- r.on do
11
- r.redirect "/hello"
10
+
11
+ r.is "about" do
12
+ r.redirect "/hello", 301
12
13
  "Foo"
13
14
  end
15
+
16
+ r.is 'foo' do
17
+ r.get do
18
+ r.redirect
19
+ end
20
+
21
+ r.post do
22
+ r.redirect
23
+ end
24
+ end
14
25
  end
15
26
 
16
27
  status.should == 302
@@ -20,5 +31,11 @@ describe "redirects" do
20
31
  status("/about").should == 301
21
32
  header('Location', "/about").should == '/hello'
22
33
  body("/about").should == ''
34
+
35
+ status("/foo", 'REQUEST_METHOD'=>'POST').should == 302
36
+ header('Location', "/foo", 'REQUEST_METHOD'=>'POST').should == '/foo'
37
+ body("/foo", 'REQUEST_METHOD'=>'POST').should == ''
38
+
39
+ proc{req('/foo')}.should raise_error(Roda::RodaError)
23
40
  end
24
41
  end
@@ -20,6 +20,15 @@ describe "request.halt" do
20
20
 
21
21
  body.should == "foo"
22
22
  end
23
+
24
+ it "should use current response if no argument is given" do
25
+ app do |r|
26
+ response.write('foo')
27
+ r.halt
28
+ end
29
+
30
+ body.should == "foo"
31
+ end
23
32
  end
24
33
 
25
34
  describe "request.scope" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-30 00:00:00.000000000 Z
11
+ date: 2014-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: sinatra-flash
42
+ name: tilt
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,21 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: tilt
56
+ name: erubis
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack_csrf
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -71,49 +85,79 @@ email:
71
85
  - code@jeremyevans.net
72
86
  executables: []
73
87
  extensions: []
74
- extra_rdoc_files: []
88
+ extra_rdoc_files:
89
+ - README.rdoc
90
+ - MIT-LICENSE
91
+ - CHANGELOG
92
+ - doc/release_notes/1.0.0.txt
75
93
  files:
76
94
  - CHANGELOG
77
95
  - MIT-LICENSE
78
96
  - README.rdoc
79
97
  - Rakefile
98
+ - doc/release_notes/1.0.0.txt
80
99
  - lib/roda.rb
100
+ - lib/roda/plugins/_erubis_escaping.rb
81
101
  - lib/roda/plugins/all_verbs.rb
102
+ - lib/roda/plugins/backtracking_array.rb
103
+ - lib/roda/plugins/content_for.rb
104
+ - lib/roda/plugins/csrf.rb
82
105
  - lib/roda/plugins/default_headers.rb
83
106
  - lib/roda/plugins/error_handler.rb
84
107
  - lib/roda/plugins/flash.rb
85
108
  - lib/roda/plugins/h.rb
86
109
  - lib/roda/plugins/halt.rb
110
+ - lib/roda/plugins/head.rb
87
111
  - lib/roda/plugins/header_matchers.rb
88
112
  - lib/roda/plugins/hooks.rb
89
113
  - lib/roda/plugins/indifferent_params.rb
114
+ - lib/roda/plugins/json.rb
90
115
  - lib/roda/plugins/middleware.rb
91
116
  - lib/roda/plugins/multi_route.rb
117
+ - lib/roda/plugins/not_allowed.rb
92
118
  - lib/roda/plugins/not_found.rb
93
119
  - lib/roda/plugins/pass.rb
120
+ - lib/roda/plugins/per_thread_caching.rb
94
121
  - lib/roda/plugins/render.rb
122
+ - lib/roda/plugins/render_each.rb
95
123
  - lib/roda/plugins/streaming.rb
124
+ - lib/roda/plugins/symbol_matchers.rb
125
+ - lib/roda/plugins/symbol_views.rb
126
+ - lib/roda/plugins/view_subdirs.rb
127
+ - lib/roda/version.rb
96
128
  - spec/composition_spec.rb
97
129
  - spec/env_spec.rb
98
130
  - spec/integration_spec.rb
99
131
  - spec/matchers_spec.rb
100
132
  - spec/module_spec.rb
101
133
  - spec/opts_spec.rb
134
+ - spec/plugin/_erubis_escaping_spec.rb
102
135
  - spec/plugin/all_verbs_spec.rb
136
+ - spec/plugin/backtracking_array_spec.rb
137
+ - spec/plugin/content_for_spec.rb
138
+ - spec/plugin/csrf_spec.rb
103
139
  - spec/plugin/default_headers_spec.rb
104
140
  - spec/plugin/error_handler_spec.rb
105
141
  - spec/plugin/flash_spec.rb
106
142
  - spec/plugin/h_spec.rb
107
143
  - spec/plugin/halt_spec.rb
144
+ - spec/plugin/head_spec.rb
108
145
  - spec/plugin/header_matchers_spec.rb
109
146
  - spec/plugin/hooks_spec.rb
110
147
  - spec/plugin/indifferent_params_spec.rb
148
+ - spec/plugin/json_spec.rb
111
149
  - spec/plugin/middleware_spec.rb
112
150
  - spec/plugin/multi_route_spec.rb
151
+ - spec/plugin/not_allowed_spec.rb
113
152
  - spec/plugin/not_found_spec.rb
114
153
  - spec/plugin/pass_spec.rb
154
+ - spec/plugin/per_thread_caching_spec.rb
155
+ - spec/plugin/render_each_spec.rb
115
156
  - spec/plugin/render_spec.rb
116
157
  - spec/plugin/streaming_spec.rb
158
+ - spec/plugin/symbol_matchers_spec.rb
159
+ - spec/plugin/symbol_views_spec.rb
160
+ - spec/plugin/view_subdirs_spec.rb
117
161
  - spec/plugin_spec.rb
118
162
  - spec/redirect_spec.rb
119
163
  - spec/request_spec.rb