sinatra 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sinatra might be problematic. Click here for more details.

Files changed (95) hide show
  1. data/CHANGELOG +1 -8
  2. data/Manifest +42 -49
  3. data/README.rdoc +430 -0
  4. data/Rakefile +22 -28
  5. data/images/404.png +0 -0
  6. data/images/500.png +0 -0
  7. data/index.html +9 -0
  8. data/lib/sinatra.rb +1144 -46
  9. data/lib/sinatra/test/methods.rb +56 -0
  10. data/lib/sinatra/test/spec.rb +10 -0
  11. data/lib/sinatra/test/unit.rb +13 -0
  12. data/sinatra.gemspec +44 -40
  13. data/test/app_test.rb +150 -0
  14. data/test/application_test.rb +175 -0
  15. data/test/builder_test.rb +101 -0
  16. data/test/custom_error_test.rb +67 -0
  17. data/test/diddy_test.rb +41 -0
  18. data/test/erb_test.rb +116 -0
  19. data/test/event_context_test.rb +15 -0
  20. data/test/events_test.rb +50 -0
  21. data/test/haml_test.rb +181 -0
  22. data/test/helper.rb +3 -16
  23. data/test/mapped_error_test.rb +61 -0
  24. data/test/public/foo.xml +1 -0
  25. data/test/rest_test.rb +16 -0
  26. data/test/sass_test.rb +57 -0
  27. data/test/sessions_test.rb +40 -0
  28. data/test/streaming_test.rb +112 -0
  29. data/test/sym_params_test.rb +19 -0
  30. data/test/template_test.rb +30 -0
  31. data/test/use_in_file_templates_test.rb +48 -0
  32. data/test/views/foo.builder +1 -0
  33. data/test/views/foo.erb +1 -0
  34. data/test/views/foo.haml +1 -0
  35. data/test/views/foo.sass +2 -0
  36. data/test/views/foo_layout.erb +2 -0
  37. data/test/views/foo_layout.haml +2 -0
  38. data/test/views/layout_test/foo.builder +1 -0
  39. data/test/views/layout_test/foo.erb +1 -0
  40. data/test/views/layout_test/foo.haml +1 -0
  41. data/test/views/layout_test/foo.sass +2 -0
  42. data/test/views/layout_test/layout.builder +3 -0
  43. data/test/views/layout_test/layout.erb +1 -0
  44. data/test/views/layout_test/layout.haml +1 -0
  45. data/test/views/layout_test/layout.sass +2 -0
  46. data/test/views/no_layout/no_layout.builder +1 -0
  47. data/test/views/no_layout/no_layout.haml +1 -0
  48. metadata +122 -98
  49. data/LICENSE +0 -22
  50. data/README +0 -100
  51. data/RakeFile +0 -35
  52. data/examples/hello/hello.rb +0 -28
  53. data/examples/hello/views/hello.erb +0 -1
  54. data/examples/todo/todo.rb +0 -38
  55. data/files/default_index.erb +0 -42
  56. data/files/error.erb +0 -9
  57. data/files/logo.png +0 -0
  58. data/files/not_found.erb +0 -52
  59. data/lib/sinatra/context.rb +0 -88
  60. data/lib/sinatra/context/renderer.rb +0 -75
  61. data/lib/sinatra/core_ext/array.rb +0 -5
  62. data/lib/sinatra/core_ext/class.rb +0 -49
  63. data/lib/sinatra/core_ext/hash.rb +0 -7
  64. data/lib/sinatra/core_ext/kernel.rb +0 -16
  65. data/lib/sinatra/core_ext/metaid.rb +0 -18
  66. data/lib/sinatra/core_ext/module.rb +0 -11
  67. data/lib/sinatra/core_ext/symbol.rb +0 -5
  68. data/lib/sinatra/dispatcher.rb +0 -27
  69. data/lib/sinatra/dsl.rb +0 -176
  70. data/lib/sinatra/environment.rb +0 -15
  71. data/lib/sinatra/event.rb +0 -238
  72. data/lib/sinatra/irb.rb +0 -56
  73. data/lib/sinatra/loader.rb +0 -31
  74. data/lib/sinatra/logger.rb +0 -22
  75. data/lib/sinatra/options.rb +0 -49
  76. data/lib/sinatra/rack_ext/request.rb +0 -15
  77. data/lib/sinatra/route.rb +0 -65
  78. data/lib/sinatra/server.rb +0 -57
  79. data/lib/sinatra/sessions.rb +0 -21
  80. data/lib/sinatra/test_methods.rb +0 -55
  81. data/site/index.htm +0 -104
  82. data/site/index.html +0 -104
  83. data/site/logo.png +0 -0
  84. data/test/sinatra/dispatcher_test.rb +0 -91
  85. data/test/sinatra/event_test.rb +0 -46
  86. data/test/sinatra/renderer_test.rb +0 -47
  87. data/test/sinatra/request_test.rb +0 -21
  88. data/test/sinatra/route_test.rb +0 -21
  89. data/test/sinatra/static_files/foo.txt +0 -1
  90. data/test/sinatra/static_files_test.rb +0 -48
  91. data/test/sinatra/url_test.rb +0 -18
  92. data/vendor/erb/init.rb +0 -3
  93. data/vendor/erb/lib/erb.rb +0 -41
  94. data/vendor/haml/init.rb +0 -3
  95. data/vendor/haml/lib/haml.rb +0 -41
