sinatra 1.4.8 → 2.0.0.beta1

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 (124) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +77 -47
  3. data/CONTRIBUTING.md +1 -1
  4. data/Gemfile +37 -49
  5. data/MAINTENANCE.md +42 -0
  6. data/README.de.md +5 -5
  7. data/README.es.md +5 -5
  8. data/README.fr.md +9 -9
  9. data/README.hu.md +3 -3
  10. data/README.ja.md +19 -8
  11. data/README.ko.md +8 -8
  12. data/README.md +90 -61
  13. data/README.pt-br.md +3 -3
  14. data/README.pt-pt.md +2 -2
  15. data/README.ru.md +42 -26
  16. data/README.zh.md +8 -8
  17. data/Rakefile +0 -6
  18. data/SECURITY.md +35 -0
  19. data/lib/sinatra/base.rb +113 -161
  20. data/lib/sinatra/main.rb +1 -0
  21. data/lib/sinatra/show_exceptions.rb +8 -8
  22. data/lib/sinatra/version.rb +1 -1
  23. data/sinatra.gemspec +7 -4
  24. metadata +34 -168
  25. data/lib/sinatra/ext.rb +0 -17
  26. data/test/asciidoctor_test.rb +0 -72
  27. data/test/base_test.rb +0 -167
  28. data/test/builder_test.rb +0 -91
  29. data/test/coffee_test.rb +0 -96
  30. data/test/compile_test.rb +0 -183
  31. data/test/contest.rb +0 -91
  32. data/test/creole_test.rb +0 -65
  33. data/test/delegator_test.rb +0 -160
  34. data/test/encoding_test.rb +0 -20
  35. data/test/erb_test.rb +0 -116
  36. data/test/extensions_test.rb +0 -98
  37. data/test/filter_test.rb +0 -487
  38. data/test/haml_test.rb +0 -109
  39. data/test/helper.rb +0 -132
  40. data/test/helpers_test.rb +0 -1917
  41. data/test/integration/app.rb +0 -79
  42. data/test/integration_helper.rb +0 -236
  43. data/test/integration_test.rb +0 -104
  44. data/test/less_test.rb +0 -69
  45. data/test/liquid_test.rb +0 -77
  46. data/test/mapped_error_test.rb +0 -285
  47. data/test/markaby_test.rb +0 -80
  48. data/test/markdown_test.rb +0 -85
  49. data/test/mediawiki_test.rb +0 -68
  50. data/test/middleware_test.rb +0 -68
  51. data/test/nokogiri_test.rb +0 -67
  52. data/test/public/favicon.ico +0 -0
  53. data/test/public/hello+world.txt +0 -1
  54. data/test/rabl_test.rb +0 -89
  55. data/test/rack_test.rb +0 -45
  56. data/test/radius_test.rb +0 -59
  57. data/test/rdoc_test.rb +0 -66
  58. data/test/readme_test.rb +0 -130
  59. data/test/request_test.rb +0 -100
  60. data/test/response_test.rb +0 -63
  61. data/test/result_test.rb +0 -76
  62. data/test/route_added_hook_test.rb +0 -59
  63. data/test/routing_test.rb +0 -1456
  64. data/test/sass_test.rb +0 -115
  65. data/test/scss_test.rb +0 -88
  66. data/test/server_test.rb +0 -56
  67. data/test/settings_test.rb +0 -582
  68. data/test/sinatra_test.rb +0 -12
  69. data/test/slim_test.rb +0 -102
  70. data/test/static_test.rb +0 -266
  71. data/test/streaming_test.rb +0 -149
  72. data/test/stylus_test.rb +0 -90
  73. data/test/templates_test.rb +0 -382
  74. data/test/textile_test.rb +0 -65
  75. data/test/views/a/in_a.str +0 -1
  76. data/test/views/ascii.erb +0 -2
  77. data/test/views/b/in_b.str +0 -1
  78. data/test/views/calc.html.erb +0 -1
  79. data/test/views/error.builder +0 -3
  80. data/test/views/error.erb +0 -3
  81. data/test/views/error.haml +0 -3
  82. data/test/views/error.sass +0 -2
  83. data/test/views/explicitly_nested.str +0 -1
  84. data/test/views/foo/hello.test +0 -1
  85. data/test/views/hello.asciidoc +0 -1
  86. data/test/views/hello.builder +0 -1
  87. data/test/views/hello.coffee +0 -1
  88. data/test/views/hello.creole +0 -1
  89. data/test/views/hello.erb +0 -1
  90. data/test/views/hello.haml +0 -1
  91. data/test/views/hello.less +0 -5
  92. data/test/views/hello.liquid +0 -1
  93. data/test/views/hello.mab +0 -1
  94. data/test/views/hello.md +0 -1
  95. data/test/views/hello.mediawiki +0 -1
  96. data/test/views/hello.nokogiri +0 -1
  97. data/test/views/hello.rabl +0 -2
  98. data/test/views/hello.radius +0 -1
  99. data/test/views/hello.rdoc +0 -1
  100. data/test/views/hello.sass +0 -2
  101. data/test/views/hello.scss +0 -3
  102. data/test/views/hello.slim +0 -1
  103. data/test/views/hello.str +0 -1
  104. data/test/views/hello.styl +0 -2
  105. data/test/views/hello.test +0 -1
  106. data/test/views/hello.textile +0 -1
  107. data/test/views/hello.wlang +0 -1
  108. data/test/views/hello.yajl +0 -1
  109. data/test/views/layout2.builder +0 -3
  110. data/test/views/layout2.erb +0 -2
  111. data/test/views/layout2.haml +0 -2
  112. data/test/views/layout2.liquid +0 -2
  113. data/test/views/layout2.mab +0 -2
  114. data/test/views/layout2.nokogiri +0 -3
  115. data/test/views/layout2.rabl +0 -3
  116. data/test/views/layout2.radius +0 -2
  117. data/test/views/layout2.slim +0 -3
  118. data/test/views/layout2.str +0 -2
  119. data/test/views/layout2.test +0 -1
  120. data/test/views/layout2.wlang +0 -2
  121. data/test/views/nested.str +0 -1
  122. data/test/views/utf8.erb +0 -2
  123. data/test/wlang_test.rb +0 -87
  124. data/test/yajl_test.rb +0 -86
