sinatra 1.4.5 → 1.4.6

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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHORS.md +77 -0
  3. data/CHANGES +30 -0
  4. data/Gemfile +5 -5
  5. data/README.de.md +186 -56
  6. data/README.es.md +76 -76
  7. data/README.fr.md +120 -56
  8. data/README.hu.md +19 -19
  9. data/README.ja.md +44 -46
  10. data/README.ko.md +163 -67
  11. data/README.md +151 -127
  12. data/README.pt-br.md +905 -144
  13. data/README.pt-pt.md +17 -17
  14. data/README.ru.md +88 -52
  15. data/README.zh.md +76 -68
  16. data/lib/sinatra.rb +0 -1
  17. data/lib/sinatra/base.rb +21 -15
  18. data/lib/sinatra/show_exceptions.rb +10 -4
  19. data/lib/sinatra/version.rb +1 -1
  20. data/sinatra.gemspec +1 -1
  21. data/test/asciidoctor_test.rb +2 -2
  22. data/test/base_test.rb +1 -5
  23. data/test/builder_test.rb +2 -2
  24. data/test/coffee_test.rb +8 -2
  25. data/test/compile_test.rb +1 -1
  26. data/test/contest.rb +3 -12
  27. data/test/creole_test.rb +2 -2
  28. data/test/delegator_test.rb +1 -1
  29. data/test/encoding_test.rb +1 -1
  30. data/test/erb_test.rb +1 -1
  31. data/test/extensions_test.rb +1 -1
  32. data/test/filter_test.rb +2 -2
  33. data/test/haml_test.rb +2 -2
  34. data/test/helper.rb +8 -7
  35. data/test/helpers_test.rb +6 -6
  36. data/test/integration_test.rb +3 -3
  37. data/test/less_test.rb +2 -2
  38. data/test/liquid_test.rb +3 -3
  39. data/test/mapped_error_test.rb +5 -5
  40. data/test/markaby_test.rb +2 -2
  41. data/test/markdown_test.rb +6 -3
  42. data/test/mediawiki_test.rb +2 -2
  43. data/test/middleware_test.rb +1 -1
  44. data/test/nokogiri_test.rb +2 -2
  45. data/test/rabl_test.rb +2 -2
  46. data/test/rack_test.rb +1 -1
  47. data/test/radius_test.rb +2 -2
  48. data/test/rdoc_test.rb +4 -4
  49. data/test/readme_test.rb +1 -1
  50. data/test/request_test.rb +4 -1
  51. data/test/response_test.rb +1 -1
  52. data/test/result_test.rb +2 -2
  53. data/test/route_added_hook_test.rb +1 -1
  54. data/test/routing_test.rb +7 -7
  55. data/test/sass_test.rb +3 -3
  56. data/test/scss_test.rb +2 -2
  57. data/test/server_test.rb +10 -2
  58. data/test/settings_test.rb +4 -4
  59. data/test/sinatra_test.rb +1 -1
  60. data/test/slim_test.rb +2 -2
  61. data/test/static_test.rb +2 -2
  62. data/test/streaming_test.rb +2 -2
  63. data/test/stylus_test.rb +2 -2
  64. data/test/templates_test.rb +3 -3
  65. data/test/textile_test.rb +2 -2
  66. data/test/wlang_test.rb +1 -1
  67. data/test/yajl_test.rb +2 -2
  68. metadata +10 -11
  69. data/AUTHORS +0 -61
@@ -1,4 +1,3 @@
1
- require 'sinatra/base'
2
1
  require 'sinatra/main'
3
2
 
4
3
  enable :inline_templates
@@ -14,7 +14,7 @@ require 'sinatra/version'
14
14
 
15
15
  module Sinatra
16
16
  # The request object. See Rack::Request for more info:
17
- # http://rack.rubyforge.org/doc/classes/Rack/Request.html
17
+ # http://rubydoc.info/github/rack/rack/master/Rack/Request
18
18
  class Request < Rack::Request
19
19
  HEADER_PARAM = /\s*[\w.]+=(?:[\w.]+|"(?:[^"\\]|\\.)*")?\s*/
