Syd-sinatra 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/ChangeLog +78 -0
  2. data/LICENSE +22 -0
  3. data/README.rdoc +523 -0
  4. data/Rakefile +162 -0
  5. data/images/404.png +0 -0
  6. data/images/500.png +0 -0
  7. data/lib/sinatra/test/methods.rb +76 -0
  8. data/lib/sinatra/test/rspec.rb +10 -0
  9. data/lib/sinatra/test/spec.rb +10 -0
  10. data/lib/sinatra/test/unit.rb +13 -0
  11. data/lib/sinatra.rb +1470 -0
  12. data/sinatra.gemspec +77 -0
  13. data/test/app_test.rb +299 -0
  14. data/test/application_test.rb +318 -0
  15. data/test/builder_test.rb +101 -0
  16. data/test/custom_error_test.rb +62 -0
  17. data/test/erb_test.rb +136 -0
  18. data/test/event_context_test.rb +15 -0
  19. data/test/events_test.rb +65 -0
  20. data/test/filter_test.rb +30 -0
  21. data/test/haml_test.rb +233 -0
  22. data/test/helper.rb +7 -0
  23. data/test/mapped_error_test.rb +72 -0
  24. data/test/pipeline_test.rb +66 -0
  25. data/test/public/foo.xml +1 -0
  26. data/test/sass_test.rb +57 -0
  27. data/test/sessions_test.rb +39 -0
  28. data/test/streaming_test.rb +118 -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 +47 -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 +129 -0
