sinatra-sinatra 0.9.1.1 → 0.9.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,3 +1,11 @@
1
+ = 0.9.2 / unreleased
2
+
3
+ * Development mode source file reloading has been removed. The
4
+ "shotgun" (http://rtomayko.github.com/shotgun/) program can be
5
+ used to achieve the same basic functionality in most situations.
6
+ Passenger users should use the "tmp/always_restart.txt"
7
+ file (http://tinyurl.com/c67o4h). [#166]
8
+
1
9
  = 0.9.1.1 / 2009-03-09
2
10
 
3
11
  * Fix directory traversal vulnerability in default static files
data/README.rdoc CHANGED
@@ -285,13 +285,7 @@ A route can punt processing to the next matching route using <tt>pass</tt>:
285
285
  The route block is immediately exited and control continues with the next
286
286
  matching route. If no matching route is found, a 404 is returned.
287
287
 
288
- == Configuration and Reloading
289
-
290
- Sinatra supports multiple environments and reloading. Reloading happens
291
- before each request when running under the <tt>:development</tt>
292
- environment. Wrap your configurations (e.g., database connections, constants,
293
- etc.) in <tt>configure</tt> blocks to protect them from reloading or to
294
- target specific environments.
288
+ == Configuration
295
289
 
296
290
  Run once, at startup, in any environment:
297
291
 
@@ -300,14 +294,14 @@ Run once, at startup, in any environment:
300
294
  end
301
295
 
302
296
  Run only when the environment (RACK_ENV environment variable) is set to
303
- <tt>:production</tt>.
297
+ <tt>:production</tt>:
304
298
 
305
299
  configure :production do
306
300
  ...
307
301
  end
308
302
 
309
- Run when the environment (RACK_ENV environment variable) is set to
310
- either <tt>:production</tt> or <tt>:test</tt>.
303
+ Run when the environment is set to either <tt>:production</tt> or
304
+ <tt>:test</tt>:
311
305
 
312
306
  configure :production, :test do
313
307
  ...
data/Rakefile CHANGED
@@ -33,7 +33,7 @@ def spec
33
33
  end
34
34
 
35
35
  def package(ext='')
36
- "dist/sinatra-#{spec.version}" + ext
36
+ "pkg/sinatra-#{spec.version}" + ext
37
37
  end
38
38
 
39
39
  desc 'Build packages'
@@ -44,15 +44,15 @@ task :install => package('.gem') do
44
44
  sh "gem install #{package('.gem')}"
45
45
  end
46
46
 
47
- directory 'dist/'
48
- CLOBBER.include('dist')
47
+ directory 'pkg/'
48
+ CLOBBER.include('pkg')
49
49
 
50
- file package('.gem') => %w[dist/ sinatra.gemspec] + spec.files do |f|
50
+ file package('.gem') => %w[pkg/ sinatra.gemspec] + spec.files do |f|
51
51
  sh "gem build sinatra.gemspec"
52
52
  mv File.basename(f.name), f.name
53
53
  end
54
54
 
55
- file package('.tar.gz') => %w[dist/] + spec.files do |f|
55
+ file package('.tar.gz') => %w[pkg/] + spec.files do |f|
56
56
  sh <<-SH
57
57
  git archive \
58
58
  --prefix=sinatra-#{source_version}/ \
@@ -64,7 +64,7 @@ end
64
64
  # Rubyforge Release / Publish Tasks ==================================
65
65
 
66
66
  desc 'Publish gem and tarball to rubyforge'
67
- task 'publish:gem' => [package('.gem'), package('.tar.gz')] do |t|
67
+ task 'release' => [package('.gem'), package('.tar.gz')] do |t|
68
68
  sh <<-end
69
69
  rubyforge add_release sinatra sinatra #{spec.version} #{package('.gem')} &&
70
70
  rubyforge add_file sinatra sinatra #{spec.version} #{package('.tar.gz')}
@@ -95,12 +95,6 @@ file 'doc/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f|
95
95
  end
96
96
  CLEAN.include 'doc/api'
97
97
 
98
- def rdoc_to_html(file_name)
99
- require 'rdoc/markup/to_html'
100
- rdoc = RDoc::Markup::ToHtml.new
101
- rdoc.convert(File.read(file_name))
102
- end
103
-
104
98
  # Gemspec Helpers ====================================================
105
99
 
106
100
  def source_version
@@ -108,12 +102,7 @@ def source_version
108
102
  line.match(/.*VERSION = '(.*)'/)[1]
109
103
  end
110
104
 
111
- project_files =
112
- FileList[
113
- '{lib,test,compat,images}/**',
114
- 'Rakefile', 'CHANGES', 'README.rdoc'
115
- ]
116
- file 'sinatra.gemspec' => project_files do |f|
105
+ task 'sinatra.gemspec' => FileList['{lib,test,compat}/**','Rakefile','CHANGES','*.rdoc'] do |f|
117
106
  # read spec file and split out manifest section
118
107
  spec = File.read(f.name)
119
108
  head, manifest, tail = spec.split(" # = MANIFEST =\n")
data/lib/sinatra/base.rb CHANGED
@@ -14,6 +14,7 @@ module Sinatra
14
14
  @env['HTTP_USER_AGENT']
15
15
  end
16
16
 
17
+ # Returns an array of acceptable media types for the response
17
18
  def accept
18
19
  @env['HTTP_ACCEPT'].to_s.split(',').map { |a| a.strip }
19
20
  end
@@ -162,6 +163,8 @@ module Sinatra
162
163
  not_found
163
164
  end
164
165
 
166
+ # Rack response body used to deliver static files. The file contents are
167
+ # generated iteratively in 8K chunks.
165
168
  class StaticFile < ::File #:nodoc:
166
169
  alias_method :to_path, :path
167
170
  def each
@@ -215,7 +218,18 @@ module Sinatra
215
218
  end
216
219
 
217
220
  # Template rendering methods. Each method takes a the name of a template
218
- # to render as a Symbol and returns a String with the rendered output.
221
+ # to render as a Symbol and returns a String with the rendered output,
222
+ # as well as an optional hash with additional options.
223
+ #
224
+ # `template` is either the name or path of the template as symbol
225
+ # (Use `:'subdir/myview'` for views in subdirectories), or a string
226
+ # that will be rendered.
227
+ #
228
+ # Possible options are:
229
+ # :layout If set to false, no layout is rendered, otherwise
230
+ # the specified layout is used (Ignored for `sass`)
231
+ # :locals A hash with local variables that should be available
232
+ # in the template
219
233
  module Templates
220
234
  def erb(template, options={})
221
235
  require 'erb' unless defined? ::ERB
@@ -223,13 +237,13 @@ module Sinatra
223
237
  end
224
238
 
225
239
  def haml(template, options={})
226
- require 'haml' unless defined? ::Haml
240
+ require 'haml' unless defined? ::Haml::Engine
227
241
  options[:options] ||= self.class.haml if self.class.respond_to? :haml
228
242
  render :haml, template, options
229
243
  end
230
244
 
231
245
  def sass(template, options={}, &block)
232
- require 'sass' unless defined? ::Sass
246
+ require 'sass' unless defined? ::Sass::Engine
233
247
  options[:layout] = false
234
248
  render :sass, template, options
235
249
  end
@@ -368,13 +382,16 @@ module Sinatra
368
382
  self.class
369
383
  end
370
384
 
371
- # Exit the current block and halt the response.
385
+ # Exit the current block, halts any further processing
386
+ # of the request, and returns the specified response.
372
387
  def halt(*response)
373
388
  response = response.first if response.length == 1
374
389
  throw :halt, response
375
390
  end
376
391
 
377
392
  # Pass control to the next matching route.
393
+ # If there are no more matching routes, Sinatra will
394
+ # return a 404 response.
378
395
  def pass
379
396
  throw :pass
380
397
  end
@@ -435,6 +452,9 @@ module Sinatra
435
452
  # No matching route found or all routes passed -- forward downstream
436
453
  # when running as middleware; 404 when running as normal app.
437
454
  if @app
455
+ # Call bypassed method before forward to catch behavior that should
456
+ # happen even if no routes are hit.
457
+ bypassed if respond_to?(:bypassed)
438
458
  forward
439
459
  else
440
460
  raise NotFound
@@ -553,12 +573,14 @@ module Sinatra
553
573
  @middleware = []
554
574
  @errors = {}
555
575
  @prototype = nil
576
+ @extensions = []
556
577
 
557
578
  class << self
558
579
  attr_accessor :routes, :filters, :conditions, :templates,
559
580
  :middleware, :errors
560
581
 
561
- public
582
+ # Sets an option to the given value. If the value is a proc,
583
+ # the proc will be called every time the option is accessed.
562
584
  def set(option, value=self)
563
585
  if value.kind_of?(Proc)
564
586
  metadef(option, &value)
@@ -574,14 +596,19 @@ module Sinatra
574
596
  self
575
597
  end
576
598
 
599
+ # Same as calling `set :option, true` for each of the given options.
577
600
  def enable(*opts)
578
601
  opts.each { |key| set(key, true) }
579
602
  end
580
603
 
604
+ # Same as calling `set :option, false` for each of the given options.
581
605
  def disable(*opts)
582
606
  opts.each { |key| set(key, false) }
583
607
  end
584
608
 
609
+ # Define a custom error handler. Optionally takes either an Exception
610
+ # class, or an HTTP status code to specify which errors should be
611
+ # handled.
585
612
  def error(codes=Exception, &block)
586
613
  if codes.respond_to? :each
587
614
  codes.each { |err| error(err, &block) }
@@ -590,23 +617,25 @@ module Sinatra
590
617
  end
591
618
  end
592
619
 
620
+ # Sugar for `error(404) { ... }`
593
621
  def not_found(&block)
594
622
  error 404, &block
595
623
  end
596
624
 
625
+ # Define a named template. The block must return the template source.
597
626
  def template(name, &block)
598
627
  templates[name] = block
599
628
  end
600
629
 
630
+ # Define the layout template. The block must return the template source.
601
631
  def layout(name=:layout, &block)
602
632
  template name, &block
603
633
  end
604
634
 
605
- def use_in_file_templates!
606
- ignore = [/lib\/sinatra.*\.rb/, /\(.*\)/, /rubygems\/custom_require\.rb/]
607
- file = caller.
608
- map { |line| line.sub(/:\d+.*$/, '') }.
609
- find { |line| ignore.all? { |pattern| line !~ pattern } }
635
+ # Load embeded templates from the file; uses the caller's __FILE__
636
+ # when no file is specified.
637
+ def use_in_file_templates!(file=nil)
638
+ file ||= caller_files.first
610
639
  if data = ::IO.read(file).split('__END__')[1]
611
640
  data.gsub!(/\r\n/, "\n")
612
641
  template = nil
@@ -627,10 +656,15 @@ module Sinatra
627
656
  Rack::Mime.mime_type(type, nil)
628
657
  end
629
658
 
659
+ # Define a before filter. Filters are run before all requests
660
+ # within the same context as route handlers and may access/modify the
661
+ # request and response.
630
662
  def before(&block)
631
663
  @filters << block
632
664
  end
633
665
 
666
+ # Add a route condition. The route is considered non-matching when the
667
+ # block returns false.
634
668
  def condition(&block)
635
669
  @conditions << block
636
670
  end
@@ -667,6 +701,8 @@ module Sinatra
667
701
  end
668
702
 
669
703
  public
704
+ # Defining a `GET` handler also automatically defines
705
+ # a `HEAD` handler.
670
706
  def get(path, opts={}, &block)
671
707
  conditions = @conditions.dup
672
708
  route('GET', path, opts, &block)
@@ -698,10 +734,16 @@ module Sinatra
698
734
  lambda { unbound_method.bind(self).call }
699
735
  end
700
736
 
737
+ invoke_hook(:route_added, verb, path)
738
+
701
739
  (routes[verb] ||= []).
702
740
  push([pattern, keys, conditions, block]).last
703
741
  end
704
742
 
743
+ def invoke_hook(name, *args)
744
+ extensions.each { |e| e.send(name, *args) if e.respond_to?(name) }
745
+ end
746
+
705
747
  def compile(path)
706
748
  keys = []
707
749
  if path.respond_to? :to_str
@@ -728,13 +770,20 @@ module Sinatra
728
770
  end
729
771
 
730
772
  public
773
+ # Makes the methods defined in the block and in the Modules given
774
+ # in `extensions` available to the handlers and templates
731
775
  def helpers(*extensions, &block)
732
776
  class_eval(&block) if block_given?
733
777
  include *extensions if extensions.any?
734
778
  end
735
779
 
780
+ def extensions
781
+ (@extensions + (superclass.extensions rescue [])).uniq
782
+ end
783
+
736
784
  def register(*extensions, &block)
737
785
  extensions << Module.new(&block) if block_given?
786
+ @extensions += extensions
738
787
  extensions.each do |extension|
739
788
  extend extension
740
789
  extension.registered(self) if extension.respond_to?(:registered)
@@ -745,16 +794,20 @@ module Sinatra
745
794
  def test? ; environment == :test ; end
746
795
  def production? ; environment == :production ; end
747
796
 
797
+ # Set configuration options for Sinatra and/or the app.
798
+ # Allows scoping of settings for certain environments.
748
799
  def configure(*envs, &block)
749
- return if reloading?
750
800
  yield if envs.empty? || envs.include?(environment.to_sym)
751
801
  end
752
802
 
803
+ # Use the specified Rack middleware
753
804
  def use(middleware, *args, &block)
754
805
  @prototype = nil
755
806
  @middleware << [middleware, args, block]
756
807
  end
757
808
 
809
+ # Run the Sinatra app as a self-hosted server using
810
+ # Thin, Mongrel or WEBrick (in that order)
758
811
  def run!(options={})
759
812
  set options
760
813
  handler = detect_rack_handler
@@ -785,28 +838,13 @@ module Sinatra
785
838
  builder.use Rack::Session::Cookie if sessions? && !test?
786
839
  builder.use Rack::CommonLogger if logging?
787
840
  builder.use Rack::MethodOverride if methodoverride?
788
- @middleware.each { |c, args, bk| builder.use(c, *args, &bk) }
841
+ @middleware.each { |c,a,b| builder.use(c, *a, &b) }
789
842
  builder.run super
790
843
  builder.to_app
791
844
  end
792
845
 
793
846
  def call(env)
794
- synchronize do
795
- reload! if reload?
796
- prototype.call(env)
797
- end
798
- end
799
-
800
- def reloading?
801
- @reloading
802
- end
803
-
804
- def reload!
805
- @reloading = true
806
- reset!
807
- $LOADED_FEATURES.delete("sinatra.rb")
808
- ::Kernel.load app_file
809
- @reloading = false
847
+ synchronize { prototype.call(env) }
810
848
  end
811
849
 
812
850
  def reset!(base=superclass)
@@ -817,6 +855,7 @@ module Sinatra
817
855
  @errors = base.errors.dup
818
856
  @middleware = base.middleware.dup
819
857
  @prototype = nil
858
+ @extensions = []
820
859
  end
821
860
 
822
861
  protected
@@ -858,6 +897,20 @@ module Sinatra
858
897
  (class << self; self; end).
859
898
  send :define_method, message, &block
860
899
  end
900
+
901
+ # Like Kernel#caller but excluding certain magic entries and without
902
+ # line / method information; the resulting array contains filenames only.
903
+ def caller_files
904
+ ignore = [
905
+ /lib\/sinatra.*\.rb$/, # all sinatra code
906
+ /\(.*\)/, # generated code
907
+ /custom_require\.rb$/, # rubygems require hacks
908
+ /active_support/, # active_support require hacks
909
+ ]
910
+ caller(1).
911
+ map { |line| line.split(/:\d/, 2).first }.
912
+ reject { |file| ignore.any? { |pattern| file =~ pattern } }
913
+ end
861
914
  end
862
915
 
863
916
  set :raise_errors, true
@@ -878,8 +931,7 @@ module Sinatra
878
931
  set :root, Proc.new { app_file && File.expand_path(File.dirname(app_file)) }
879
932
  set :views, Proc.new { root && File.join(root, 'views') }
880
933
  set :public, Proc.new { root && File.join(root, 'public') }
881
- set :reload, Proc.new { app_file? && app_file !~ /\.ru$/i && development? }
882
- set :lock, Proc.new { reload? }
934
+ set :lock, false
883
935
 
884
936
  # static files route
885
937
  get(/.*[^\/]$/) do
@@ -980,14 +1032,17 @@ module Sinatra
980
1032
  class Application < Default
981
1033
  end
982
1034
 
1035
+ # Sinatra delegation mixin. Mixing this module into an object causes all
1036
+ # methods to be delegated to the Sinatra::Application class. Used primarily
1037
+ # at the top-level.
983
1038
  module Delegator #:nodoc:
984
1039
  def self.delegate(*methods)
985
1040
  methods.each do |method_name|
986
1041
  eval <<-RUBY, binding, '(__DELEGATE__)', 1
987
1042
  def #{method_name}(*args, &b)
988
- ::Sinatra::Application.#{method_name}(*args, &b)
1043
+ ::Sinatra::Application.send(#{method_name.inspect}, *args, &b)
989
1044
  end
990
- private :#{method_name}
1045
+ private #{method_name.inspect}
991
1046
  RUBY
992
1047
  end
993
1048
  end
@@ -998,6 +1053,8 @@ module Sinatra
998
1053
  :production?, :use_in_file_templates!, :helpers
999
1054
  end
1000
1055
 
1056
+ # Create a new Sinatra application. The block is evaluated in the new app's
1057
+ # class scope.
1001
1058
  def self.new(base=Base, options={}, &block)
1002
1059
  base = Class.new(base)
1003
1060
  base.send :class_eval, &block if block_given?
data/lib/sinatra/main.rb CHANGED
@@ -6,26 +6,14 @@ module Sinatra
6
6
  # we assume that the first file that requires 'sinatra' is the
7
7
  # app_file. all other path related options are calculated based
8
8
  # on this path by default.
9
- set :app_file, lambda {
10
- ignore = [
11
- /lib\/sinatra.*\.rb$/, # all sinatra code
12
- /\(.*\)/, # generated code
13
- /custom_require\.rb$/ # rubygems require hacks
14
- ]
15
- path =
16
- caller.map{ |line| line.split(/:\d/, 2).first }.find do |file|
17
- next if ignore.any? { |pattern| file =~ pattern }
18
- file
19
- end
20
- path || $0
21
- }.call
9
+ set :app_file, caller_files.first || $0
22
10
 
23
11
  set :run, Proc.new { $0 == app_file }
24
12
 
25
13
  if run? && ARGV.any?
26
14
  require 'optparse'
27
15
  OptionParser.new { |op|
28
- op.on('-x') { set :mutex, true }
16
+ op.on('-x') { set :lock, true }
29
17
  op.on('-e env') { |val| set :environment, val.to_sym }
30
18
  op.on('-s server') { |val| set :server, val }
31
19
  op.on('-p port') { |val| set :port, val.to_i }
data/sinatra.gemspec CHANGED
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
3
3
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
4
 
5
5
  s.name = 'sinatra'
6
- s.version = '0.9.1.1'
7
- s.date = '2009-03-09'
6
+ s.version = '0.9.1.2'
7
+ s.date = '2009-03-24'
8
8
 
9
9
  s.description = "Classy web-development dressed in a DSL"
10
10
  s.summary = "Classy web-development dressed in a DSL"
@@ -78,7 +78,6 @@ Gem::Specification.new do |s|
78
78
  test/mapped_error_test.rb
79
79
  test/middleware_test.rb
80
80
  test/options_test.rb
81
- test/reload_test.rb
82
81
  test/request_test.rb
83
82
  test/response_test.rb
84
83
  test/result_test.rb
@@ -104,7 +103,8 @@ Gem::Specification.new do |s|
104
103
  s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
105
104
 
106
105
  s.extra_rdoc_files = %w[README.rdoc LICENSE]
107
- s.add_dependency 'rack', '>= 0.9.1', '< 1.0'
106
+ s.add_dependency 'rack', '>= 0.9.1', '< 1.0'
107
+ s.add_development_dependency 'shotgun', '>= 0.2', '< 1.0'
108
108
 
109
109
  s.has_rdoc = true
110
110
  s.homepage = "http://sinatra.rubyforge.org"
data/test/base_test.rb CHANGED
@@ -42,7 +42,7 @@ end
42
42
  describe "Sinatra::Base as Rack middleware" do
43
43
 
44
44
  app = lambda { |env|
45
- [210, {'X-Downstream' => 'true'}, ['Hello from downstream']] }
45
+ [210, {'X-Downstream' => 'true', 'X-Bypass-Test' => '1' || ''}, ['Hello from downstream']] }
46
46
 
47
47
  class TestMiddleware < Sinatra::Base
48
48
  end
@@ -58,6 +58,10 @@ describe "Sinatra::Base as Rack middleware" do
58
58
  end
59
59
 
60
60
  class TestMiddleware < Sinatra::Base
61
+ def bypassed
62
+ env['X-Bypass-Test'] = '1'
63
+ end
64
+
61
65
  get '/' do
62
66
  'Hello from middleware'
63
67
  end
@@ -78,6 +82,11 @@ describe "Sinatra::Base as Rack middleware" do
78
82
  assert_equal 'Hello from downstream', response.body
79
83
  end
80
84
 
85
+ it 'calls #bypassed before forwarding downstream' do
86
+ response = request.get('/missing')
87
+ assert_equal '1', response['X-Bypass-Test']
88
+ end
89
+
81
90
  class TestMiddleware < Sinatra::Base
82
91
  get '/low-level-forward' do
83
92
  app.call(env)
@@ -25,6 +25,12 @@ describe 'Registering extensions' do
25
25
  end
26
26
  end
27
27
 
28
+ module PainExtensions
29
+ def foo=(name); end
30
+ def bar?(name); end
31
+ def fizz!(name); end
32
+ end
33
+
28
34
  it 'will add the methods to the DSL for the class in which you register them and its subclasses' do
29
35
  Sinatra::Base.register FooExtensions
30
36
  assert Sinatra::Base.respond_to?(:foo)
@@ -50,6 +56,16 @@ describe 'Registering extensions' do
50
56
  map { |m| m.to_sym }.include?(:im_hiding_in_ur_foos)
51
57
  end
52
58
 
59
+ it 'will handle special method names' do
60
+ Sinatra::Default.register PainExtensions
61
+ assert Sinatra::Delegator.private_instance_methods.
62
+ map { |m| m.to_sym }.include?(:foo=)
63
+ assert Sinatra::Delegator.private_instance_methods.
64
+ map { |m| m.to_sym }.include?(:bar?)
65
+ assert Sinatra::Delegator.private_instance_methods.
66
+ map { |m| m.to_sym }.include?(:fizz!)
67
+ end
68
+
53
69
  it 'will not delegate methods on Base#register' do
54
70
  Sinatra::Base.register QuuxExtensions
55
71
  assert !Sinatra::Delegator.private_instance_methods.include?("quux")
data/test/options_test.rb CHANGED
@@ -319,56 +319,8 @@ describe_option 'public' do
319
319
  end
320
320
  end
321
321
 
322
- describe_option 'reload' do
323
- it 'is enabled when
324
- app_file is set,
325
- is not a rackup file,
326
- and we are in development' do
327
- @base.app_file = __FILE__
328
- @base.set(:environment, :development)
329
- assert @base.reload?
330
-
331
- @default.app_file = __FILE__
332
- @default.set(:environment, :development)
333
- assert @default.reload?
334
- end
335
-
336
- it 'is disabled if app_file is not set' do
337
- assert ! @base.reload?
338
- assert ! @default.reload?
339
- end
340
-
341
- it 'is disabled if app_file is a rackup file' do
342
- @base.app_file = 'config.ru'
343
- assert ! @base.reload?
344
-
345
- @default.app_file = 'config.ru'
346
- assert ! @base.reload?
347
- end
348
-
349
- it 'is disabled if we are not in development' do
350
- @base.set(:environment, :foo)
351
- assert ! @base.reload
352
-
353
- @default.set(:environment, :bar)
354
- assert ! @default.reload
355
- end
356
- end
357
-
358
322
  describe_option 'lock' do
359
- it 'is enabled when reload is enabled' do
360
- @base.enable(:reload)
361
- assert @base.lock?
362
-
363
- @default.enable(:reload)
364
- assert @default.lock?
365
- end
366
-
367
- it 'is disabled when reload is disabled' do
368
- @base.disable(:reload)
323
+ it 'is disabled by default' do
369
324
  assert ! @base.lock?
370
-
371
- @default.disable(:reload)
372
- assert ! @default.lock?
373
325
  end
374
326
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1.1
4
+ version: 0.9.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Mizerany
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-09 00:00:00 -07:00
12
+ date: 2009-03-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -25,6 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: "1.0"
27
27
  version:
28
+ - !ruby/object:Gem::Dependency
29
+ name: shotgun
30
+ type: :development
31
+ version_requirement:
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: "0.2"
37
+ - - <
38
+ - !ruby/object:Gem::Version
39
+ version: "1.0"
40
+ version:
28
41
  description: Classy web-development dressed in a DSL
29
42
  email: sinatrarb@googlegroups.com
30
43
  executables: []
@@ -99,7 +112,6 @@ files:
99
112
  - test/mapped_error_test.rb
100
113
  - test/middleware_test.rb
101
114
  - test/options_test.rb
102
- - test/reload_test.rb
103
115
  - test/request_test.rb
104
116
  - test/response_test.rb
105
117
  - test/result_test.rb
@@ -161,7 +173,6 @@ test_files:
161
173
  - test/mapped_error_test.rb
162
174
  - test/middleware_test.rb
163
175
  - test/options_test.rb
164
- - test/reload_test.rb
165
176
  - test/request_test.rb
166
177
  - test/response_test.rb
167
178
  - test/result_test.rb
data/test/reload_test.rb DELETED
@@ -1,68 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- $reload_count = 0
4
- $reload_app = nil
5
-
6
- describe "Reloading" do
7
- before {
8
- @app = mock_app(Sinatra::Default)
9
- $reload_app = @app
10
- }
11
-
12
- after {
13
- $reload_app = nil
14
- }
15
-
16
- it 'is enabled by default when in development and the app_file is set' do
17
- @app.set :app_file, __FILE__
18
- @app.set :environment, :development
19
- assert_same true, @app.reload
20
- assert_same true, @app.reload?
21
- end
22
-
23
- it 'is disabled by default when running in non-development environment' do
24
- @app.set :app_file, __FILE__
25
- @app.set :environment, :test
26
- assert !@app.reload
27
- assert_same false, @app.reload?
28
- end
29
-
30
- it 'is disabled by default when no app_file is available' do
31
- @app.set :app_file, nil
32
- @app.set :environment, :development
33
- assert !@app.reload
34
- assert_same false, @app.reload?
35
- end
36
-
37
- it 'is disabled when app_file is a rackup (.ru) file' do
38
- @app.set :app_file, __FILE__.sub(/\.rb$/, '.ru')
39
- @app.set :environment, :development
40
- assert !@app.reload
41
- assert_same false, @app.reload?
42
- end
43
-
44
- it 'can be turned off explicitly' do
45
- @app.set :app_file, __FILE__
46
- @app.set :environment, :development
47
- assert_same true, @app.reload
48
- @app.set :reload, false
49
- assert_same false, @app.reload
50
- assert_same false, @app.reload?
51
- end
52
-
53
- it 'reloads the app_file each time a request is made' do
54
- @app.set :app_file, File.dirname(__FILE__) + '/data/reload_app_file.rb'
55
- @app.set :reload, true
56
- @app.get('/') { 'Hello World' }
57
-
58
- get '/'
59
- assert_equal 200, status
60
- assert_equal 'Hello from reload file', body
61
- assert_equal 1, $reload_count
62
-
63
- get '/'
64
- assert_equal 200, status
65
- assert_equal 'Hello from reload file', body
66
- assert_equal 2, $reload_count
67
- end
68
- end