20
20
  HEADER_VALUE_WITH_PARAMS = /(?:(?:\w+|\*)\/(?:\w+(?:\.|\-|\+)?|\*)*)\s*(?:;#{HEADER_PARAM})*/
@@ -72,6 +72,7 @@ module Sinatra
72
72
 
73
73
  class AcceptEntry
74
74
  attr_accessor :params
75
+ attr_reader :entry
75
76
 
76
77
  def initialize(entry)
77
78
  params = entry.scan(HEADER_PARAM).map! do |s|
@@ -115,8 +116,8 @@ module Sinatra
115
116
 
116
117
  # The response object. See Rack::Response and Rack::Response::Helpers for
117
118
  # more info:
118
- # http://rack.rubyforge.org/doc/classes/Rack/Response.html
119
- # http://rack.rubyforge.org/doc/classes/Rack/Response/Helpers.html
119
+ # http://rubydoc.info/github/rack/rack/master/Rack/Response
120
+ # http://rubydoc.info/github/rack/rack/master/Rack/Response/Helpers
120
121
  class Response < Rack::Response
121
122
  DROP_BODY_RESPONSES = [204, 205, 304]
122
123
  def initialize(*)
@@ -390,7 +391,7 @@ module Sinatra
390
391
  end
391
392
 
392
393
  def close
393
- return if @closed
394
+ return if closed?
394
395
  @closed = true
395
396
  @scheduler.schedule { @callbacks.each { |c| c.call }}
396
397
  end
@@ -413,7 +414,7 @@ module Sinatra
413
414
  end
414
415
 
415
416
  def callback(&block)
416
- return yield if @closed
417
+ return yield if closed?
417
418
  @callbacks << block
418
419
  end
419
420
 
@@ -768,9 +769,16 @@ module Sinatra
768
769
  # named name.ext, where ext is registered on engine.
769
770
  def find_template(views, name, engine)
770
771
  yield ::File.join(views, "#{name}.#{@preferred_extension}")
771
- Tilt.mappings.each do |ext, engines|
772
- next unless ext != @preferred_extension and engines.include? engine
773
- yield ::File.join(views, "#{name}.#{ext}")
772
+
773
+ if Tilt.respond_to?(:mappings)
774
+ Tilt.mappings.each do |ext, engines|
775
+ next unless ext != @preferred_extension and engines.include? engine
776
+ yield ::File.join(views, "#{name}.#{ext}")
777
+ end
778
+ else
779
+ Tilt.default_mapping.extensions_for(engine).each do |ext|
780
+ yield ::File.join(views, "#{name}.#{ext}") unless ext == @preferred_extension
781
+ end
774
782
  end
775
783
  end
776
784
 
@@ -1132,7 +1140,7 @@ module Sinatra
1132
1140
  end
1133
1141
 
1134
1142
  def dump_errors!(boom)
1135
- msg = ["#{boom.class} - #{boom.message}:", *boom.backtrace].join("\n\t")
1143
+ msg = ["#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{boom.class} - #{boom.message}:", *boom.backtrace].join("\n\t")
1136
1144
  @env['rack.errors'].puts(msg)
1137
1145
  end
1138
1146
 
@@ -1496,8 +1504,7 @@ module Sinatra
1496
1504
  def start_server(handler, server_settings, handler_name)
1497
1505
  handler.run(self, server_settings) do |server|
1498
1506
  unless handler_name =~ /cgi/i
1499
- $stderr.puts "== Sinatra/#{Sinatra::VERSION} has taken the stage " +
1500
- "on #{port} for #{environment} with backup from #{handler_name}"
1507
+ $stderr.puts "== Sinatra (v#{Sinatra::VERSION}) has taken the stage on #{port} for #{environment} with backup from #{handler_name}"
1501
1508
  end
1502
1509
 
1503
1510
  setup_traps
@@ -1899,7 +1906,7 @@ module Sinatra
1899
1906
 
1900
1907
  configure :development do
1901
1908
  get '/__sinatra__/:image.png' do
1902
- filename = File.dirname(__FILE__) + "/images/#{params[:image]}.png"
1909
+ filename = File.dirname(__FILE__) + "/images/#{params[:image].to_i}.png"
1903
1910
  content_type :png
1904
1911
  send_file filename
1905
1912
  end
@@ -1941,7 +1948,7 @@ module Sinatra
1941
1948
  <img src='#{uri "/__sinatra__/404.png"}'>
1942
1949
  <div id="c">
1943
1950
  Try this:
1944
- <pre>#{code}</pre>
1951
+ <pre>#{Rack::Utils.escape_html(code)}</pre>
1945
1952
  </div>
1946
1953
  </body>
1947
1954
  </html>
@@ -2019,8 +2026,7 @@ module Sinatra
2019
2026
  end
2020
2027
  end
2021
2028
 
2022
- # Create a new Sinatra application. The block is evaluated in the new app's
2023
- # class scope.
2029
+ # Create a new Sinatra application; the block is evaluated in the class scope.
2024
2030
  def self.new(base = Base, &block)
2025
2031
  base = Class.new(base)
2026
2032
  base.class_eval(&block) if block_given?
@@ -24,18 +24,24 @@ module Sinatra
24
24
 
25
25
  if prefers_plain_text?(env)
26
26
  content_type = "text/plain"
27
- body = [dump_exception(e)]
27
+ exception_string = dump_exception(e)
28
28
  else
29
29
  content_type = "text/html"
30
- body = pretty(env, e)
30
+ exception_string = pretty(env, e)
31
31
  end
32
32
 
33
33
  env["rack.errors"] = errors
34
34
 
35
- [500,
35
+ # Post 893a2c50 in rack/rack, the #pretty method above, implemented in
36
+ # Rack::ShowExceptions, returns a String instead of an array.
37
+ body = Array(exception_string)
38
+
39
+ [
40
+ 500,
36
41
  {"Content-Type" => content_type,
37
42
  "Content-Length" => Rack::Utils.bytesize(body.join).to_s},
38
- body]
43
+ body
44
+ ]
39
45
  end
40
46
 
41
47
  private
@@ -1,3 +1,3 @@
1
1
  module Sinatra
2
- VERSION = '1.4.5'
2
+ VERSION = '1.4.6'
3
3
  end
@@ -14,6 +14,6 @@ Gem::Specification.new 'sinatra', Sinatra::VERSION do |s|
14
14
  s.rdoc_options = %w[--line-numbers --inline-source --title Sinatra --main README.rdoc --encoding=UTF-8]
15
15
 
16
16
  s.add_dependency 'rack', '~> 1.4'
17
- s.add_dependency 'tilt', '~> 1.3', '>= 1.3.4'
17
+ s.add_dependency 'tilt', '>= 1.3', '< 3'
18
18
  s.add_dependency 'rack-protection', '~> 1.4'
19
19
  end
@@ -3,7 +3,7 @@ require File.expand_path('../helper', __FILE__)
3
3
  begin
4
4
  require 'asciidoctor'
5
5
 
6
- class AsciidoctorTest < Test::Unit::TestCase
6
+ class AsciidoctorTest < Minitest::Test
7
7
  def asciidoc_app(&block)
8
8
  mock_app do
9
9
  set :views, File.dirname(__FILE__) + '/views'
@@ -33,7 +33,7 @@ begin
33
33
 
34
34
  it 'raises error if template not found' do
35
35
  mock_app { get('/') { asciidoc :no_such_template } }
36
- assert_raise(Errno::ENOENT) { get('/') }
36
+ assert_raises(Errno::ENOENT) { get('/') }
37
37
  end
38
38
 
39
39
  it 'renders with inline layouts' do
@@ -1,10 +1,6 @@
1
1
  require File.expand_path('../helper', __FILE__)
2
2
 
3
- class BaseTest < Test::Unit::TestCase
4
- def test_default
5
- assert true
6
- end
7
-
3
+ class BaseTest < Minitest::Test
8
4
  describe 'Sinatra::Base subclasses' do
9
5
  class TestApp < Sinatra::Base
10
6
  get('/') { 'Hello World' }
@@ -3,7 +3,7 @@ require File.expand_path('../helper', __FILE__)
3
3
  begin
4
4
  require 'builder'
5
5
 
6
- class BuilderTest < Test::Unit::TestCase
6
+ class BuilderTest < Minitest::Test
7
7
  def builder_app(options = {}, &block)
8
8
  mock_app do
9
9
  set :views, File.dirname(__FILE__) + '/views'
@@ -82,7 +82,7 @@ class BuilderTest < Test::Unit::TestCase
82
82
  mock_app do
83
83
  get('/') { builder :no_such_template }
84
84
  end
85
- assert_raise(Errno::ENOENT) { get('/') }
85
+ assert_raises(Errno::ENOENT) { get('/') }
86
86
  end
87
87
  end
88
88
 
@@ -10,7 +10,7 @@ rescue Exception
10
10
  raise LoadError, 'unable to execute JavaScript'
11
11
  end
12
12
 
13
- class CoffeeTest < Test::Unit::TestCase
13
+ class CoffeeTest < Minitest::Test
14
14
  def coffee_app(options = {}, &block)
15
15
  mock_app do
16
16
  set :views, File.dirname(__FILE__) + '/views'
@@ -65,7 +65,7 @@ class CoffeeTest < Test::Unit::TestCase
65
65
  mock_app {
66
66
  get('/') { coffee :no_such_template }
67
67
  }
68
- assert_raise(Errno::ENOENT) { get('/') }
68
+ assert_raises(Errno::ENOENT) { get('/') }
69
69
  end
70
70
 
71
71
  it "passes coffee options to the coffee engine" do
@@ -87,4 +87,10 @@ end
87
87
 
88
88
  rescue LoadError
89
89
  warn "#{$!.to_s}: skipping coffee tests"
90
+ rescue
91
+ if $!.class.name == 'ExecJS::RuntimeUnavailable'
92
+ warn "#{$!.to_s}: skipping coffee tests"
93
+ else
94
+ raise
95
+ end
90
96
  end
@@ -1,7 +1,7 @@
1
1
  # I like coding: UTF-8
2
2
  require File.expand_path('../helper', __FILE__)
3
3
 
4
- class CompileTest < Test::Unit::TestCase
4
+ class CompileTest < Minitest::Test
5
5
 
6
6
  def self.converts pattern, expected_regexp
7
7
  it "generates #{expected_regexp.source} from #{pattern}" do
@@ -17,24 +17,15 @@
17
17
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
- require "test/unit"
21
-
22
- # Test::Unit loads a default test if the suite is empty, whose purpose is to
23
- # fail. Since having empty contexts is a common practice, we decided to
24
- # overwrite TestSuite#empty? in order to allow them. Having a failure when no
25
- # tests have been defined seems counter-intuitive.
26
- class Test::Unit::TestSuite
27
- def empty?
28
- false
29
- end
30
- end
20
+ require "rubygems"
21
+ require "minitest/autorun"
31
22
 
32
23
  # Contest adds +teardown+, +test+ and +context+ as class methods, and the
33
24
  # instance methods +setup+ and +teardown+ now iterate on the corresponding
34
25
  # blocks. Note that all setup and teardown blocks must be defined with the
35
26
  # block syntax. Adding setup or teardown instance methods defeats the purpose
36
27
  # of this library.
37
- class Test::Unit::TestCase
28
+ class Minitest::Test
38
29
  def self.setup(&block) setup_blocks << block end
39
30
  def self.teardown(&block) teardown_blocks << block end
40
31
  def self.setup_blocks() @setup_blocks ||= [] end
@@ -3,7 +3,7 @@ require File.expand_path('../helper', __FILE__)
3
3
  begin
4
4
  require 'creole'
5
5
 
6
- class CreoleTest < Test::Unit::TestCase
6
+ class CreoleTest < Minitest::Test
7
7
  def creole_app(&block)
8
8
  mock_app do
9
9
  set :views, File.dirname(__FILE__) + '/views'
@@ -26,7 +26,7 @@ class CreoleTest < Test::Unit::TestCase
26
26
 
27
27
  it "raises error if template not found" do
28
28
  mock_app { get('/') { creole :no_such_template } }
29
- assert_raise(Errno::ENOENT) { get('/') }
29
+ assert_raises(Errno::ENOENT) { get('/') }
30
30
  end
31
31
 
32
32
  it "renders with inline layouts" do
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../helper', __FILE__)
2
2
 
3
- class DelegatorTest < Test::Unit::TestCase
3
+ class DelegatorTest < Minitest::Test
4
4
  class Mirror
5
5
  attr_reader :last_call
6
6
  def method_missing(*a, &b)
@@ -2,7 +2,7 @@
2
2
  require File.expand_path('../helper', __FILE__)
3
3
  require 'erb'
4
4
 
5
- class BaseTest < Test::Unit::TestCase
5
+ class BaseTest < Minitest::Test
6
6
  setup do
7
7
  @base = Sinatra.new(Sinatra::Base)
8
8
  @base.set :views, File.dirname(__FILE__) + "/views"
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../helper', __FILE__)
2
2
 
3
- class ERBTest < Test::Unit::TestCase
3
+ class ERBTest < Minitest::Test
4
4
  def engine
5
5
  Tilt::ERBTemplate
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../helper', __FILE__)
2
2
 
3
- class ExtensionsTest < Test::Unit::TestCase
3
+ class ExtensionsTest < Minitest::Test
4
4
  module FooExtensions
5
5
  def foo
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../helper', __FILE__)
2
2
 
3
- class BeforeFilterTest < Test::Unit::TestCase
3
+ class BeforeFilterTest < Minitest::Test
4
4
  it "executes filters in the order defined" do
5
5
  count = 0
6
6
  mock_app do
@@ -176,7 +176,7 @@ class BeforeFilterTest < Test::Unit::TestCase
176
176
  end
177
177
  end
178
178
 
179
- class AfterFilterTest < Test::Unit::TestCase
179
+ class AfterFilterTest < Minitest::Test
180
180
  it "executes before and after filters in correct order" do
181
181
  invoked = 0
182
182
  mock_app do
@@ -3,7 +3,7 @@ require File.expand_path('../helper', __FILE__)
3
3
  begin
4
4
  require 'haml'
5
5
 
6
- class HAMLTest < Test::Unit::TestCase
6
+ class HAMLTest < Minitest::Test
7
7
  def haml_app(&block)
8
8
  mock_app do
9
9
  set :views, File.dirname(__FILE__) + '/views'
@@ -42,7 +42,7 @@ class HAMLTest < Test::Unit::TestCase
42
42
 
43
43
  it "raises error if template not found" do
44
44
  mock_app { get('/') { haml :no_such_template } }
45
- assert_raise(Errno::ENOENT) { get('/') }
45
+ assert_raises(Errno::ENOENT) { get('/') }
46
46
  end
47
47
 
48
48
  it "passes HAML options to the Haml engine" do
@@ -16,13 +16,19 @@ $LOAD_PATH.unshift testdir unless $LOAD_PATH.include?(testdir)
16
16
  libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
17
17
  $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
18
18
 
19
+ require 'minitest'
19
20
  require 'contest'
20
21
  require 'rack/test'
21
22
  require 'sinatra/base'
22
23
 
23
24
  class Sinatra::Base
25
+ include Minitest::Assertions
24
26
  # Allow assertions in request context
25
- include Test::Unit::Assertions
27
+ def assertions
28
+ @assertions ||= 0
29
+ end
30
+
31
+ attr_writer :assertions
26
32
  end
27
33
 
28
34
  class Rack::Builder
@@ -33,7 +39,7 @@ end
33
39
 
34
40
  Sinatra::Base.set :environment, :test
35
41
 
36
- class Test::Unit::TestCase
42
+ class Minitest::Test
37
43
  include Rack::Test::Methods
38
44
 
39
45
  class << self
@@ -116,11 +122,6 @@ class Test::Unit::TestCase
116
122
  super
117
123
  end
118
124
 
119
- # Also check response since we delegate there.
120
- def respond_to?(symbol, include_private=false)
121
- super || (response && response.respond_to?(symbol, include_private))
122
- end
123
-
124
125
  # Do not output warnings for the duration of the block.
125
126
  def silence_warnings
126
127
  $VERBOSE, v = nil, $VERBOSE
@@ -2,7 +2,7 @@ require File.expand_path('../helper', __FILE__)
2
2
  require 'date'
3
3
  require 'json'
4
4
 
5
- class HelpersTest < Test::Unit::TestCase
5
+ class HelpersTest < Minitest::Test
6
6
  def test_default
7
7
  assert true
8
8
  end
@@ -647,7 +647,7 @@ class HelpersTest < Test::Unit::TestCase
647
647
  end
648
648
  end
649
649
 
650
- assert_raise(RuntimeError) { get '/foo.xml' }
650
+ assert_raises(RuntimeError) { get '/foo.xml' }
651
651
  end
652
652
 
653
653
  it 'only sets default charset for specific mime types' do
@@ -975,12 +975,12 @@ class HelpersTest < Test::Unit::TestCase
975
975
 
976
976
  it 'sets the Expires header' do
977
977
  get '/foo'
978
- assert_not_nil response['Expires']
978
+ refute_nil response['Expires']
979
979
  end
980
980
 
981
981
  it 'allows passing Time.now objects' do
982
982
  get '/bar'
983
- assert_not_nil response['Expires']
983
+ refute_nil response['Expires']
984
984
  end
985
985
 
986
986
  it 'allows passing Time.at objects' do
@@ -994,7 +994,7 @@ class HelpersTest < Test::Unit::TestCase
994
994
  end
995
995
 
996
996
  it 'fails when Time.parse raises an ArgumentError' do
997
- assert_raise(ArgumentError) { get '/boom' }
997
+ assert_raises(ArgumentError) { get '/boom' }
998
998
  end
999
999
  end
1000
1000
 
@@ -1763,7 +1763,7 @@ class HelpersTest < Test::Unit::TestCase
1763
1763
  "that's weak, dude."
1764
1764
  end
1765
1765
  end
1766
- assert_raise(ArgumentError) { get('/') }
1766
+ assert_raises(ArgumentError) { get('/') }
1767
1767
  end
1768
1768
  end
1769
1769