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
@@ -1,17 +1,4 @@
1
- require File.dirname(__FILE__) + '/../lib/sinatra'
1
+ require File.dirname(__FILE__) + "/../lib/sinatra"
2
+ require File.dirname(__FILE__) + "/../lib/sinatra/test/spec"
2
3
 
3
- %w(mocha test/spec).each do |library|
4
- begin
5
- require library
6
- rescue
7
- STDERR.puts "== Sinatra's tests need #{library} to run."
8
- end
9
- end
10
-
11
- Sinatra::Server.running = true
12
- Sinatra::Options.set_environment :test
13
- Sinatra::Environment.prepare_loggers
14
-
15
- class Test::Unit::TestCase
16
- include Sinatra::TestMethods
17
- end
4
+ require "mocha"
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class FooError < RuntimeError; end
4
+
5
+ context "Mapped errors" do
6
+
7
+ setup do
8
+ Sinatra.application = nil
9
+ end
10
+
11
+ specify "are rescued and run in context" do
12
+
13
+ error FooError do
14
+ 'MAPPED ERROR!'
15
+ end
16
+
17
+ get '/' do
18
+ raise FooError.new
19
+ end
20
+
21
+ get_it '/'
22
+
23
+ should.be.server_error
24
+ body.should.equal 'MAPPED ERROR!'
25
+
26
+ end
27
+
28
+ specify "renders empty if no each method on result" do
29
+
30
+ error FooError do
31
+ nil
32
+ end
33
+
34
+ get '/' do
35
+ raise FooError.new
36
+ end
37
+
38
+ get_it '/'
39
+
40
+ should.be.server_error
41
+ body.should.be.empty
42
+
43
+ end
44
+
45
+ specify "doesn't override status if set" do
46
+
47
+ error FooError do
48
+ status(200)
49
+ end
50
+
51
+ get '/' do
52
+ raise FooError.new
53
+ end
54
+
55
+ get_it '/'
56
+
57
+ should.be.ok
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1 @@
1
+ <foo></foo>
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ context "RESTful tests" do
4
+
5
+ specify "should take xml" do
6
+ post '/foo.xml' do
7
+ request.body.string
8
+ end
9
+
10
+ post_it '/foo.xml', '<myxml></myxml>'
11
+ assert ok?
12
+ assert_equal('<myxml></myxml>', body)
13
+ end
14
+
15
+ end
16
+
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ context "Sass" do
4
+
5
+ setup do
6
+ Sinatra.application = nil
7
+ end
8
+
9
+ context "Templates (in general)" do
10
+
11
+ setup do
12
+ Sinatra.application = nil
13
+ end
14
+
15
+ specify "are read from files if Symbols" do
16
+
17
+ get '/from_file' do
18
+ sass :foo, :views_directory => File.dirname(__FILE__) + "/views"
19
+ end
20
+
21
+ get_it '/from_file'
22
+ should.be.ok
23
+ body.should.equal "#sass {\n background_color: #FFF; }\n"
24
+
25
+ end
26
+
27
+ specify "raise an error if template not found" do
28
+ get '/' do
29
+ sass :not_found
30
+ end
31
+
32
+ lambda { get_it '/' }.should.raise(Errno::ENOENT)
33
+ end
34
+
35
+ specify "ignore default layout file with .sass extension" do
36
+ get '/' do
37
+ sass :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
38
+ end
39
+
40
+ get_it '/'
41
+ should.be.ok
42
+ body.should.equal "#sass {\n background_color: #FFF; }\n"
43
+ end
44
+
45
+ specify "ignore explicitly specified layout file" do
46
+ get '/' do
47
+ sass :foo, :layout => :layout, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
48
+ end
49
+
50
+ get_it '/'
51
+ should.be.ok
52
+ body.should.equal "#sass {\n background_color: #FFF; }\n"
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ context "Sessions" do
4
+
5
+ specify "should be off by default" do
6
+ Sinatra.application = nil
7
+
8
+ get '/asdf' do
9
+ session[:test] = true
10
+ "asdf"
11
+ end
12
+
13
+ get '/test' do
14
+ session[:test] == true ? "true" : "false"
15
+ end
16
+
17
+ get_it '/asdf', {}, 'HTTP_HOST' => 'foo.sinatrarb.com'
18
+ assert ok?
19
+ assert !include?('Set-Cookie')
20
+ end
21
+
22
+ specify "should be able to store data accross requests" do
23
+ set_options(:sessions => true)
24
+ Sinatra.application = nil
25
+
26
+ get '/foo' do
27
+ session[:test] = true
28
+ "asdf"
29
+ end
30
+
31
+ get '/bar' do
32
+ session[:test] == true ? "true" : "false"
33
+ end
34
+
35
+ get_it '/foo', :env => { :host => 'foo.sinatrarb.com' }
36
+ assert ok?
37
+ assert include?('Set-Cookie')
38
+ end
39
+
40
+ end
@@ -0,0 +1,112 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ context "Static files (by default)" do
4
+
5
+ setup do
6
+ Sinatra.application = nil
7
+ Sinatra.application.options.public = File.dirname(__FILE__) + '/public'
8
+ end
9
+
10
+ specify "are served from root/public" do
11
+ get_it '/foo.xml'
12
+ should.be.ok
13
+ headers['Content-Length'].should.equal '12'
14
+ headers['Content-Type'].should.equal 'application/xml'
15
+ body.should.equal "<foo></foo>\n"
16
+ end
17
+
18
+ specify "are not served when verb is not GET or HEAD" do
19
+ post_it '/foo.xml'
20
+ # these should actually be giving back a 405 Method Not Allowed but that
21
+ # complicates the routing logic quite a bit.
22
+ should.be.not_found
23
+ status.should.equal 404
24
+ end
25
+
26
+ specify "are served when verb is HEAD but missing a body" do
27
+ head_it '/foo.xml'
28
+ should.be.ok
29
+ headers['Content-Length'].should.equal '12'
30
+ headers['Content-Type'].should.equal 'application/xml'
31
+ body.should.equal ""
32
+ end
33
+
34
+ # static files override dynamic/internal events and ...
35
+ specify "are served when conflicting events exists" do
36
+ get '/foo.xml' do
37
+ 'this is not foo.xml!'
38
+ end
39
+ get_it '/foo.xml'
40
+ should.be.ok
41
+ body.should.equal "<foo></foo>\n"
42
+ end
43
+
44
+ specify "are irrelevant when request_method is not GET/HEAD" do
45
+ put '/foo.xml' do
46
+ 'putted!'
47
+ end
48
+ put_it '/foo.xml'
49
+ should.be.ok
50
+ body.should.equal 'putted!'
51
+
52
+ get_it '/foo.xml'
53
+ should.be.ok
54
+ body.should.equal "<foo></foo>\n"
55
+ end
56
+
57
+ specify "include a Last-Modified header" do
58
+ last_modified = File.mtime(Sinatra.application.options.public + '/foo.xml')
59
+ get_it('/foo.xml')
60
+ should.be.ok
61
+ body.should.not.be.empty
62
+ headers['Last-Modified'].should.equal last_modified.httpdate
63
+ end
64
+
65
+ specify "are not served when If-Modified-Since matches" do
66
+ last_modified = File.mtime(Sinatra.application.options.public + '/foo.xml')
67
+ @request = Rack::MockRequest.new(Sinatra.application)
68
+ @response = @request.get('/foo.xml', 'HTTP_IF_MODIFIED_SINCE' => last_modified.httpdate)
69
+ status.should.equal 304
70
+ body.should.be.empty
71
+ end
72
+
73
+ specify "should omit Content-Disposition headers" do
74
+ get_it('/foo.xml')
75
+ should.be.ok
76
+ headers['Content-Disposition'].should.be.nil
77
+ headers['Content-Transfer-Encoding'].should.be.nil
78
+ end
79
+
80
+ end
81
+
82
+ context "SendData" do
83
+
84
+ setup do
85
+ Sinatra.application = nil
86
+ end
87
+
88
+ specify "should send the data with options" do
89
+ get '/' do
90
+ send_data 'asdf', :status => 500
91
+ end
92
+
93
+ get_it '/'
94
+
95
+ should.be.server_error
96
+ body.should.equal 'asdf'
97
+ end
98
+
99
+ specify "should include a Content-Disposition header" do
100
+ get '/' do
101
+ send_file File.dirname(__FILE__) + '/public/foo.xml'
102
+ end
103
+
104
+ get_it '/'
105
+
106
+ should.be.ok
107
+ headers['Content-Disposition'].should.not.be.nil
108
+ headers['Content-Disposition'].should.equal 'attachment; filename="foo.xml"'
109
+ headers['Content-Transfer-Encoding'].should.equal 'binary'
110
+ end
111
+
112
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ context "Symbol Params" do
4
+
5
+ setup do
6
+ Sinatra.application = nil
7
+ end
8
+
9
+ specify "should be accessable as Strings or Symbols" do
10
+ get '/' do
11
+ params[:foo] + params['foo']
12
+ end
13
+
14
+ get_it '/', :foo => "X"
15
+ assert_equal('XX', body)
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ context "Templates (in general)" do
4
+
5
+ specify "are read from files if Symbols" do
6
+
7
+ get '/from_file' do
8
+ @name = 'Alena'
9
+ erb :foo, :views_directory => File.dirname(__FILE__) + "/views"
10
+ end
11
+
12
+ get_it '/from_file'
13
+
14
+ body.should.equal 'You rock Alena!'
15
+
16
+ end
17
+
18
+ specify "use layout.ext by default if available" do
19
+
20
+ get '/layout_from_file' do
21
+ erb :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
22
+ end
23
+
24
+ get_it '/layout_from_file'
25
+ should.be.ok
26
+ body.should.equal "x This is foo! x \n"
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ context "Rendering in file templates" do
4
+
5
+ setup do
6
+ Sinatra.application = nil
7
+ use_in_file_templates!
8
+ end
9
+
10
+ specify "should set template" do
11
+ assert Sinatra.application.templates[:foo]
12
+ end
13
+
14
+ specify "should set layout" do
15
+ assert Sinatra.application.templates[:layout]
16
+ end
17
+
18
+ specify "should render without layout if specified" do
19
+ get '/' do
20
+ haml :foo, :layout => false
21
+ end
22
+
23
+ get_it '/'
24
+ assert_equal "this is foo\n", body
25
+ end
26
+
27
+ specify "should render with layout if specified" do
28
+ get '/' do
29
+ haml :foo
30
+ end
31
+
32
+ get_it '/'
33
+ assert_equal "X\nthis is foo\nX\n", body
34
+ end
35
+
36
+
37
+ end
38
+
39
+ __END__
40
+
41
+ ## foo
42
+ this is foo
43
+
44
+ ## layout
45
+ X
46
+ = yield
47
+ X
48
+
@@ -0,0 +1 @@
1
+ xml.exclaim "You rock #{@name}!"
@@ -0,0 +1 @@
1
+ You rock <%= @name %>!
@@ -0,0 +1 @@
1
+ == You rock #{@name}!
@@ -0,0 +1,2 @@
1
+ #sass
2
+ :background_color #FFF
@@ -0,0 +1,2 @@
1
+ <%= @title %>
2
+ Hi <%= yield %>
@@ -0,0 +1,2 @@
1
+ == #{@title}
2
+ == Hi #{yield}
@@ -0,0 +1 @@
1
+ xml.this "is foo!"
@@ -0,0 +1 @@
1
+ This is foo!
@@ -0,0 +1 @@
1
+ This is foo!