@@ -0,0 +1,72 @@
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
+ Sinatra.application.options.raise_errors = false
10
+ end
11
+
12
+ specify "are rescued and run in context" do
13
+
14
+ error FooError do
15
+ 'MAPPED ERROR!'
16
+ end
17
+
18
+ get '/' do
19
+ raise FooError
20
+ end
21
+
22
+ get_it '/'
23
+
24
+ should.be.server_error
25
+ body.should.equal 'MAPPED ERROR!'
26
+
27
+ end
28
+
29
+ specify "renders empty if no each method on result" do
30
+
31
+ error FooError do
32
+ nil
33
+ end
34
+
35
+ get '/' do
36
+ raise FooError
37
+ end
38
+
39
+ get_it '/'
40
+
41
+ should.be.server_error
42
+ body.should.be.empty
43
+
44
+ end
45
+
46
+ specify "doesn't override status if set" do
47
+
48
+ error FooError do
49
+ status(200)
50
+ end
51
+
52
+ get '/' do
53
+ raise FooError
54
+ end
55
+
56
+ get_it '/'
57
+
58
+ should.be.ok
59
+
60
+ end
61
+
62
+ specify "raises errors when the raise_errors option is set" do
63
+ Sinatra.application.options.raise_errors = true
64
+ error FooError do
65
+ end
66
+ get '/' do
67
+ raise FooError
68
+ end
69
+ assert_raises(FooError) { get_it('/') }
70
+ end
71
+
72
+ end
@@ -0,0 +1,66 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class UpcaseMiddleware
4
+ def initialize(app, *args, &block)
5
+ @app = app
6
+ @args = args
7
+ @block = block
8
+ end
9
+ def call(env)
10
+ env['PATH_INFO'] = env['PATH_INFO'].to_s.upcase
11
+ @app.call(env)
12
+ end
13
+ end
14
+
15
+ context "Middleware Pipelines" do
16
+
17
+ setup do
18
+ Sinatra.application = nil
19
+ @app = Sinatra.application
20
+ end
21
+
22
+ teardown do
23
+ Sinatra.application = nil
24
+ end
25
+
26
+ specify "includes default middleware with options set" do
27
+ @app.set_options :sessions => true, :logging => true
28
+ @app.send(:optional_middleware).should.include([Rack::Session::Cookie, [], nil])
29
+ @app.send(:optional_middleware).should.include([Rack::CommonLogger, [], nil])
30
+ end
31
+
32
+ specify "does not include default middleware with options unset" do
33
+ @app.set_options :sessions => false, :logging => false
34
+ @app.send(:optional_middleware).should.not.include([Rack::Session::Cookie, [], nil])
35
+ @app.send(:optional_middleware).should.not.include([Rack::CommonLogger, [], nil])
36
+ end
37
+
38
+ specify "includes only optional middleware when no explicit middleware added" do
39
+ @app.set_options :sessions => true, :logging => true
40
+ @app.send(:middleware).should.equal @app.send(:optional_middleware)
41
+ end
42
+
43
+ specify "should clear middleware before reload" do
44
+ @app.clearables.should.include(@app.send(:explicit_middleware))
45
+ end
46
+
47
+ specify "should add middleware with use" do
48
+ block = Proc.new { |env| }
49
+ @app.use UpcaseMiddleware
50
+ @app.use UpcaseMiddleware, "foo", "bar"
51
+ @app.use UpcaseMiddleware, "foo", "bar", &block
52
+ @app.send(:middleware).should.include([UpcaseMiddleware, [], nil])
53
+ @app.send(:middleware).should.include([UpcaseMiddleware, ["foo", "bar"], nil])
54
+ @app.send(:middleware).should.include([UpcaseMiddleware, ["foo", "bar"], block])
55
+ end
56
+
57
+ specify "should run middleware added with use" do
58
+ get('/foo') { "FAIL!" }
59
+ get('/FOO') { "PASS!" }
60
+ use UpcaseMiddleware
61
+ get_it '/foo'
62
+ should.be.ok
63
+ body.should.equal "PASS!"
64
+ end
65
+
66
+ end
@@ -0,0 +1 @@
1
+ <foo></foo>
data/test/sass_test.rb ADDED
@@ -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,39 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ context "Sessions" do
4
+
5
+ setup { Sinatra.application = nil }
6
+
7
+ specify "should be off by default" do
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_option :sessions, true
24
+
25
+ get '/foo' do
26
+ session[:test] = true
27
+ "asdf"
28
+ end
29
+
30
+ get '/bar' do
31
+ session[:test] == true ? "true" : "false"
32
+ end
33
+
34
+ get_it '/foo', :env => { :host => 'foo.sinatrarb.com' }
35
+ assert ok?
36
+ assert include?('Set-Cookie')
37
+ end
38
+
39
+ end
@@ -0,0 +1,118 @@
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
+ specify "should be served even if their path is url escaped" do
81
+ get_it('/fo%6f.xml')
82
+ should.be.ok
83
+ body.should.equal "<foo></foo>\n"
84
+ end
85
+
86
+ end
87
+
88
+ context "SendData" do
89
+
90
+ setup do
91
+ Sinatra.application = nil
92
+ end
93
+
94
+ specify "should send the data with options" do
95
+ get '/' do
96
+ send_data 'asdf', :status => 500
97
+ end
98
+
99
+ get_it '/'
100
+
101
+ should.be.server_error
102
+ body.should.equal 'asdf'
103
+ end
104
+
105
+ specify "should include a Content-Disposition header" do
106
+ get '/' do
107
+ send_file File.dirname(__FILE__) + '/public/foo.xml'
108
+ end
109
+
110
+ get_it '/'
111
+
112
+ should.be.ok
113
+ headers['Content-Disposition'].should.not.be.nil
114
+ headers['Content-Disposition'].should.equal 'attachment; filename="foo.xml"'
115
+ headers['Content-Transfer-Encoding'].should.equal 'binary'
116
+ end
117
+
118
+ 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" 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,47 @@
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
+ end
37
+
38
+ __END__
39
+
40
+ @@ foo
41
+ this is foo
42
+
43
+ @@ layout
44
+ X
45
+ = yield
46
+ X
47
+
@@ -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!
@@ -0,0 +1,2 @@
1
+ #sass
2
+ :background_color #FFF
@@ -0,0 +1,3 @@
1
+ xml.layout do
2
+ xml << yield
3
+ end
@@ -0,0 +1 @@
1
+ x <%= yield %> x
@@ -0,0 +1 @@
1
+ == x #{yield} x
@@ -0,0 +1,2 @@
1
+ b0rked!
2
+ = yield
@@ -0,0 +1 @@
1
+ xml.foo "No Layout!"
@@ -0,0 +1 @@
1
+ %h1 No Layout!
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Syd-sinatra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
5
+ platform: ruby
6
+ authors:
7
+ - Blake Mizerany
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-02 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.4.0
23
+ version:
24
+ description: Classy web-development dressed in a DSL
25
+ email:
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README.rdoc
32
+ - LICENSE
33
+ files:
34
+ - ChangeLog
35
+ - LICENSE
36
+ - README.rdoc
37
+ - Rakefile
38
+ - images/404.png
39
+ - images/500.png
40
+ - lib/sinatra.rb
41
+ - lib/sinatra/test/methods.rb
42
+ - lib/sinatra/test/rspec.rb
43
+ - lib/sinatra/test/spec.rb
44
+ - lib/sinatra/test/unit.rb
45
+ - sinatra.gemspec
46
+ - test/app_test.rb
47
+ - test/application_test.rb
48
+ - test/builder_test.rb
49
+ - test/custom_error_test.rb
50
+ - test/erb_test.rb
51
+ - test/event_context_test.rb
52
+ - test/events_test.rb
53
+ - test/filter_test.rb
54
+ - test/haml_test.rb
55
+ - test/helper.rb
56
+ - test/mapped_error_test.rb
57
+ - test/pipeline_test.rb
58
+ - test/public/foo.xml
59
+ - test/sass_test.rb
60
+ - test/sessions_test.rb
61
+ - test/streaming_test.rb
62
+ - test/sym_params_test.rb
63
+ - test/template_test.rb
64
+ - test/use_in_file_templates_test.rb
65
+ - test/views/foo.builder
66
+ - test/views/foo.erb
67
+ - test/views/foo.haml
68
+ - test/views/foo.sass
69
+ - test/views/foo_layout.erb
70
+ - test/views/foo_layout.haml
71
+ - test/views/layout_test/foo.builder
72
+ - test/views/layout_test/foo.erb
73
+ - test/views/layout_test/foo.haml
74
+ - test/views/layout_test/foo.sass
75
+ - test/views/layout_test/layout.builder
76
+ - test/views/layout_test/layout.erb
77
+ - test/views/layout_test/layout.haml
78
+ - test/views/layout_test/layout.sass
79
+ - test/views/no_layout/no_layout.builder
80
+ - test/views/no_layout/no_layout.haml
81
+ has_rdoc: true
82
+ homepage: http://sinatra.rubyforge.org
83
+ post_install_message:
84
+ rdoc_options:
85
+ - --line-numbers
86
+ - --inline-source
87
+ - --title
88
+ - Sinatra
89
+ - --main
90
+ - README.rdoc
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ version:
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ version:
105
+ requirements: []
106
+
107
+ rubyforge_project: sinatra
108
+ rubygems_version: 1.2.0
109
+ signing_key:
110
+ specification_version: 2
111
+ summary: Classy web-development dressed in a DSL
112
+ test_files:
113
+ - test/app_test.rb
114
+ - test/application_test.rb
115
+ - test/builder_test.rb
116
+ - test/custom_error_test.rb
117
+ - test/erb_test.rb
118
+ - test/event_context_test.rb
119
+ - test/events_test.rb
120
+ - test/filter_test.rb
121
+ - test/haml_test.rb
122
+ - test/mapped_error_test.rb
123
+ - test/pipeline_test.rb
124
+ - test/sass_test.rb
125
+ - test/sessions_test.rb
126
+ - test/streaming_test.rb
127
+ - test/sym_params_test.rb
128
+ - test/template_test.rb
129
+ - test/use_in_file_templates_test.rb