@@ -1,115 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- begin
4
- require 'sass'
5
-
6
- class SassTest < Minitest::Test
7
- def sass_app(options = {}, &block)
8
- mock_app do
9
- set :views, File.dirname(__FILE__) + '/views'
10
- set options
11
- get('/', &block)
12
- end
13
- get '/'
14
- end
15
-
16
- it 'renders inline Sass strings' do
17
- sass_app { sass "#sass\n :background-color white\n" }
18
- assert ok?
19
- assert_equal "#sass {\n background-color: white; }\n", body
20
- end
21
-
22
- it 'defaults content type to css' do
23
- sass_app { sass "#sass\n :background-color white\n" }
24
- assert ok?
25
- assert_equal "text/css;charset=utf-8", response['Content-Type']
26
- end
27
-
28
- it 'defaults allows setting content type per route' do
29
- sass_app do
30
- content_type :html
31
- sass "#sass\n :background-color white\n"
32
- end
33
- assert ok?
34
- assert_equal "text/html;charset=utf-8", response['Content-Type']
35
- end
36
-
37
- it 'defaults allows setting content type globally' do
38
- sass_app(:sass => { :content_type => 'html' }) {
39
- sass "#sass\n :background-color white\n"
40
- }
41
- assert ok?
42
- assert_equal "text/html;charset=utf-8", response['Content-Type']
43
- end
44
-
45
- it 'renders .sass files in views path' do
46
- sass_app { sass :hello }
47
- assert ok?
48
- assert_equal "#sass {\n background-color: white; }\n", body
49
- end
50
-
51
- it 'ignores the layout option' do
52
- sass_app { sass :hello, :layout => :layout2 }
53
- assert ok?
54
- assert_equal "#sass {\n background-color: white; }\n", body
55
- end
56
-
57
- it "raises error if template not found" do
58
- mock_app { get('/') { sass :no_such_template } }
59
- assert_raises(Errno::ENOENT) { get('/') }
60
- end
61
-
62
- it "passes SASS options to the Sass engine" do
63
- sass_app do
64
- sass(
65
- "#sass\n :background-color white\n :color black\n",
66
- :style => :compact
67
- )
68
- end
69
- assert ok?
70
- assert_equal("#sass { background-color: white; color: black; }\n", body)
71
- end
72
-
73
- it "passes default SASS options to the Sass engine" do
74
- mock_app do
75
- set :sass, {:style => :compact} # default Sass style is :nested
76
- get('/') { sass("#sass\n :background-color white\n :color black\n") }
77
- end
78
- get '/'
79
- assert ok?
80
- assert_equal "#sass { background-color: white; color: black; }\n", body
81
- end
82
-
83
- it "merges the default SASS options with the overrides" do
84
- mock_app do
85
- # default Sass attribute_syntax is :normal (with : in front)
86
- set :sass, {:style => :compact, :attribute_syntax => :alternate }
87
- get('/') { sass("#sass\n background-color: white\n color: black\n") }
88
- get('/raised') do
89
- # retains global attribute_syntax settings
90
- sass(
91
- "#sass\n :background-color white\n :color black\n",
92
- :style => :expanded
93
- )
94
- end
95
- get('/expanded_normal') do
96
- sass(
97
- "#sass\n :background-color white\n :color black\n",
98
- :style => :expanded, :attribute_syntax => :normal
99
- )
100
- end
101
- end
102
- get '/'
103
- assert ok?
104
- assert_equal "#sass { background-color: white; color: black; }\n", body
105
- assert_raises(Sass::SyntaxError) { get('/raised') }
106
- get '/expanded_normal'
107
- assert ok?
108
- assert_equal "#sass {\n background-color: white;\n color: black;\n}\n",
109
- body
110
- end
111
- end
112
-
113
- rescue LoadError
114
- warn "#{$!.to_s}: skipping sass tests"
115
- end
@@ -1,88 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- begin
4
- require 'sass'
5
-
6
- class ScssTest < Minitest::Test
7
- def scss_app(options = {}, &block)
8
- mock_app do
9
- set :views, File.dirname(__FILE__) + '/views'
10
- set options
11
- get('/', &block)
12
- end
13
- get '/'
14
- end
15
-
16
- it 'renders inline Scss strings' do
17
- scss_app { scss "#scss {\n background-color: white; }\n" }
18
- assert ok?
19
- assert_equal "#scss {\n background-color: white; }\n", body
20
- end
21
-
22
- it 'defaults content type to css' do
23
- scss_app { scss "#scss {\n background-color: white; }\n" }
24
- assert ok?
25
- assert_equal "text/css;charset=utf-8", response['Content-Type']
26
- end
27
-
28
- it 'defaults allows setting content type per route' do
29
- scss_app do
30
- content_type :html
31
- scss "#scss {\n background-color: white; }\n"
32
- end
33
- assert ok?
34
- assert_equal "text/html;charset=utf-8", response['Content-Type']
35
- end
36
-
37
- it 'defaults allows setting content type globally' do
38
- scss_app(:scss => { :content_type => 'html' }) {
39
- scss "#scss {\n background-color: white; }\n"
40
- }
41
- assert ok?
42
- assert_equal "text/html;charset=utf-8", response['Content-Type']
43
- end
44
-
45
- it 'renders .scss files in views path' do
46
- scss_app { scss :hello }
47
- assert ok?
48
- assert_equal "#scss {\n background-color: white; }\n", body
49
- end
50
-
51
- it 'ignores the layout option' do
52
- scss_app { scss :hello, :layout => :layout2 }
53
- assert ok?
54
- assert_equal "#scss {\n background-color: white; }\n", body
55
- end
56
-
57
- it "raises error if template not found" do
58
- mock_app { get('/') { scss(:no_such_template) } }
59
- assert_raises(Errno::ENOENT) { get('/') }
60
- end
61
-
62
- it "passes scss options to the scss engine" do
63
- scss_app do
64
- scss(
65
- "#scss {\n background-color: white;\n color: black\n}",
66
- :style => :compact
67
- )
68
- end
69
- assert ok?
70
- assert_equal "#scss { background-color: white; color: black; }\n", body
71
- end
72
-
73
- it "passes default scss options to the scss engine" do
74
- mock_app do
75
- set :scss, {:style => :compact} # default scss style is :nested
76
- get('/') {
77
- scss("#scss {\n background-color: white;\n color: black;\n}")
78
- }
79
- end
80
- get '/'
81
- assert ok?
82
- assert_equal "#scss { background-color: white; color: black; }\n", body
83
- end
84
- end
85
-
86
- rescue LoadError
87
- warn "#{$!.to_s}: skipping scss tests"
88
- end
@@ -1,56 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
- require 'stringio'
3
-
4
- module Rack::Handler
5
- class Mock
6
- extend Minitest::Assertions
7
- # Allow assertions in request context
8
- def self.assertions
9
- @assertions ||= 0
10
- end
11
-
12
- def self.assertions= assertions
13
- @assertions = assertions
14
- end
15
-
16
- def self.run(app, options={})
17
- assert(app < Sinatra::Base)
18
- assert_equal 9001, options[:Port]
19
- assert_equal 'foo.local', options[:Host]
20
- yield new
21
- end
22
-
23
- def stop
24
- end
25
- end
26
-
27
- register 'mock', 'Rack::Handler::Mock'
28
- end
29
-
30
- class ServerTest < Minitest::Test
31
- setup do
32
- mock_app do
33
- set :server, 'mock'
34
- set :bind, 'foo.local'
35
- set :port, 9001
36
- end
37
- $stderr = StringIO.new
38
- end
39
-
40
- def teardown
41
- $stderr = STDERR
42
- end
43
-
44
- it "locates the appropriate Rack handler and calls ::run" do
45
- @app.run!
46
- end
47
-
48
- it "sets options on the app before running" do
49
- @app.run! :sessions => true
50
- assert @app.sessions?
51
- end
52
-
53
- it "falls back on the next server handler when not found" do
54
- @app.run! :server => %w[foo bar mock]
55
- end
56
- end
@@ -1,582 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- class SettingsTest < Minitest::Test
4
- setup do
5
- @base = Sinatra.new(Sinatra::Base)
6
- @base.set :environment => :foo, :app_file => nil
7
-
8
- @application = Sinatra.new(Sinatra::Application)
9
- @application.set :environment => :foo, :app_file => nil
10
- end
11
-
12
- it 'sets settings to literal values' do
13
- @base.set(:foo, 'bar')
14
- assert @base.respond_to?(:foo)
15
- assert_equal 'bar', @base.foo
16
- end
17
-
18
- it 'sets settings to Procs' do
19
- @base.set(:foo, Proc.new { 'baz' })
20
- assert @base.respond_to?(:foo)
21
- assert_equal 'baz', @base.foo
22
- end
23
-
24
- it 'sets settings using a block' do
25
- @base.set(:foo){ 'baz' }
26
- assert @base.respond_to?(:foo)
27
- assert_equal 'baz', @base.foo
28
- end
29
-
30
- it 'raises an error with a value and a block' do
31
- assert_raises ArgumentError do
32
- @base.set(:fiz, 'boom!'){ 'baz' }
33
- end
34
- assert !@base.respond_to?(:fiz)
35
- end
36
-
37
- it 'raises an error without value and block' do
38
- assert_raises(ArgumentError) { @base.set(:fiz) }
39
- assert !@base.respond_to?(:fiz)
40
- end
41
-
42
- it 'allows setting a value to the app class' do
43
- @base.set :base, @base
44
- assert @base.respond_to?(:base)
45
- assert_equal @base, @base.base
46
- end
47
-
48
- it 'raises an error with the app class as value and a block' do
49
- assert_raises ArgumentError do
50
- @base.set(:fiz, @base) { 'baz' }
51
- end
52
- assert !@base.respond_to?(:fiz)
53
- end
54
-
55
- it "sets multiple settings with a Hash" do
56
- @base.set :foo => 1234,
57
- :bar => 'Hello World',
58
- :baz => Proc.new { 'bizzle' }
59
- assert_equal 1234, @base.foo
60
- assert_equal 'Hello World', @base.bar
61
- assert_equal 'bizzle', @base.baz
62
- end
63
-
64
- it 'sets multiple settings using #each' do
65
- @base.set [["foo", "bar"]]
66
- assert_equal "bar", @base.foo
67
- end
68
-
69
- it 'inherits settings methods when subclassed' do
70
- @base.set :foo, 'bar'
71
- @base.set :biz, Proc.new { 'baz' }
72
-
73
- sub = Class.new(@base)
74
- assert sub.respond_to?(:foo)
75
- assert_equal 'bar', sub.foo
76
- assert sub.respond_to?(:biz)
77
- assert_equal 'baz', sub.biz
78
- end
79
-
80
- it 'overrides settings in subclass' do
81
- @base.set :foo, 'bar'
82
- @base.set :biz, Proc.new { 'baz' }
83
- sub = Class.new(@base)
84
- sub.set :foo, 'bling'
85
- assert_equal 'bling', sub.foo
86
- assert_equal 'bar', @base.foo
87
- end
88
-
89
- it 'creates setter methods when first defined' do
90
- @base.set :foo, 'bar'
91
- assert @base.respond_to?('foo=')
92
- @base.foo = 'biz'
93
- assert_equal 'biz', @base.foo
94
- end
95
-
96
- it 'creates predicate methods when first defined' do
97
- @base.set :foo, 'hello world'
98
- assert @base.respond_to?(:foo?)
99
- assert @base.foo?
100
- @base.set :foo, nil
101
- assert !@base.foo?
102
- end
103
-
104
- it 'uses existing setter methods if detected' do
105
- class << @base
106
- def foo
107
- @foo
108
- end
109
- def foo=(value)
110
- @foo = 'oops'
111
- end
112
- end
113
-
114
- @base.set :foo, 'bam'
115
- assert_equal 'oops', @base.foo
116
- end
117
-
118
- it 'merges values of multiple set calls if those are hashes' do
119
- @base.set :foo, :a => 1
120
- sub = Class.new(@base)
121
- sub.set :foo, :b => 2
122
- assert_equal({:a => 1, :b => 2}, sub.foo)
123
- end
124
-
125
- it 'merging does not affect the superclass' do
126
- @base.set :foo, :a => 1
127
- sub = Class.new(@base)
128
- sub.set :foo, :b => 2
129
- assert_equal({:a => 1}, @base.foo)
130
- end
131
-
132
- it 'is possible to change a value from a hash to something else' do
133
- @base.set :foo, :a => 1
134
- @base.set :foo, :bar
135
- assert_equal(:bar, @base.foo)
136
- end
137
-
138
- it 'merges values with values of the superclass if those are hashes' do
139
- @base.set :foo, :a => 1
140
- @base.set :foo, :b => 2
141
- assert_equal({:a => 1, :b => 2}, @base.foo)
142
- end
143
-
144
- it "sets multiple settings to true with #enable" do
145
- @base.enable :sessions, :foo, :bar
146
- assert @base.sessions
147
- assert @base.foo
148
- assert @base.bar
149
- end
150
-
151
- it "sets multiple settings to false with #disable" do
152
- @base.disable :sessions, :foo, :bar
153
- assert !@base.sessions
154
- assert !@base.foo
155
- assert !@base.bar
156
- end
157
-
158
- it 'is accessible from instances via #settings' do
159
- assert_equal :foo, @base.new!.settings.environment
160
- end
161
-
162
- it 'is accessible from class via #settings' do
163
- assert_equal :foo, @base.settings.environment
164
- end
165
-
166
- describe 'methodoverride' do
167
- it 'is disabled on Base' do
168
- assert ! @base.method_override?
169
- end
170
-
171
- it 'is enabled on Application' do
172
- assert @application.method_override?
173
- end
174
-
175
- it 'enables MethodOverride middleware' do
176
- @base.set :method_override, true
177
- @base.put('/') { 'okay' }
178
- @app = @base
179
- post '/', {'_method'=>'PUT'}, {}
180
- assert_equal 200, status
181
- assert_equal 'okay', body
182
- end
183
-
184
- it 'is backward compatible with methodoverride' do
185
- assert ! @base.methodoverride?
186
- @base.enable :methodoverride
187
- assert @base.methodoverride?
188
- end
189
- end
190
-
191
- describe 'run' do
192
- it 'is disabled on Base' do
193
- assert ! @base.run?
194
- end
195
-
196
- it 'is enabled on Application except in test environment' do
197
- assert @application.run?
198
-
199
- @application.set :environment, :test
200
- assert ! @application.run?
201
- end
202
- end
203
-
204
- describe 'raise_errors' do
205
- it 'is enabled on Base only in test' do
206
- assert ! @base.raise_errors?
207
-
208
- @base.set(:environment, :test)
209
- assert @base.raise_errors?
210
- end
211
-
212
- it 'is enabled on Application only in test' do
213
- assert ! @application.raise_errors?
214
-
215
- @application.set(:environment, :test)
216
- assert @application.raise_errors?
217
- end
218
- end
219
-
220
- describe 'show_exceptions' do
221
- it 'is disabled on Base except under development' do
222
- assert ! @base.show_exceptions?
223
- @base.environment = :development
224
- assert @base.show_exceptions?
225
- end
226
-
227
- it 'is disabled on Application except in development' do
228
- assert ! @application.show_exceptions?
229
-
230
- @application.set(:environment, :development)
231
- assert @application.show_exceptions?
232
- end
233
-
234
- it 'returns a friendly 500' do
235
- klass = Sinatra.new(Sinatra::Application)
236
- mock_app(klass) {
237
- enable :show_exceptions
238
-
239
- get '/' do
240
- raise StandardError
241
- end
242
- }
243
-
244
- get '/'
245
- assert_equal 500, status
246
- assert body.include?("StandardError")
247
- assert body.include?("<code>show_exceptions</code> setting")
248
- end
249
-
250
- it 'does not override app-specified error handling when set to :after_handler' do
251
- ran = false
252
- mock_app do
253
- set :show_exceptions, :after_handler
254
- error(RuntimeError) { ran = true }
255
- get('/') { raise RuntimeError }
256
- end
257
-
258
- get '/'
259
- assert_equal 500, status
260
- assert ran
261
- end
262
-
263
- it 'does catch any other exceptions when set to :after_handler' do
264
- ran = false
265
- mock_app do
266
- set :show_exceptions, :after_handler
267
- error(RuntimeError) { ran = true }
268
- get('/') { raise ArgumentError }
269
- end
270
-
271
- get '/'
272
- assert_equal 500, status
273
- assert !ran
274
- end
275
- end
276
-
277
- describe 'dump_errors' do
278
- it 'is disabled on Base in test' do
279
- @base.environment = :test
280
- assert ! @base.dump_errors?
281
- @base.environment = :development
282
- assert @base.dump_errors?
283
- @base.environment = :production
284
- assert @base.dump_errors?
285
- end
286
-
287
- it 'dumps exception with backtrace to rack.errors' do
288
- klass = Sinatra.new(Sinatra::Application)
289
-
290
- mock_app(klass) {
291
- enable :dump_errors
292
- disable :raise_errors
293
-
294
- error do
295
- error = @env['rack.errors'].instance_variable_get(:@error)
296
- error.rewind
297
-
298
- error.read
299
- end
300
-
301
- get '/' do
302
- raise
303
- end
304
- }
305
-
306
- get '/'
307
- assert body.include?("RuntimeError") && body.include?("settings_test.rb")
308
- end
309
-
310
- it 'does not dump 404 errors' do
311
- klass = Sinatra.new(Sinatra::Application)
312
-
313
- mock_app(klass) {
314
- enable :dump_errors
315
- disable :raise_errors
316
-
317
- error do
318
- error = @env['rack.errors'].instance_variable_get(:@error)
319
- error.rewind
320
-
321
- error.read
322
- end
323
-
324
- get '/' do
325
- raise Sinatra::NotFound
326
- end
327
- }
328
-
329
- get '/'
330
- assert !body.include?("NotFound") && !body.include?("settings_test.rb")
331
- end
332
- end
333
-
334
- describe 'sessions' do
335
- it 'is disabled on Base' do
336
- assert ! @base.sessions?
337
- end
338
-
339
- it 'is disabled on Application' do
340
- assert ! @application.sessions?
341
- end
342
- end
343
-
344
- describe 'logging' do
345
- it 'is disabled on Base' do
346
- assert ! @base.logging?
347
- end
348
-
349
- it 'is enabled on Application except in test environment' do
350
- assert @application.logging?
351
-
352
- @application.set :environment, :test
353
- assert ! @application.logging
354
- end
355
- end
356
-
357
- describe 'static' do
358
- it 'is disabled on Base by default' do
359
- assert ! @base.static?
360
- end
361
-
362
- it 'is enabled on Base when public_folder is set and exists' do
363
- @base.set :environment, :development
364
- @base.set :public_folder, File.dirname(__FILE__)
365
- assert @base.static?
366
- end
367
-
368
- it 'is enabled on Base when root is set and root/public_folder exists' do
369
- @base.set :environment, :development
370
- @base.set :root, File.dirname(__FILE__)
371
- assert @base.static?
372
- end
373
-
374
- it 'is disabled on Application by default' do
375
- assert ! @application.static?
376
- end
377
-
378
- it 'is enabled on Application when public_folder is set and exists' do
379
- @application.set :environment, :development
380
- @application.set :public_folder, File.dirname(__FILE__)
381
- assert @application.static?
382
- end
383
-
384
- it 'is enabled on Application when root is set and root/public_folder exists' do
385
- @application.set :environment, :development
386
- @application.set :root, File.dirname(__FILE__)
387
- assert @application.static?
388
- end
389
-
390
- it 'is possible to use Module#public' do
391
- @base.send(:define_method, :foo) { }
392
- @base.send(:private, :foo)
393
- assert !@base.public_method_defined?(:foo)
394
- @base.send(:public, :foo)
395
- assert @base.public_method_defined?(:foo)
396
- end
397
-
398
- it 'is possible to use the keyword public in a sinatra app' do
399
- app = Sinatra.new do
400
- private
401
- def priv; end
402
- public
403
- def pub; end
404
- end
405
- assert !app.public_method_defined?(:priv)
406
- assert app.public_method_defined?(:pub)
407
- end
408
- end
409
-
410
- describe 'bind' do
411
- it 'defaults to 0.0.0.0' do
412
- assert_equal '0.0.0.0', @base.bind
413
- assert_equal '0.0.0.0', @application.bind
414
- end
415
- end
416
-
417
- describe 'port' do
418
- it 'defaults to 4567' do
419
- assert_equal 4567, @base.port
420
- assert_equal 4567, @application.port
421
- end
422
- end
423
-
424
- describe 'server' do
425
- it 'includes webrick' do
426
- assert @base.server.include?('webrick')
427
- assert @application.server.include?('webrick')
428
- end
429
-
430
- it 'includes puma' do
431
- assert @base.server.include?('puma')
432
- assert @application.server.include?('puma')
433
- end
434
-
435
- it 'includes thin' do
436
- next if RUBY_ENGINE == 'jruby'
437
- assert @base.server.include?('thin')
438
- assert @application.server.include?('thin')
439
- end
440
- end
441
-
442
- describe 'app_file' do
443
- it 'is nil for base classes' do
444
- assert_nil Sinatra::Base.app_file
445
- assert_nil Sinatra::Application.app_file
446
- end
447
-
448
- it 'defaults to the file subclassing' do
449
- assert_equal File.expand_path(__FILE__), Sinatra.new.app_file
450
- end
451
- end
452
-
453
- describe 'root' do
454
- it 'is nil if app_file is not set' do
455
- assert @base.root.nil?
456
- assert @application.root.nil?
457
- end
458
-
459
- it 'is equal to the expanded basename of app_file' do
460
- @base.app_file = __FILE__
461
- assert_equal File.expand_path(File.dirname(__FILE__)), @base.root
462
-
463
- @application.app_file = __FILE__
464
- assert_equal File.expand_path(File.dirname(__FILE__)), @application.root
465
- end
466
- end
467
-
468
- describe 'views' do
469
- it 'is nil if root is not set' do
470
- assert @base.views.nil?
471
- assert @application.views.nil?
472
- end
473
-
474
- it 'is set to root joined with views/' do
475
- @base.root = File.dirname(__FILE__)
476
- assert_equal File.dirname(__FILE__) + "/views", @base.views
477
-
478
- @application.root = File.dirname(__FILE__)
479
- assert_equal File.dirname(__FILE__) + "/views", @application.views
480
- end
481
- end
482
-
483
- describe 'public_folder' do
484
- it 'is nil if root is not set' do
485
- assert @base.public_folder.nil?
486
- assert @application.public_folder.nil?
487
- end
488
-
489
- it 'is set to root joined with public/' do
490
- @base.root = File.dirname(__FILE__)
491
- assert_equal File.dirname(__FILE__) + "/public", @base.public_folder
492
-
493
- @application.root = File.dirname(__FILE__)
494
- assert_equal File.dirname(__FILE__) + "/public", @application.public_folder
495
- end
496
- end
497
-
498
- describe 'public_dir' do
499
- it 'is an alias for public_folder' do
500
- @base.public_dir = File.dirname(__FILE__)
501
- assert_equal File.dirname(__FILE__), @base.public_dir
502
- assert_equal @base.public_folder, @base.public_dir
503
-
504
- @application.public_dir = File.dirname(__FILE__)
505
- assert_equal File.dirname(__FILE__), @application.public_dir
506
- assert_equal @application.public_folder, @application.public_dir
507
- end
508
- end
509
-
510
- describe 'lock' do
511
- it 'is disabled by default' do
512
- assert ! @base.lock?
513
- assert ! @application.lock?
514
- end
515
- end
516
-
517
- describe 'protection' do
518
- class MiddlewareTracker < Rack::Builder
519
- def self.track
520
- Rack.send :remove_const, :Builder
521
- Rack.const_set :Builder, MiddlewareTracker
522
- MiddlewareTracker.used.clear
523
- yield
524
- ensure
525
- Rack.send :remove_const, :Builder
526
- Rack.const_set :Builder, MiddlewareTracker.superclass
527
- end
528
-
529
- def self.used
530
- @used ||= []
531
- end
532
-
533
- def use(middleware, *)
534
- MiddlewareTracker.used << middleware
535
- super
536
- end
537
- end
538
-
539
- it 'sets up Rack::Protection' do
540
- MiddlewareTracker.track do
541
- Sinatra::Base.new
542
- assert_include MiddlewareTracker.used, Rack::Protection
543
- end
544
- end
545
-
546
- it 'sets up Rack::Protection::PathTraversal' do
547
- MiddlewareTracker.track do
548
- Sinatra::Base.new
549
- assert_include MiddlewareTracker.used, Rack::Protection::PathTraversal
550
- end
551
- end
552
-
553
- it 'does not set up Rack::Protection::PathTraversal when disabling it' do
554
- MiddlewareTracker.track do
555
- Sinatra.new { set :protection, :except => :path_traversal }.new
556
- assert_include MiddlewareTracker.used, Rack::Protection
557
- assert !MiddlewareTracker.used.include?(Rack::Protection::PathTraversal)
558
- end
559
- end
560
-
561
- it 'sets up RemoteToken if sessions are enabled' do
562
- MiddlewareTracker.track do
563
- Sinatra.new { enable :sessions }.new
564
- assert_include MiddlewareTracker.used, Rack::Protection::RemoteToken
565
- end
566
- end
567
-
568
- it 'does not set up RemoteToken if sessions are disabled' do
569
- MiddlewareTracker.track do
570
- Sinatra.new.new
571
- assert !MiddlewareTracker.used.include?(Rack::Protection::RemoteToken)
572
- end
573
- end
574
-
575
- it 'sets up RemoteToken if it is configured to' do
576
- MiddlewareTracker.track do
577
- Sinatra.new { set :protection, :session => true }.new
578
- assert_include MiddlewareTracker.used, Rack::Protection::RemoteToken
579
- end
580
- end
581
- end
582
- end