Binary file
@@ -1,91 +0,0 @@
1
- require File.dirname(__FILE__) + '/../helper'
2
-
3
- describe "When a dispatcher receives a request" do
4
-
5
- before(:each) do
6
- Sinatra::EventManager.reset!
7
- end
8
-
9
- it "should attend to the event" do
10
-
11
- Sinatra::Event.new(:get, '/') do
12
- body 'this is the index as a get'
13
- end
14
-
15
- get_it "/"
16
-
17
- status.should.equal 200
18
- text.should.equal 'this is the index as a get'
19
- headers['Content-Type'].should.equal 'text/html'
20
-
21
- post_it "/"
22
-
23
- status.should.equal 404
24
- text.scan("Not Found :: Sinatra").size.should.equal 1
25
- headers['Content-Type'].should.equal 'text/html'
26
-
27
- get_it '/foo'
28
-
29
- status.should.equal 404
30
- text.scan("Not Found :: Sinatra").size.should.equal 1
31
-
32
- end
33
-
34
- it "should use custom error pages if present" do
35
- Sinatra::Event.new(:get, 404) do
36
- body 'custom 404'
37
- end
38
-
39
- get_it('/laksdjf').should.equal 'custom 404'
40
- end
41
-
42
- it "should reload app files unless in production" do
43
- Sinatra::Event.new(:get, '/') {}
44
-
45
- Sinatra::Options.expects(:environment).returns(:production)
46
- Sinatra::Loader.expects(:reload!).never
47
- get_it '/'
48
-
49
- Sinatra::Options.expects(:environment).returns(:development)
50
- Sinatra::Loader.expects(:reload!)
51
- get_it '/'
52
- end
53
-
54
- it "should not register not_found (otherwise we'll have a newone in the array for every error)" do
55
- Sinatra::EventManager.events.size.should.equal 0
56
- get_it '/blake'
57
- Sinatra::EventManager.events.size.should.equal 0
58
- end
59
-
60
- it "should return blocks result if body not called" do
61
- event = Sinatra::Event.new(:get, '/return_block') do
62
- 'no body called'
63
- end
64
-
65
- get_it '/return_block'
66
-
67
- status.should.equal 200
68
- html.should.equal 'no body called'
69
- end
70
-
71
- it "should recognize pretty urls" do
72
- Sinatra::Event.new(:get, '/test/:name') do
73
- params[:name]
74
- end
75
-
76
- get_it '/test/blake'
77
- body.should.equal 'blake'
78
- end
79
-
80
- it "should respond to DELETE and PUT" do
81
- Sinatra::Event.new(:delete, '/') do
82
- request.request_method
83
- end
84
-
85
- # Browser only know GET and POST. DELETE and PUT are signaled by passing in a _method paramater
86
- post_it '/', :_method => 'DELETE'
87
- status.should.equal 200
88
- text.should.equal 'DELETE'
89
- end
90
-
91
- end
@@ -1,46 +0,0 @@
1
- require File.dirname(__FILE__) + '/../helper'
2
-
3
- describe "Event" do
4
-
5
- before(:each) do
6
- Sinatra::EventManager.reset!
7
- end
8
-
9
- it "should return 500 if exception thrown" do
10
- Sinatra::Environment.prepare_loggers stub_everything
11
-
12
- event = Sinatra::Event.new(:get, '/') do
13
- raise 'whaaaa!'
14
- end
15
-
16
- result = event.attend(stub_everything(:params => {}, :path_info => '/'))
17
-
18
- result.status.should.equal 500
19
- end
20
-
21
- it "custom error if present" do
22
- Sinatra::Environment.prepare_loggers stub_everything
23
-
24
- event = Sinatra::Event.new(:get, '404') do
25
- body 'custom 404'
26
- end
27
-
28
- Sinatra::EventManager.expects(:not_found).never
29
- Sinatra::EventManager.determine_event(:get, '/sdf')
30
- end
31
-
32
- it "should show default 404 if custom not present" do
33
- Sinatra::EventManager.expects(:not_found)
34
- Sinatra::EventManager.determine_event(:get, '/asdfsasd')
35
- end
36
-
37
- it "should not execute event if halted" do
38
- Sinatra::Event.before_filters << lambda { throw :halt, 'whoa!' }
39
- event = Sinatra::Event.new(:get, '/') do
40
- foo
41
- end
42
- event.expects(:foo).never
43
- get_it('/').should.equal 'whoa!'
44
- end
45
-
46
- end
@@ -1,47 +0,0 @@
1
- require File.dirname(__FILE__) + '/../helper'
2
-
3
- class Sinatra::EventContext # :nodoc:
4
-
5
- def render_foo(template)
6
- require 'erb'
7
- ERB.new(template).result(binding)
8
- end
9
-
10
- end
11
-
12
- describe "Renderer" do
13
-
14
- before(:each) do
15
- Layouts.clear
16
- @context = Sinatra::EventContext.new(stub())
17
- end
18
-
19
- it "should render render a tempalate" do
20
- @context.render('foo', :foo).should.equal 'foo'
21
- end
22
-
23
- it "should render with a layout if given" do
24
- result = @context.render('content', :foo) do
25
- 'X <%= yield %> X'
26
- end
27
-
28
- result.should.equal 'X content X'
29
- end
30
-
31
- it "should render default layout if it exists and layout if no layout name given" do
32
- Layouts[:layout] = 'X <%= yield %> Y'
33
- @context.render('foo', :foo).should.equal 'X foo Y'
34
-
35
- Layouts[:foo] = 'Foo <%= yield %> Layout'
36
- @context.render('bar', :foo, :layout => :foo).should.equal 'Foo bar Layout'
37
- end
38
-
39
- it "should read template from a file if exists" do
40
- File.expects(:read).with('views/bar.foo').returns('foo content')
41
- @context.render(:bar, :foo).should.equal 'foo content'
42
-
43
- File.expects(:read).with('views2/bar.foo').returns('foo content')
44
- @context.render(:bar, :foo, :views_directory => 'views2').should.equal 'foo content'
45
- end
46
-
47
- end
@@ -1,21 +0,0 @@
1
- require File.dirname(__FILE__) + '/../helper'
2
-
3
- describe "Rack::Request" do
4
- it "should return PUT and DELETE based on _method param" do
5
- env = {'REQUEST_METHOD' => 'POST', 'rack.input' => StringIO.new('_method=DELETE')}
6
- Rack::Request.new(env).request_method.should.equal 'DELETE'
7
-
8
- env = {'REQUEST_METHOD' => 'POST', 'rack.input' => StringIO.new('_method=PUT')}
9
- Rack::Request.new(env).request_method.should.equal 'PUT'
10
- end
11
-
12
- it "should not allow faking" do
13
- env = {'REQUEST_METHOD' => 'POST', 'rack.input' => StringIO.new('_method=GET')}
14
- Rack::Request.new(env).request_method.should.equal 'POST'
15
-
16
- env = {'REQUEST_METHOD' => 'GET', 'rack.input' => StringIO.new('_method=POST')}
17
- Rack::Request.new(env).request_method.should.equal 'GET'
18
- end
19
- end
20
-
21
-
@@ -1,21 +0,0 @@
1
- require File.dirname(__FILE__) + '/../helper'
2
-
3
- describe "Route" do
4
- it "gives :format for free" do
5
- route = Sinatra::Route.new('/foo/:test/:blake')
6
-
7
- route.recognize('/foo/bar/baz').should.equal true
8
- route.params.should.equal :test => 'bar', :blake => 'baz', :format => 'html'
9
-
10
- route.recognize('/foo/bar/baz.xml').should.equal true
11
- route.params.should.equal :test => 'bar', :blake => 'baz', :format => 'xml'
12
- end
13
-
14
- it "doesn't auto add :format for routes with explicit formats" do
15
- route = Sinatra::Route.new('/foo/:test.xml')
16
- route.recognize('/foo/bar').should.equal false
17
- route.recognize('/foo/bar.xml').should.equal true
18
- route.params.should.equal :test => 'bar', :format => 'xml'
19
- end
20
- end
21
-
@@ -1 +0,0 @@
1
- You found foo!
@@ -1,48 +0,0 @@
1
- require File.dirname(__FILE__) + '/../helper'
2
- require 'stringio'
3
-
4
- context "StaticEvent" do
5
-
6
- before(:each) do
7
- Sinatra::EventManager.reset!
8
- end
9
-
10
- specify "recognizes paths prefixed with it's path" do
11
- File.expects(:exists?).with('/x/bar/test.jpg').returns(true)
12
- File.expects(:file?).with('/x/bar/test.jpg').returns(true)
13
- Sinatra::StaticEvent.new('/foo', '/x/bar').recognize('/foo/test.jpg').should.equal true
14
-
15
- File.expects(:exists?).with('/x/bar/test.jpg').returns(false)
16
- Sinatra::StaticEvent.new('/foo', '/x/bar').recognize('/foo/test.jpg').should.equal false
17
- end
18
-
19
- specify "sets headers for file type" do
20
- File.expects(:open).with('/x/bar/test.jpg', 'rb').returns(StringIO.new)
21
- File.expects(:size).with('/x/bar/test.jpg').returns(255)
22
- result = Sinatra::StaticEvent.new('/foo', '/x/bar').attend(stub(:path_info => '/foo/test.jpg'))
23
- result.headers.should.equal 'Content-Type' => 'image/jpeg', 'Content-Length' => '255'
24
- result.body.each { }
25
- end
26
-
27
- specify "makes sure it is a file and not a directory" do
28
- File.expects(:exists?).with('/x/bar').returns(true)
29
- File.expects(:file?).with('/x/bar').returns(false)
30
- Sinatra::StaticEvent.new('/foo', '/x').recognize('/foo/bar').should.equal false
31
- end
32
-
33
- end
34
-
35
- context "StaticEvent (In full context)" do
36
-
37
- specify "should serve a static file" do
38
- e = static '/x', root = File.dirname(__FILE__) + '/static_files'
39
-
40
- File.read(e.physical_path_for('/x/foo.txt')).should.equal 'You found foo!'
41
-
42
- get_it '/x/foo.txt'
43
-
44
- status.should.equal 200
45
- body.should.equal 'You found foo!'
46
- end
47
-
48
- end
@@ -1,18 +0,0 @@
1
- require File.dirname(__FILE__) + '/../helper'
2
-
3
- describe "Route" do
4
- it "should recognize params in urls" do
5
- route = Sinatra::Route.new('/foo/:test/:blake')
6
-
7
- route.recognize('/foo/bar/baz').should.equal true
8
- route.params.should.equal :test => 'bar', :blake => 'baz', :format => 'html'
9
-
10
- route.recognize('/foo/bar/baz.xml').should.equal true
11
- route.params.should.equal :test => 'bar', :blake => 'baz', :format => 'xml'
12
- end
13
-
14
- # it "test" do
15
- # p /^(\w)$|^(\w\.\w)$/.match('b').captures rescue 'NOTHING'
16
- # end
17
- end
18
-
@@ -1,3 +0,0 @@
1
- require File.dirname(__FILE__) + '/lib/erb'
2
-
3
- Sinatra::EventContext.send(:include, Sinatra::Erb::EventContext)
@@ -1,41 +0,0 @@
1
- module Sinatra
2
-
3
- module Erb # :nodoc:
4
-
5
- module EventContext
6
-
7
- # Renders raw erb in within the events context.
8
- #
9
- # This can be use to if you already have the template on hand and don't
10
- # need a layout. This is speedier than using erb
11
- #
12
- def render_erb(content)
13
- require 'erb'
14
- body ERB.new(content).result(binding)
15
- end
16
-
17
- # Renders erb within an event.
18
- #
19
- # Inline example:
20
- #
21
- # get '/foo' do
22
- # erb 'The time is <%= Time.now %>'
23
- # end
24
- #
25
- # Template example:
26
- #
27
- # get '/foo' do
28
- # erb :foo #=> reads and renders view/foo.erb
29
- # end
30
- #
31
- # For options, see Sinatra::Renderer
32
- #
33
- # See also: Sinatra::Renderer
34
- def erb(template, options = {}, &layout)
35
- render(template, :erb, options, &layout)
36
- end
37
- end
38
-
39
- end
40
-
41
- end
@@ -1,3 +0,0 @@
1
- require File.dirname(__FILE__) + '/lib/haml'
2
-
3
- Sinatra::EventContext.send(:include, Sinatra::Haml::EventContext)
@@ -1,41 +0,0 @@
1
- module Sinatra
2
-
3
- module Haml # :nodoc:
4
-
5
- module EventContext
6
-
7
- # Renders raw haml in within the events context.
8
- #
9
- # This can be use to if you already have the template on hand and don't
10
- # need a layout. This is speedier than using haml
11
- #
12
- def render_haml(template)
13
- require 'haml'
14
- body ::Haml::Engine.new(template).render(self)
15
- end
16
-
17
- # Renders Haml within an event.
18
- #
19
- # Inline example:
20
- #
21
- # get '/foo' do
22
- # haml '== The time is #{Time.now}'
23
- # end
24
- #
25
- # Template example:
26
- #
27
- # get '/foo' do
28
- # haml :foo #=> reads and renders view/foo.haml
29
- # end
30
- #
31
- # For options, see Sinatra::Renderer
32
- #
33
- # See also: Sinatra::Renderer
34
- def haml(template, options = {}, &layout)
35
- render(template, :haml, options, &layout)
36
- end
37
- end
38
-
39
- end
40
-
41
- end