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,91 +0,0 @@
1
- # Copyright (c) 2009 Damian Janowski and Michel Martens for Citrusbyte
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
- require "rubygems"
21
- require "minitest/autorun"
22
-
23
- # Contest adds +teardown+, +test+ and +context+ as class methods, and the
24
- # instance methods +setup+ and +teardown+ now iterate on the corresponding
25
- # blocks. Note that all setup and teardown blocks must be defined with the
26
- # block syntax. Adding setup or teardown instance methods defeats the purpose
27
- # of this library.
28
- class Minitest::Test
29
- def self.setup(&block) setup_blocks << block end
30
- def self.teardown(&block) teardown_blocks << block end
31
- def self.setup_blocks() @setup_blocks ||= [] end
32
- def self.teardown_blocks() @teardown_blocks ||= [] end
33
-
34
- def setup_blocks(base = self.class)
35
- setup_blocks base.superclass if base.superclass.respond_to? :setup_blocks
36
- base.setup_blocks.each do |block|
37
- instance_eval(&block)
38
- end
39
- end
40
-
41
- def teardown_blocks(base = self.class)
42
- teardown_blocks base.superclass if base.superclass.respond_to? :teardown_blocks
43
- base.teardown_blocks.each do |block|
44
- instance_eval(&block)
45
- end
46
- end
47
-
48
- alias setup setup_blocks
49
- alias teardown teardown_blocks
50
-
51
- def self.context(*name, &block)
52
- subclass = Class.new(self)
53
- remove_tests(subclass)
54
- subclass.class_eval(&block) if block_given?
55
- const_set(context_name(name.join(" ")), subclass)
56
- end
57
-
58
- def self.test(name, &block)
59
- define_method(test_name(name), &block)
60
- end
61
-
62
- class << self
63
- alias_method :should, :test
64
- alias_method :describe, :context
65
- end
66
-
67
- private
68
-
69
- def self.context_name(name)
70
- # "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym
71
- name = "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}"
72
- name.tr(" ", "_").to_sym
73
- end
74
-
75
- def self.test_name(name)
76
- name = "test_#{sanitize_name(name).gsub(/\s+/,'_')}_0"
77
- name = name.succ while method_defined? name
78
- name.to_sym
79
- end
80
-
81
- def self.sanitize_name(name)
82
- # name.gsub(/\W+/, ' ').strip
83
- name.gsub(/\W+/, ' ')
84
- end
85
-
86
- def self.remove_tests(subclass)
87
- subclass.public_instance_methods.grep(/^test_/).each do |meth|
88
- subclass.send(:undef_method, meth.to_sym)
89
- end
90
- end
91
- end
@@ -1,65 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- begin
4
- require 'creole'
5
-
6
- class CreoleTest < Minitest::Test
7
- def creole_app(&block)
8
- mock_app do
9
- set :views, File.dirname(__FILE__) + '/views'
10
- get('/', &block)
11
- end
12
- get '/'
13
- end
14
-
15
- it 'renders inline creole strings' do
16
- creole_app { creole '= Hiya' }
17
- assert ok?
18
- assert_body "<h1>Hiya</h1>"
19
- end
20
-
21
- it 'renders .creole files in views path' do
22
- creole_app { creole :hello }
23
- assert ok?
24
- assert_body "<h1>Hello From Creole</h1>"
25
- end
26
-
27
- it "raises error if template not found" do
28
- mock_app { get('/') { creole :no_such_template } }
29
- assert_raises(Errno::ENOENT) { get('/') }
30
- end
31
-
32
- it "renders with inline layouts" do
33
- mock_app do
34
- layout { 'THIS. IS. #{yield.upcase}!' }
35
- get('/') { creole 'Sparta', :layout_engine => :str }
36
- end
37
- get '/'
38
- assert ok?
39
- assert_like 'THIS. IS. <P>SPARTA</P>!', body
40
- end
41
-
42
- it "renders with file layouts" do
43
- creole_app do
44
- creole 'Hello World', :layout => :layout2, :layout_engine => :erb
45
- end
46
- assert ok?
47
- assert_body "ERB Layout!\n<p>Hello World</p>"
48
- end
49
-
50
- it "can be used in a nested fashion for partials and whatnot" do
51
- mock_app do
52
- template(:inner) { "hi" }
53
- template(:outer) { "<outer><%= creole :inner %></outer>" }
54
- get('/') { erb :outer }
55
- end
56
-
57
- get '/'
58
- assert ok?
59
- assert_like '<outer><p>hi</p></outer>', body
60
- end
61
- end
62
-
63
- rescue LoadError
64
- warn "#{$!.to_s}: skipping creole tests"
65
- end
@@ -1,160 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- class DelegatorTest < Minitest::Test
4
- class Mirror
5
- attr_reader :last_call
6
- def method_missing(*a, &b)
7
- @last_call = [*a.map(&:to_s)]
8
- @last_call << b if b
9
- end
10
- end
11
-
12
- def self.delegates(name)
13
- it "delegates #{name}" do
14
- m = mirror { send name }
15
- assert_equal [name.to_s], m.last_call
16
- end
17
-
18
- it "delegates #{name} with arguments" do
19
- m = mirror { send name, "foo", "bar" }
20
- assert_equal [name.to_s, "foo", "bar"], m.last_call
21
- end
22
-
23
- it "delegates #{name} with block" do
24
- block = proc { }
25
- m = mirror { send(name, &block) }
26
- assert_equal [name.to_s, block], m.last_call
27
- end
28
- end
29
-
30
- setup do
31
- @target_was = Sinatra::Delegator.target
32
- end
33
-
34
- def teardown
35
- Sinatra::Delegator.target = @target_was
36
- end
37
-
38
- def delegation_app(&block)
39
- mock_app { Sinatra::Delegator.target = self }
40
- delegate(&block)
41
- end
42
-
43
- def mirror(&block)
44
- mirror = Mirror.new
45
- Sinatra::Delegator.target = mirror
46
- delegate(&block)
47
- end
48
-
49
- def delegate(&block)
50
- assert Sinatra::Delegator.target != Sinatra::Application
51
- Object.new.extend(Sinatra::Delegator).instance_eval(&block) if block
52
- Sinatra::Delegator.target
53
- end
54
-
55
- def target
56
- Sinatra::Delegator.target
57
- end
58
-
59
- it 'defaults to Sinatra::Application as target' do
60
- assert_equal Sinatra::Application, Sinatra::Delegator.target
61
- end
62
-
63
- %w[get put post delete options patch link unlink].each do |verb|
64
- it "delegates #{verb} correctly" do
65
- delegation_app do
66
- send(verb, '/hello') { 'Hello World' }
67
- end
68
-
69
- request = Rack::MockRequest.new(@app)
70
- response = request.request(verb.upcase, '/hello', {})
71
- assert response.ok?
72
- assert_equal 'Hello World', response.body
73
- end
74
- end
75
-
76
- it "delegates head correctly" do
77
- delegation_app do
78
- head '/hello' do
79
- response['X-Hello'] = 'World!'
80
- 'remove me'
81
- end
82
- end
83
-
84
- request = Rack::MockRequest.new(@app)
85
- response = request.request('HEAD', '/hello', {})
86
- assert response.ok?
87
- assert_equal 'World!', response['X-Hello']
88
- assert_equal '', response.body
89
- end
90
-
91
- it "registers extensions with the delegation target" do
92
- app, mixin = mirror, Module.new
93
- Sinatra.register mixin
94
- assert_equal ["register", mixin.to_s], app.last_call
95
- end
96
-
97
- it "registers helpers with the delegation target" do
98
- app, mixin = mirror, Module.new
99
- Sinatra.helpers mixin
100
- assert_equal ["helpers", mixin.to_s], app.last_call
101
- end
102
-
103
- it "registers middleware with the delegation target" do
104
- app, mixin = mirror, Module.new
105
- Sinatra.use mixin
106
- assert_equal ["use", mixin.to_s], app.last_call
107
- end
108
-
109
- it "should work with method_missing proxies for options" do
110
- mixin = Module.new do
111
- def respond_to?(method, *)
112
- method.to_sym == :options or super
113
- end
114
-
115
- def method_missing(method, *args, &block)
116
- return super unless method.to_sym == :options
117
- {:some => :option}
118
- end
119
- end
120
-
121
- value = nil
122
- mirror do
123
- extend mixin
124
- value = options
125
- end
126
-
127
- assert_equal({:some => :option}, value)
128
- end
129
-
130
- it "delegates crazy method names" do
131
- Sinatra::Delegator.delegate "foo:bar:"
132
- method = mirror { send "foo:bar:" }.last_call.first
133
- assert_equal "foo:bar:", method
134
- end
135
-
136
- delegates 'get'
137
- delegates 'patch'
138
- delegates 'put'
139
- delegates 'post'
140
- delegates 'delete'
141
- delegates 'head'
142
- delegates 'options'
143
- delegates 'template'
144
- delegates 'layout'
145
- delegates 'before'
146
- delegates 'after'
147
- delegates 'error'
148
- delegates 'not_found'
149
- delegates 'configure'
150
- delegates 'set'
151
- delegates 'mime_type'
152
- delegates 'enable'
153
- delegates 'disable'
154
- delegates 'use'
155
- delegates 'development?'
156
- delegates 'test?'
157
- delegates 'production?'
158
- delegates 'helpers'
159
- delegates 'settings'
160
- end
@@ -1,20 +0,0 @@
1
- # encoding: UTF-8
2
- require File.expand_path('../helper', __FILE__)
3
- require 'erb'
4
-
5
- class BaseTest < Minitest::Test
6
- setup do
7
- @base = Sinatra.new(Sinatra::Base)
8
- @base.set :views, File.dirname(__FILE__) + "/views"
9
- end
10
-
11
- it 'allows unicode strings in ascii templates per default (1.9)' do
12
- next unless defined? Encoding
13
- @base.new!.erb(File.read(@base.views + "/ascii.erb").encode("ASCII"), {}, :value => "åkej")
14
- end
15
-
16
- it 'allows ascii strings in unicode templates per default (1.9)' do
17
- next unless defined? Encoding
18
- @base.new!.erb(:utf8, {}, :value => "Some Lyrics".encode("ASCII"))
19
- end
20
- end
@@ -1,116 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- class ERBTest < Minitest::Test
4
- def engine
5
- Tilt::ERBTemplate
6
- end
7
-
8
- def setup
9
- Tilt.prefer engine, :erb
10
- super
11
- end
12
-
13
- def erb_app(&block)
14
- mock_app do
15
- set :views, File.dirname(__FILE__) + '/views'
16
- get('/', &block)
17
- end
18
- get '/'
19
- end
20
-
21
- it 'uses the correct engine' do
22
- assert_equal engine, Tilt[:erb]
23
- end
24
-
25
- it 'renders inline ERB strings' do
26
- erb_app { erb '<%= 1 + 1 %>' }
27
- assert ok?
28
- assert_equal '2', body
29
- end
30
-
31
- it 'renders .erb files in views path' do
32
- erb_app { erb :hello }
33
- assert ok?
34
- assert_equal "Hello World\n", body
35
- end
36
-
37
- it 'takes a :locals option' do
38
- erb_app do
39
- locals = {:foo => 'Bar'}
40
- erb '<%= foo %>', :locals => locals
41
- end
42
- assert ok?
43
- assert_equal 'Bar', body
44
- end
45
-
46
- it "renders with inline layouts" do
47
- mock_app do
48
- layout { 'THIS. IS. <%= yield.upcase %>!' }
49
- get('/') { erb 'Sparta' }
50
- end
51
- get '/'
52
- assert ok?
53
- assert_equal 'THIS. IS. SPARTA!', body
54
- end
55
-
56
- it "renders with file layouts" do
57
- erb_app { erb 'Hello World', :layout => :layout2 }
58
- assert ok?
59
- assert_body "ERB Layout!\nHello World"
60
- end
61
-
62
- it "renders erb with blocks" do
63
- mock_app do
64
- def container
65
- @_out_buf << "THIS."
66
- yield
67
- @_out_buf << "SPARTA!"
68
- end
69
- def is; "IS." end
70
- get('/') { erb '<% container do %> <%= is %> <% end %>' }
71
- end
72
- get '/'
73
- assert ok?
74
- assert_equal 'THIS. IS. SPARTA!', body
75
- end
76
-
77
- it "can be used in a nested fashion for partials and whatnot" do
78
- mock_app do
79
- template(:inner) { "<inner><%= 'hi' %></inner>" }
80
- template(:outer) { "<outer><%= erb :inner %></outer>" }
81
- get('/') { erb :outer }
82
- end
83
-
84
- get '/'
85
- assert ok?
86
- assert_equal '<outer><inner>hi</inner></outer>', body
87
- end
88
-
89
- it "can render truly nested layouts by accepting a layout and a block with the contents" do
90
- mock_app do
91
- template(:main_outer_layout) { "<h1>Title</h1>\n<%= yield %>" }
92
- template(:an_inner_layout) { "<h2>Subtitle</h2>\n<%= yield %>" }
93
- template(:a_page) { "<p>Contents.</p>\n" }
94
- get('/') do
95
- erb :main_outer_layout, :layout => false do
96
- erb :an_inner_layout do
97
- erb :a_page
98
- end
99
- end
100
- end
101
- end
102
- get '/'
103
- assert ok?
104
- assert_body "<h1>Title</h1>\n<h2>Subtitle</h2>\n<p>Contents.</p>\n"
105
- end
106
- end
107
-
108
-
109
- begin
110
- require 'erubis'
111
- class ErubisTest < ERBTest
112
- def engine; Tilt::ErubisTemplate end
113
- end
114
- rescue LoadError
115
- warn "#{$!.to_s}: skipping erubis tests"
116
- end