diff -Nru ruby-sinatra-contrib-1.3.2/README.md ruby-sinatra-contrib-1.4.1/README.md --- ruby-sinatra-contrib-1.3.2/README.md 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/README.md 2013-08-29 10:22:25.000000000 +0000 @@ -1,3 +1,5 @@ +[![Build Status](https://secure.travis-ci.org/sinatra/sinatra-contrib.png)](http://travis-ci.org/sinatra/sinatra-contrib) + Collection of common Sinatra extensions, semi-officially supported. # Goals @@ -6,13 +8,6 @@ * High code quality, high test coverage * Include plugins people usually ask for a lot -# TODO - -* Write documentation, integrate into Sinatra website -* Finish imports and rewrites -* Wrap up first release -* Find contributors (both code and docs) - # Included extensions ## Common Extensions @@ -46,7 +41,7 @@ * `sinatra/namespace`: Adds namespace support to Sinatra. -* `sinatra/respond_with`: Choose action and/or template depending automatically +* `sinatra/respond_with`: Choose action and/or template automatically depending on the incoming request. Adds helpers `respond_to` and `respond_with`. @@ -70,6 +65,12 @@ * `sinatra/test_helpers`: Helper methods to ease testing your Sinatra application. Partly extracted from Sinatra. Testing framework agnostic +# Installation +Add `gem 'sinatra-contrib'` to *Gemfile*, then execute `bundle install`. + +If you don't use Bundler, install the gem manually by executing `gem install sinatra-contrib` in your command line. + + # Usage ## Classic Style @@ -133,3 +134,8 @@ register Sinatra::Contrib end ``` + +## Documentation + +For more info check the [official docs](http://www.sinatrarb.com/contrib/) and +[api docs](http://rubydoc.info/gems/sinatra-contrib/1.4.0/frames). diff -Nru ruby-sinatra-contrib-1.3.2/Rakefile ruby-sinatra-contrib-1.4.1/Rakefile --- ruby-sinatra-contrib-1.3.2/Rakefile 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/Rakefile 2013-08-29 10:22:25.000000000 +0000 @@ -44,7 +44,6 @@ content.sub!(/ s\.#{field} = \[\n( .*\n)* \]/, updated) end - content.sub! /(s\.version.*=\s+).*/, "\\1\"#{Sinatra::Contrib::VERSION}\"" File.open('sinatra-contrib.gemspec', 'w') { |f| f << content } end Binary files /tmp/8BsObkPiv2/ruby-sinatra-contrib-1.3.2/checksums.yaml.gz and /tmp/23xyk5kCYc/ruby-sinatra-contrib-1.4.1/checksums.yaml.gz differ diff -Nru ruby-sinatra-contrib-1.3.2/debian/changelog ruby-sinatra-contrib-1.4.1/debian/changelog --- ruby-sinatra-contrib-1.3.2/debian/changelog 2013-04-19 10:16:22.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/debian/changelog 2013-08-29 10:33:04.000000000 +0000 @@ -1,3 +1,10 @@ +ruby-sinatra-contrib (1.4.1-1) unstable; urgency=low + + * New upstream version. (Closes: #713163) + * Update Depends and Build-Depends. + + -- Jérémy Bobbio Thu, 29 Aug 2013 12:26:56 +0200 + ruby-sinatra-contrib (1.3.2-1) unstable; urgency=low * Initial release (Closes: #703068) diff -Nru ruby-sinatra-contrib-1.3.2/debian/control ruby-sinatra-contrib-1.4.1/debian/control --- ruby-sinatra-contrib-1.3.2/debian/control 2013-04-19 10:16:22.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/debian/control 2013-08-29 10:33:04.000000000 +0000 @@ -3,17 +3,17 @@ Priority: optional Maintainer: Debian Ruby Extras Maintainers Uploaders: Eugene Lavnikevich , Jérémy Bobbio -Build-Depends: debhelper (>= 7.0.50~), gem2deb (>= 0.3.0~), ruby-sinatra (>= 1.3.0~), ruby-backports (>= 2.0~), ruby-tilt (>= 1.3~), ruby-rack-test, ruby-rack-protection, ruby-eventmachine, ruby-rspec (>= 2.3~), ruby-haml, ruby-erubis, ruby-slim, rake, ruby-yajl, ruby-json +Build-Depends: debhelper (>= 7.0.50~), gem2deb (>= 0.3.0~), ruby-sinatra (>= 1.4.2~), ruby-backports (>= 2.0~), ruby-tilt (>= 1.3~), ruby-rack-test, ruby-rack-protection, ruby-multi-json, ruby-rspec (>= 2.3~), ruby-haml, ruby-erubis, ruby-slim, rake, ruby-json, ruby-yajl Standards-Version: 3.9.4 -Vcs-Git: git://git.debian.org/pkg-ruby-extras/ruby-sinatra-contrib.git -Vcs-Browser: http://git.debian.org/?p=pkg-ruby-extras/ruby-sinatra-contrib.git;a=summary +Vcs-Git: git://anonscm.debian.org/pkg-ruby-extras/ruby-sinatra-contrib.git +Vcs-Browser: http://anonscm.debian.org/gitweb?p=pkg-ruby-extras/ruby-sinatra-contrib.git;a=summary Homepage: http://github.com/sinatra/sinatra-contrib XS-Ruby-Versions: all Package: ruby-sinatra-contrib Architecture: all XB-Ruby-Versions: ${ruby:Versions} -Depends: ${shlibs:Depends}, ${misc:Depends}, ruby | ruby-interpreter, ruby-sinatra (>= 1.3.0~), ruby-backports (>= 2.0~), ruby-tilt (>= 1.3~), ruby-rack-test, ruby-rack-protection, ruby-eventmachine +Depends: ${shlibs:Depends}, ${misc:Depends}, ruby | ruby-interpreter, ruby-sinatra (>= 1.4.2~), ruby-backports (>= 2.0~), ruby-tilt (>= 1.3~), ruby-rack-test, ruby-rack-protection, ruby-multi-json Description: collection of useful extensions to the Sinatra web framework sinatra-contrib is a collection of common extensions to the Sinatra web framework, semi-officially supported: diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/capture.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/capture.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/capture.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/capture.rb 2013-08-29 10:22:25.000000000 +0000 @@ -3,21 +3,103 @@ require 'backports' module Sinatra + # + # = Sinatra::Capture + # + # Extension that enables blocks inside other extensions. + # It currently works for erb, slim and haml. + # Enables mixing of different template languages. + # + # Example: + # + # # in hello_world.erb + # + # Say + # <% a = capture do %>World<% end %> + # Hello <%= a %>! + # + # # in hello_world.slim + # + # | Say + # - a = capture do + # | World + # | Hello #{a}! + # + # # in hello_world.haml + # + # Say + # - a = capture do + # World + # Hello #{a.strip}! + # + # + # You can also use nested blocks. + # + # Example + # + # # in hello_world.erb + # + # Say + # <% a = capture do %> + # <% b = capture do %>World<% end %> + # <%= b %>! + # <% end %> + # Hello <%= a.strip %> + # + # + # The main advantage of capture is mixing of different template engines. + # + # Example + # + # # in mix_me_up.slim + # + # - two = capture do + # - erb "<%= 1 + 1 %>" + # | 1 + 1 = #{two} + # + # == Usage + # + # === Classic Application + # + # In a classic application simply require the helpers, and start using them: + # + # require "sinatra" + # require "sinatra/capture" + # + # # The rest of your classic application code goes here... + # + # === Modular Application + # + # In a modular application you need to require the helpers, and then tell + # the application you will use them: + # + # require "sinatra/base" + # require "sinatra/capture" + # + # class MyApp < Sinatra::Base + # helpers Sinatra::Capture + # + # # The rest of your modular application code goes here... + # end + # module Capture include Sinatra::EngineTracking DUMMIES = { - :haml => "!= capture_haml(*args, &block)", - :erb => "<% @capture = yield(*args) %>", - :slim => "== yield(*args)" + :haml => "!= capture_haml(*args, &block)", + :erubis => "<% @capture = yield(*args) %>", + :slim => "== yield(*args)" } - DUMMIES[:erubis] = DUMMIES[:erb] - def capture(*args, &block) @capture = nil if current_engine == :ruby result = block[*args] + elsif current_engine == :erb + @_out_buf, _buf_was = '', @_out_buf + block[*args] + result = eval('@_out_buf', block.binding) + @_out_buf = _buf_was else buffer = eval '_buf if defined?(_buf)', block.binding old_buffer = buffer.dup if buffer diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/config_file.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/config_file.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/config_file.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/config_file.rb 2013-08-29 10:22:25.000000000 +0000 @@ -1,5 +1,6 @@ require 'sinatra/base' require 'yaml' +require 'erb' module Sinatra @@ -10,7 +11,7 @@ # the files contains specific environment settings and it will use the # corresponding to the current one. # - # Within the application you can access those options through +settings+. If + # You can access those options through +settings+ within the application. If # you try to get the value for a setting that hasn't been defined in the # config file for the current environment, you will get whatever it was set # to in the application. @@ -94,10 +95,23 @@ # # Be aware that if you have a different environment, besides development, # test and production, you will also need to adjust the +environments+ - # setting. For instance, when you also have a staging environment: + # setting, otherwise the settings will not load. For instance, when + # you also have a staging environment: # # set :environments, %w{development test production staging} # + # If you wish to provide defaults that may be shared among all the environments, + # this can be done by using one of the existing environments as the default using + # the YAML alias, and then overwriting values in the other environments: + # + # development: &common_settings + # foo: 'foo' + # bar: 'bar' + # + # production: + # <<: *common_settings + # bar: 'baz' # override the default value + # module ConfigFile # When the extension is registered sets the +environments+ setting to the @@ -114,7 +128,9 @@ paths.each do |pattern| Dir.glob(pattern) do |file| $stderr.puts "loading config file '#{file}'" if logging? - yaml = config_for_env(YAML.load_file(file)) || {} + document = IO.read(file) + document = ERB.new(document).result if file.split('.').include?('erb') + yaml = config_for_env(YAML.load(document)) || {} yaml.each_pair do |key, value| for_env = config_for_env(value) set key, for_env unless value and for_env.nil? and respond_to? key diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/content_for.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/content_for.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/content_for.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/content_for.rb 2013-08-29 10:22:25.000000000 +0000 @@ -78,7 +78,7 @@ def content_for(key, &block) content_blocks[key.to_sym] << capture_later(&block) end - + # Check if a block of content with the given key was defined. For # example: # @@ -100,7 +100,7 @@ # <%= yield_content :head %> # # - # Would render everything you declared with content_for + # Would render everything you declared with content_for # :head before closing the tag. # # You can also pass values to the content blocks by passing them diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/contrib/setup.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/contrib/setup.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/contrib/setup.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/contrib/setup.rb 2013-08-29 10:22:25.000000000 +0000 @@ -24,9 +24,9 @@ end def registered(base) - @extensions.each do |meth, list| + @extensions.each do |method, list| list = list.map { |name| Sinatra.const_get name } - base.send(meth, *list) unless base == ::Sinatra::Application + base.send(method, *list) unless base == ::Sinatra::Application end end end diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/contrib/version.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/contrib/version.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/contrib/version.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/contrib/version.rb 2013-08-29 10:22:25.000000000 +0000 @@ -4,7 +4,7 @@ VERSION end - SIGNATURE = [1, 3, 1] + SIGNATURE = [1, 4, 1] VERSION = SIGNATURE.join('.') VERSION.extend Comparable diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/cookies.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/cookies.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/cookies.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/cookies.rb 2013-08-29 10:22:25.000000000 +0000 @@ -11,7 +11,7 @@ # Allows you to read cookies: # # get '/' do - # "value: #{cookie[:something]}" + # "value: #{cookies[:something]}" # end # # And of course to write cookies: @@ -42,7 +42,7 @@ # === Modular Application # # In a modular application you need to require the helpers, and then tell - # the application you will use them: + # the application to use them: # # require "sinatra/base" # require "sinatra/cookies" @@ -111,7 +111,7 @@ def delete(key) result = self[key] - @response.delete_cookie(key.to_s) + @response.delete_cookie(key.to_s, @options) result end @@ -305,7 +305,7 @@ key, value = line.split(';', 2).first.to_s.split('=', 2) next if key.nil? key = Rack::Utils.unescape(key) - if line.include? "expires=Thu, 01-Jan-1970 00:00:00 GMT" + if line =~ /expires=Thu, 01[-\s]Jan[-\s]1970/ @deleted << key else @deleted.delete key diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/decompile.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/decompile.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/decompile.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/decompile.rb 2013-08-29 10:22:25.000000000 +0000 @@ -60,7 +60,7 @@ # end # end # - # Will return the internal Regexp if unable to reconstruct the pattern, + # Will return the internal Regexp if it's unable to reconstruct the pattern, # which likely indicates that a Regexp was used in the first place. # # You can also use this to check whether you could actually use a string @@ -70,17 +70,25 @@ def decompile(pattern, keys = nil, *) # Everything in here is basically just the reverse of # Sinatra::Base#compile + # + # Sinatra 2.0 will come with a mechanism for this, making this obsolete. pattern, keys = pattern if pattern.respond_to? :to_ary keys, str = keys.try(:dup), pattern.inspect return pattern unless str.start_with? '/' and str.end_with? '/' - str.gsub! /^\/\^?|\$?\/$/, '' + str.gsub! /^\/(\^|\\A)?|(\$|\\z)?\/$/, '' str.gsub! encoded(' '), ' ' return pattern if str =~ /^[\.\+]/ - str.gsub! /\([^\(\)]*\)/ do |part| + str.gsub! '((?:[^\.\/?#%]|(?:%[^2].|%[2][^Ee]))+)', '([^\/?#]+)' + str.gsub! '((?:[^\/?#%]|(?:%[^2].|%[2][^Ee]))+)', '([^\/?#]+)' + str.gsub! /\([^\(\)]*\)|\([^\(\)]*\([^\(\)]*\)[^\(\)]*\)/ do |part| case part when '(.*?)' return pattern if keys.shift != 'splat' '*' + when /^\(\?\:(\\*.)\|%[\w\[\]]+\)$/ + $1 + when /^\(\?\:(%\d+)\|([^\)]+|\([^\)]+\))\)$/ + URI.unescape($1) when '([^\/?#]+)' return pattern if keys.empty? ":" << keys.shift @@ -102,8 +110,8 @@ def encoded(char) return super if defined? super - enc = URI.encode(char) - enc = "(?:#{Regexp.escape enc}|#{URI.encode char, /./})" if enc == char + enc = URI.escape(char) + enc = "(?:#{escaped(char, enc).join('|')})" if enc == char enc = "(?:#{enc}|#{encoded('+')})" if char == " " enc end diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/extension.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/extension.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/extension.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/extension.rb 2013-08-29 10:22:25.000000000 +0000 @@ -6,12 +6,12 @@ # = Sinatra::Extension # # Sinatra::Extension is a mixin that provides some syntactic sugar - # for your extensions. It allows you to call directly inside your extension - # module almost any Sinatra::Base method. This means you can use - # +get+ to define a route, +before+ to define a before filter, +set+ to - # define a setting, a so on. + # for your extensions. It allows you to call almost any + # Sinatra::Base method directly inside your extension + # module. This means you can use +get+ to define a route, +before+ + # to define a before filter, +set+ to define a setting and so on. # - # Is important to be aware that this mixin remembers the methods calls you + # Is important to be aware that this mixin remembers the method calls you # make, and then, when your extension is registered, replays them on the # Sinatra application that has been extended. In order to do that, it # defines a registered method, so, if your extension defines one diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/json.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/json.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/json.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/json.rb 2013-08-29 10:22:25.000000000 +0000 @@ -1,5 +1,5 @@ require 'sinatra/base' - +require 'multi_json' module Sinatra # = Sinatra::JSON @@ -32,7 +32,6 @@ # require "sinatra/json" # # class MyApp < Sinatra::Base - # helpers Sinatra::JSON # # # define a route that uses the helper # get '/' do @@ -44,8 +43,8 @@ # # === Encoders # - # Per default it will try to call +to_json+ on the object, but if it doesn't - # respond to that message, will use its own, rather simple encoder. You can + # By default it will try to call +to_json+ on the object, but if it doesn't + # respond to that message, it will use its own rather simple encoder. You can # easily change that anyways. To use +JSON+, simply require it: # # require 'json' @@ -90,45 +89,43 @@ module JSON class << self def encode(object) - enc object, Array, Hash + ::MultiJson.dump(object) end + end - private + def json(object, options = {}) + content_type resolve_content_type(options) + resolve_encoder_action object, resolve_encoder(options) + end - def enc(o, *a) - o = o.to_s if o.is_a? Symbol - fail "invalid: #{o.inspect}" unless a.empty? or a.include? o.class - case o - when Float then o.nan? || o.infinite? ? 'null' : o.inspect - when TrueClass, FalseClass, NilClass, Numeric, String then o.inspect - when Array then map(o, "[%s]") { |e| enc(e) } - when Hash then map(o, "{%s}") { |k,v| enc(k, String) + ":" + enc(v) } - end - end + private - def map(o, wrapper, &block) - wrapper % o.map(&block).join(',') - end + def resolve_content_type(options = {}) + options[:content_type] || settings.json_content_type end - def json(object, options = {}) - encoder = options[:encoder] || settings.json_encoder - content_type options[:content_type] || settings.json_content_type - if encoder.respond_to? :encode then encoder.encode(object) - elsif encoder.respond_to? :generate then encoder.generate(object) - elsif encoder.is_a? Symbol then object.__send__(encoder) - else fail "#{encoder} does not respond to #generate nor #encode" - end + def resolve_encoder(options = {}) + options[:json_encoder] || settings.json_encoder end - end + + def resolve_encoder_action(object, encoder) + [:encode, :generate].each do |method| + return encoder.send(method, object) if encoder.respond_to? method + end + if encoder.is_a? Symbol + object.__send__(encoder) + else + fail "#{encoder} does not respond to #generate nor #encode" + end #if + end #resolve_encoder_action + end #JSON Base.set :json_encoder do - return Yajl::Encoder if defined? Yajl::Encoder - return JSON if defined? JSON - return :to_json if {}.respond_to? :to_json and [].respond_to? :to_json - Sinatra::JSON + ::MultiJson end Base.set :json_content_type, :json - helpers JSON + + # Load the JSON helpers in modular style automatically + Base.helpers JSON end diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/link_header.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/link_header.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/link_header.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/link_header.rb 2013-08-29 10:22:25.000000000 +0000 @@ -53,8 +53,8 @@ # module LinkHeader ## - # Set Link HTTP header and returns HTML tags for telling the browser to - # prefetch given resources (only supported by Opera and Firefox at the + # Sets Link HTTP header and returns HTML tags for telling the browser to + # prefetch given resources (only supported by Opera and Firefox at the # moment). def prefetch(*urls) link(:prefetch, *urls) diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/multi_route.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/multi_route.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/multi_route.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/multi_route.rb 2013-08-29 10:22:25.000000000 +0000 @@ -19,6 +19,12 @@ # # ... # end # + # Or for multiple verbs and multiple routes: + # + # route :get, :post, ['/foo', '/bar'] do + # # ... + # end + # # Or even for custom verbs: # # route 'LIST', '/' do diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/namespace.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/namespace.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/namespace.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/namespace.rb 2013-08-29 10:22:25.000000000 +0000 @@ -14,7 +14,7 @@ # # == Usage # - # Once you have loaded the extension (see below), you use the +namespace+ + # Once you have loaded the extension (see below), you can use the +namespace+ # method to define namespaces in your application. # # You can define a namespace by a path prefix: @@ -177,18 +177,21 @@ end def errors - base.errors.merge(@errors) + base.errors.merge(namespace_errors) end def namespace_errors @errors end - + def error(*codes, &block) args = Sinatra::Base.send(:compile!, "ERROR", /^#{@pattern}/, block) codes = codes.map { |c| Array(c) }.flatten codes << Exception if codes.empty? - codes.each { |c| @errors[c] = args } + codes.each do |c| + errors = @errors[c] ||= [] + errors << args + end end def respond_to(*args) @@ -262,8 +265,8 @@ result end - def method_missing(meth, *args, &block) - base.send(meth, *args, &block) + def method_missing(method, *args, &block) + base.send(method, *args, &block) end end diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/reloader.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/reloader.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/reloader.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/reloader.rb 2013-08-29 10:22:25.000000000 +0000 @@ -13,7 +13,7 @@ # # === Classic Application # - # To enable the realoader in a classic application all you need to do is + # To enable the reloader in a classic application all you need to do is # require it: # # require "sinatra" @@ -23,7 +23,7 @@ # # === Modular Application # - # To enable the realoader in a modular application all you need to do is + # To enable the reloader in a modular application all you need to do is # require it, and then, register it: # # require "sinatra/base" @@ -75,7 +75,7 @@ module Reloader # Watches a file so it can tell when it has been updated, and what - # elements contains. + # elements does it contain. class Watcher # Represents an element of a Sinatra application that may need to @@ -95,8 +95,8 @@ # Collection of file +Watcher+ that can be associated with a # Sinatra application. That way, we can know which files belong # to a given application and which files have been modified. It - # also provides a mechanism to inform a Watcher the elements - # defined in the file being watched and if it changes should be + # also provides a mechanism to inform a Watcher of the elements + # defined in the file being watched and if its changes should be # ignored. class List @app_list_map = Hash.new { |hash, key| hash[key] = new } @@ -113,7 +113,7 @@ end end - # Lets the +Watcher+ for the file localted at +path+ know that the + # Lets the +Watcher+ for the file located at +path+ know that the # +element+ is defined there, and adds the +Watcher+ to the +List+, # if it isn't already there. def watch(path, element) @@ -159,7 +159,7 @@ !ignore? && !removed? && mtime != File.mtime(path) end - # Updates the file being watched mtime. + # Updates the mtime of the file being watched. def update @mtime = File.mtime(path) end diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/respond_with.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/respond_with.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/respond_with.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/respond_with.rb 2013-08-29 10:22:25.000000000 +0000 @@ -1,11 +1,11 @@ -require 'sinatra/base' require 'sinatra/json' +require 'sinatra/base' module Sinatra - ## + # # = Sinatra::RespondWith # - # This extensions lets Sinatra automatically choose what template to render or + # These extensions let Sinatra automatically choose what template to render or # action to perform depending on the request's Accept header. # # Example: @@ -14,7 +14,7 @@ # get '/' do # data = { :name => 'example' } # request.accept.each do |type| - # case type + # case type.to_s # when 'text/html' # halt haml(:index, :locals => data) # when 'text/json' @@ -53,8 +53,8 @@ # == Security # # Since methods are triggered based on client input, this can lead to security - # issues (but not as seviere as those might apear in the first place: keep in - # mind that only known file extensions are used). You therefore should limit + # issues (but not as severe as those might appear in the first place: keep in + # mind that only known file extensions are used). You should limit # the possible formats you serve. # # This is possible with the +provides+ condition: @@ -64,7 +64,7 @@ # end # # However, since you have to set +provides+ for every route, this extension - # adds a app global (class method) `respond_to`, that let's you define content + # adds an app global (class method) `respond_to`, that lets you define content # types for all routes: # # respond_to :html, :json, :xml, :atom @@ -118,9 +118,9 @@ @app.halt 406 end - def method_missing(meth, *args, &block) - return super if args.any? or block.nil? or not @app.mime_type(meth) - on(meth, &block) + def method_missing(method, *args, &block) + return super if args.any? or block.nil? or not @app.mime_type(method) + on(method, &block) end end @@ -138,15 +138,18 @@ if args.any? locals = { :object => object } locals.merge! object.to_hash if object.respond_to? :to_hash - args << { :locals => locals } - halt send(*args) + + renderer = args.first + options = args[1..-1] + [{:locals => locals}] + + halt send(renderer, *options) end end if object exts.each do |ext| halt json(object) if ext == :json - next unless meth = "to_#{ext}" and object.respond_to? meth - halt(*object.send(meth)) + next unless object.respond_to? method = "to_#{ext}" + halt(*object.send(method)) end end false @@ -161,7 +164,7 @@ private def template_for(name, exts) - # in production this is cached, so don't worry to much about runtime + # in production this is cached, so don't worry too much about runtime possible = [] settings.template_engines[:all].each do |engine| exts.each { |ext| possible << [engine, "#{name}.#{ext}"] } @@ -181,8 +184,6 @@ end end - attr_accessor :ext_map - def remap_extensions ext_map.clear Rack::Mime::MIME_TYPES.each { |e,t| ext_map[t] << e[1..-1].to_sym } @@ -224,6 +225,7 @@ :css => [:less, :sass, :scss], :xml => [:builder, :nokogiri], :js => [:coffee], + :json => [:yajl], :html => [:erb, :erubis, :haml, :slim, :liquid, :radius, :mab, :markdown, :textile, :rdoc], :all => Sinatra::Templates.instance_methods.map(&:to_sym) + [:mab] - @@ -233,7 +235,7 @@ ENGINES.default = [] def self.registered(base) - base.ext_map = Hash.new { |h,k| h[k] = [] } + base.set :ext_map, Hash.new { |h,k| h[k] = [] } base.set :template_engines, ENGINES.dup base.remap_extensions base.helpers Helpers diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/streaming.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/streaming.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/streaming.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/streaming.rb 2013-08-29 10:22:25.000000000 +0000 @@ -1,5 +1,4 @@ require 'sinatra/base' -require 'eventmachine' require 'backports' module Sinatra @@ -7,7 +6,7 @@ # = Sinatra::Streaming # # Sinatra 1.3 introduced the +stream+ helper. This addon improves the - # streaming API by making the stream object immitate an IO object, turing + # streaming API by making the stream object immitate an IO object, turning # it into a real Deferrable and making the body play nicer with middleware # unaware of streaming. # @@ -25,28 +24,11 @@ # end # end # - # == Proper Deferrable - # - # Handy when using EventMachine. - # - # list = [] - # - # get '/' do - # stream(:keep_open) do |out| - # list << out - # out.callback { list.delete out } - # out.errback do - # logger.warn "lost connection" - # list.delete out - # end - # end - # end - # # == Better Middleware Handling # - # Blocks passed to #map! or #map will actually be applied while streaming - # (as you might suspect, #map! applies modifications to the current body, - # #map creates a new one): + # Blocks passed to #map! or #map will actually be applied when streaming + # takes place (as you might have suspected, #map! applies modifications + # to the current body, while #map creates a new one): # # class StupidMiddleware # def initialize(app) @app = app end @@ -89,7 +71,7 @@ # # require "sinatra/base" # require "sinatra/streaming" - # + # # class MyApp < Sinatra::Base # helpers Sinatra::Streaming # end @@ -103,7 +85,6 @@ end module Stream - include EventMachine::Deferrable attr_accessor :app, :lineno, :pos, :transformer, :closed alias tell pos @@ -169,11 +150,6 @@ nil end - def close - @scheduler.schedule { succeed } - nil - end - def close_read raise IOError, "closing non-duplex IO for reading" end @@ -264,4 +240,4 @@ end helpers Streaming -end \ No newline at end of file +end diff -Nru ruby-sinatra-contrib-1.3.2/lib/sinatra/test_helpers.rb ruby-sinatra-contrib-1.4.1/lib/sinatra/test_helpers.rb --- ruby-sinatra-contrib-1.3.2/lib/sinatra/test_helpers.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/lib/sinatra/test_helpers.rb 2013-08-29 10:22:25.000000000 +0000 @@ -72,7 +72,7 @@ def session return {} unless last_request? - raise Rack::Test:Error, "session not enabled for app" unless last_env["rack.session"] or app.session? + raise Rack::Test::Error, "session not enabled for app" unless last_env["rack.session"] or app.session? last_request.session end diff -Nru ruby-sinatra-contrib-1.3.2/metadata.yml ruby-sinatra-contrib-1.4.1/metadata.yml --- ruby-sinatra-contrib-1.3.2/metadata.yml 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/metadata.yml 2013-08-29 10:22:25.000000000 +0000 @@ -1,49 +1,67 @@ --- !ruby/object:Gem::Specification name: sinatra-contrib version: !ruby/object:Gem::Version - version: 1.3.2 - prerelease: + version: 1.4.1 platform: ruby authors: - Konstantin Haase - Gabriel Andretta - Trevor Bramble +- Zachary Scott +- Katrina Owen - Nicolas Sanguinetti -- Ilya Shindyapin - Masahiro Fujiwara +- Rafael Magana +- Hrvoje Šimić +- Jack Chu +- Sumeet Singh +- Ilya Shindyapin +- lest +- Kashyap +- Michi Huber +- Patricio Mac Adden +- Reed Lipman +- Samy Dindane +- Thibaut Sacreste +- Uchio KONDO +- Will Bailey - Adrian Pacała +- undr +- Aish - Andrew Crump +- David Asabina - Eliot Shepard - Eric Marden - Gray Manley +- Guillaume Bouteille +- Jamie Hodge +- Kyle Lacy +- Martin Frost - Matt Lyon -- lest -- undr +- Matthew Conway +- Meck autorequire: bindir: bin cert_chain: [] -date: 2012-10-22 00:00:00.000000000 Z +date: 2013-08-19 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: sinatra requirement: !ruby/object:Gem::Requirement - none: false requirements: - - ~> - !ruby/object:Gem::Version - version: 1.3.0 + version: 1.4.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement - none: false requirements: - - ~> - !ruby/object:Gem::Version - version: 1.3.0 + version: 1.4.0 - !ruby/object:Gem::Dependency name: backports requirement: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -51,7 +69,6 @@ type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -59,7 +76,6 @@ - !ruby/object:Gem::Dependency name: tilt requirement: !ruby/object:Gem::Requirement - none: false requirements: - - ~> - !ruby/object:Gem::Version @@ -67,7 +83,6 @@ type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement - none: false requirements: - - ~> - !ruby/object:Gem::Version @@ -75,7 +90,6 @@ - !ruby/object:Gem::Dependency name: rack-test requirement: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -83,7 +97,6 @@ type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -91,7 +104,6 @@ - !ruby/object:Gem::Dependency name: rack-protection requirement: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -99,15 +111,13 @@ type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency - name: eventmachine + name: multi_json requirement: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -115,7 +125,6 @@ type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -123,7 +132,6 @@ - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement - none: false requirements: - - ~> - !ruby/object:Gem::Version @@ -131,7 +139,6 @@ type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement - none: false requirements: - - ~> - !ruby/object:Gem::Version @@ -139,7 +146,6 @@ - !ruby/object:Gem::Dependency name: haml requirement: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -147,7 +153,6 @@ type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -155,7 +160,6 @@ - !ruby/object:Gem::Dependency name: erubis requirement: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -163,7 +167,6 @@ type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -171,7 +174,6 @@ - !ruby/object:Gem::Dependency name: slim requirement: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -179,7 +181,6 @@ type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -187,7 +188,6 @@ - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -195,7 +195,6 @@ type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version @@ -205,17 +204,41 @@ - konstantin.mailinglists@googlemail.com - ohhgabriel@gmail.com - inbox@trevorbramble.com +- zachary@zacharyscott.net +- katrina.owen@gmail.com - contacto@nicolassanguinetti.info -- ilya@shindyapin.com - m-fujiwara@axsh.net +- raf.magana@gmail.com +- shime.ferovac@gmail.com +- konstantin.haase@gmail.com +- jack@jackchu.com +- ilya@shindyapin.com +- ortuna@gmail.com +- kashyap.kmbc@gmail.com +- e@zzak.io +- just.lest@gmail.com +- rmlipman@gmail.com +- samy@dindane.com +- thibaut.sacreste@gmail.com +- udzura@udzura.jp +- will.bailey@gmail.com - altpacala@gmail.com +- undr@yandex.ru +- aisha.fenton@visfleet.com - andrew.crump@ieee.org +- david@supr.nu - eshepard@slower.net - eric.marden@gmail.com - g.manley@tukaiz.com +- duffman@via.ecp.fr +- jamiehodge@me.com +- kylewlacy@me.com +- blame@kth.se - matt@flowerpowered.com -- just.lest@gmail.com -- undr@yandex.ru +- himself@mattonrails.com +- yesmeck@gmail.com +- michi.huber@gmail.com +- patriciomacadden@gmail.com executables: [] extensions: [] extra_rdoc_files: [] @@ -246,6 +269,7 @@ - sinatra-contrib.gemspec - spec/capture_spec.rb - spec/config_file/key_value.yml +- spec/config_file/key_value.yml.erb - spec/config_file/key_value_override.yml - spec/config_file/missing_env.yml - spec/config_file/with_envs.yml @@ -298,6 +322,7 @@ - spec/reloader_spec.rb - spec/respond_with/bar.erb - spec/respond_with/bar.json.erb +- spec/respond_with/baz.yajl - spec/respond_with/foo.html.erb - spec/respond_with/not_html.sass - spec/respond_with_spec.rb @@ -305,26 +330,25 @@ - spec/streaming_spec.rb homepage: http://github.com/sinatra/sinatra-contrib licenses: [] +metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement - none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: -rubygems_version: 1.8.24 +rubygems_version: 2.0.3 signing_key: -specification_version: 3 +specification_version: 4 summary: Collection of useful Sinatra extensions test_files: [] diff -Nru ruby-sinatra-contrib-1.3.2/sinatra-contrib.gemspec ruby-sinatra-contrib-1.4.1/sinatra-contrib.gemspec --- ruby-sinatra-contrib-1.3.2/sinatra-contrib.gemspec 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/sinatra-contrib.gemspec 2013-08-29 10:22:25.000000000 +0000 @@ -1,7 +1,8 @@ # Run `rake sinatra-contrib.gemspec` to update the gemspec. +require File.expand_path('../lib/sinatra/contrib/version', __FILE__) Gem::Specification.new do |s| s.name = "sinatra-contrib" - s.version = "1.3.2" + s.version = Sinatra::Contrib::VERSION s.description = "Collection of useful Sinatra extensions" s.homepage = "http://github.com/sinatra/sinatra-contrib" s.summary = s.description @@ -11,17 +12,39 @@ "Konstantin Haase", "Gabriel Andretta", "Trevor Bramble", + "Zachary Scott", + "Katrina Owen", "Nicolas Sanguinetti", - "Ilya Shindyapin", "Masahiro Fujiwara", + "Rafael Magana", + "Hrvoje Šimić", + "Jack Chu", + "Sumeet Singh", + "Ilya Shindyapin", + "lest", + "Kashyap", + "Michi Huber", + "Patricio Mac Adden", + "Reed Lipman", + "Samy Dindane", + "Thibaut Sacreste", + "Uchio KONDO", + "Will Bailey", "Adrian Pacała", + "undr", + "Aish", "Andrew Crump", + "David Asabina", "Eliot Shepard", "Eric Marden", "Gray Manley", + "Guillaume Bouteille", + "Jamie Hodge", + "Kyle Lacy", + "Martin Frost", "Matt Lyon", - "lest", - "undr" + "Matthew Conway", + "Meck" ] # generated from git shortlog -sne @@ -29,17 +52,41 @@ "konstantin.mailinglists@googlemail.com", "ohhgabriel@gmail.com", "inbox@trevorbramble.com", + "zachary@zacharyscott.net", + "katrina.owen@gmail.com", "contacto@nicolassanguinetti.info", - "ilya@shindyapin.com", "m-fujiwara@axsh.net", + "raf.magana@gmail.com", + "shime.ferovac@gmail.com", + "konstantin.haase@gmail.com", + "jack@jackchu.com", + "ilya@shindyapin.com", + "ortuna@gmail.com", + "kashyap.kmbc@gmail.com", + "e@zzak.io", + "just.lest@gmail.com", + "rmlipman@gmail.com", + "samy@dindane.com", + "thibaut.sacreste@gmail.com", + "udzura@udzura.jp", + "will.bailey@gmail.com", "altpacala@gmail.com", + "undr@yandex.ru", + "aisha.fenton@visfleet.com", "andrew.crump@ieee.org", + "david@supr.nu", "eshepard@slower.net", "eric.marden@gmail.com", "g.manley@tukaiz.com", + "duffman@via.ecp.fr", + "jamiehodge@me.com", + "kylewlacy@me.com", + "blame@kth.se", "matt@flowerpowered.com", - "just.lest@gmail.com", - "undr@yandex.ru" + "himself@mattonrails.com", + "yesmeck@gmail.com", + "michi.huber@gmail.com", + "patriciomacadden@gmail.com" ] # generated from git ls-files @@ -70,6 +117,7 @@ "sinatra-contrib.gemspec", "spec/capture_spec.rb", "spec/config_file/key_value.yml", + "spec/config_file/key_value.yml.erb", "spec/config_file/key_value_override.yml", "spec/config_file/missing_env.yml", "spec/config_file/with_envs.yml", @@ -122,6 +170,7 @@ "spec/reloader_spec.rb", "spec/respond_with/bar.erb", "spec/respond_with/bar.json.erb", + "spec/respond_with/baz.yajl", "spec/respond_with/foo.html.erb", "spec/respond_with/not_html.sass", "spec/respond_with_spec.rb", @@ -129,12 +178,12 @@ "spec/streaming_spec.rb" ] - s.add_dependency "sinatra", "~> 1.3.0" + s.add_dependency "sinatra", "~> 1.4.0" s.add_dependency "backports", ">= 2.0" s.add_dependency "tilt", "~> 1.3" s.add_dependency "rack-test" s.add_dependency "rack-protection" - s.add_dependency "eventmachine" + s.add_dependency "multi_json" s.add_development_dependency "rspec", "~> 2.3" s.add_development_dependency "haml" diff -Nru ruby-sinatra-contrib-1.3.2/spec/capture_spec.rb ruby-sinatra-contrib-1.4.1/spec/capture_spec.rb --- ruby-sinatra-contrib-1.3.2/spec/capture_spec.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/spec/capture_spec.rb 2013-08-29 10:22:25.000000000 +0000 @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- require 'backports' require 'slim' require_relative 'spec_helper' @@ -20,6 +21,7 @@ shared_examples_for "a template language" do |engine| lang = engine == :erubis ? :erb : engine + require "#{engine}" it "captures content" do render(engine, "simple_#{lang}").should == "Say Hello World!" @@ -32,8 +34,15 @@ describe('haml') { it_behaves_like "a template language", :haml } describe('slim') { it_behaves_like "a template language", :slim } - describe('erb') { it_behaves_like "a template language", :erb } describe('erubis') { it_behaves_like "a template language", :erubis } + + describe 'erb' do + it_behaves_like "a template language", :erb + + it "handles utf-8 encoding" do + render(:erb, "utf_8").should == "UTF-8 –" + end + end end __END__ @@ -78,3 +87,7 @@ World #{b.strip}! Hello #{a.strip} + +@@ utf_8 +<% a = capture do %>–<% end %> +UTF-8 <%= a %> diff -Nru ruby-sinatra-contrib-1.3.2/spec/config_file/key_value.yml.erb ruby-sinatra-contrib-1.4.1/spec/config_file/key_value.yml.erb --- ruby-sinatra-contrib-1.3.2/spec/config_file/key_value.yml.erb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/spec/config_file/key_value.yml.erb 2013-08-29 10:22:25.000000000 +0000 @@ -0,0 +1,6 @@ +--- +foo: <%= "bar" %> +something: <%= 42 %> +nested: + a: <%= 1 %> + b: <%= 2 %> diff -Nru ruby-sinatra-contrib-1.3.2/spec/config_file_spec.rb ruby-sinatra-contrib-1.4.1/spec/config_file_spec.rb --- ruby-sinatra-contrib-1.3.2/spec/config_file_spec.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/spec/config_file_spec.rb 2013-08-29 10:22:25.000000000 +0000 @@ -23,6 +23,16 @@ settings.nested[:a].should == 1 end + it 'should render options in ERB tags' do + config_file 'key_value.yml.erb' + settings.foo.should == "bar" + settings.something.should == 42 + settings.nested['a'].should == 1 + settings.nested[:a].should == 1 + settings.nested['b'].should == 2 + settings.nested[:b].should == 2 + end + it 'should recognize env specific settings per file' do config_file 'with_envs.yml' settings.foo.should == 'test' diff -Nru ruby-sinatra-contrib-1.3.2/spec/content_for_spec.rb ruby-sinatra-contrib-1.4.1/spec/content_for_spec.rb --- ruby-sinatra-contrib-1.3.2/spec/content_for_spec.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/spec/content_for_spec.rb 2013-08-29 10:22:25.000000000 +0000 @@ -138,13 +138,13 @@ render(inner, :passes_values).should == "12" end end - + describe "with content_for? in Ruby" do - it 'renders block if key is set' do + it 'renders block if key is set' do content_for(:foo) { "foot" } render(inner, :footer).should == "foot" end - + it 'does not render a block if different key' do content_for(:different_key) { "foot" } render(inner, :footer).should be_empty diff -Nru ruby-sinatra-contrib-1.3.2/spec/cookies_spec.rb ruby-sinatra-contrib-1.4.1/spec/cookies_spec.rb --- ruby-sinatra-contrib-1.3.2/spec/cookies_spec.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/spec/cookies_spec.rb 2013-08-29 10:22:25.000000000 +0000 @@ -154,11 +154,11 @@ end.should be_nil end - it 'expiers existing cookies' do + it 'expires existing cookies' do cookie_route("foo=bar") do cookies.clear response['Set-Cookie'] - end.should include("foo=; expires=Thu, 01-Jan-1970 00:00:00 GMT") + end.should include("foo=;", "expires=", "1970 00:00:00") end end @@ -185,16 +185,32 @@ it 'removes response cookies from cookies hash' do cookie_route do cookies['foo'] = 'bar' - cookies.clear + cookies.delete 'foo' cookies['foo'] end.should be_nil end - it 'expiers existing cookies' do + it 'expires existing cookies' do cookie_route("foo=bar") do cookies.delete 'foo' response['Set-Cookie'] - end.should include("foo=; expires=Thu, 01-Jan-1970 00:00:00 GMT") + end.should include("foo=;", "expires=", "1970 00:00:00") + end + + it 'honours the app cookie_options' do + @cookie_app.class_eval do + set :cookie_options, { + :path => '/foo', + :domain => 'bar.com', + :secure => true, + :httponly => true + } + end + cookie_header = cookie_route("foo=bar") do + cookies.delete 'foo' + response['Set-Cookie'] + end + cookie_header.should include("path=/foo;", "domain=bar.com;", "secure;", "HttpOnly") end it 'does not touch other cookies' do @@ -466,7 +482,11 @@ end it 'raises an exception if key does not exist' do - error = RUBY_VERSION >= '1.9' ? KeyError : IndexError + error = if defined? JRUBY_VERSION + IndexError + else + RUBY_VERSION >= '1.9' ? KeyError : IndexError + end expect { cookies.fetch('foo') }.to raise_exception(error) end diff -Nru ruby-sinatra-contrib-1.3.2/spec/json_spec.rb ruby-sinatra-contrib-1.4.1/spec/json_spec.rb --- ruby-sinatra-contrib-1.3.2/spec/json_spec.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/spec/json_spec.rb 2013-08-29 10:22:25.000000000 +0000 @@ -1,4 +1,6 @@ require 'backports' +require 'multi_json' + require_relative 'spec_helper' require_relative 'okjson' @@ -31,7 +33,6 @@ describe Sinatra::JSON do def mock_app(&block) super do - helpers Sinatra::JSON class_eval(&block) end end @@ -41,8 +42,8 @@ end it "encodes objects to json out of the box" do - mock_app { get('/') { json :foo => [1, 'bar'] } } - results_in 'foo' => [1, 'bar'] + mock_app { get('/') { json :foo => [1, 'bar', nil] } } + results_in 'foo' => [1, 'bar', nil] end it "sets the content type to 'application/json'" do @@ -107,7 +108,7 @@ get('/').body.should == '42' end - describe('Yajl') { it_should_behave_like "a json encoder", "yajl", "Yajl::Encoder" } + describe('Yajl') { it_should_behave_like "a json encoder", "yajl", "Yajl::Encoder" } unless defined? JRUBY_VERSION describe('JSON') { it_should_behave_like "a json encoder", "json", "::JSON" } describe('OkJson') { it_should_behave_like "a json encoder", nil, "OkJson" } describe('to_json') { it_should_behave_like "a json encoder", "json", ":to_json" } diff -Nru ruby-sinatra-contrib-1.3.2/spec/multi_route_spec.rb ruby-sinatra-contrib-1.4.1/spec/multi_route_spec.rb --- ruby-sinatra-contrib-1.3.2/spec/multi_route_spec.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/spec/multi_route_spec.rb 2013-08-29 10:22:25.000000000 +0000 @@ -2,25 +2,23 @@ require_relative 'spec_helper' describe Sinatra::MultiRoute do - before do - count = 0 + + it 'does not break normal routing' do mock_app do - set(:some_condition) { |_| count += 1 } register Sinatra::MultiRoute get('/') { 'normal' } - get('/foo', '/bar', :some_condition => true) { 'paths' } - route('PUT', 'POST', '/') { 'verb' } - route(:get, '/baz') { 'symbol as verb' } end - @count = count - end - it 'does still allow normal routing' do get('/').should be_ok body.should be == 'normal' end - it 'supports multpile routes' do + it 'supports multiple routes' do + mock_app do + register Sinatra::MultiRoute + get('/foo', '/bar') { 'paths' } + end + get('/foo').should be_ok body.should be == 'paths' get('/bar').should be_ok @@ -28,10 +26,22 @@ end it 'triggers conditions' do - @count.should be == 4 + count = 0 + mock_app do + register Sinatra::MultiRoute + set(:some_condition) { |_| count += 1 } + get('/foo', '/bar', :some_condition => true) { 'paths' } + end + + count.should be == 4 end - it 'supports multpile verbs' do + it 'supports multiple verbs' do + mock_app do + register Sinatra::MultiRoute + route('PUT', 'POST', '/') { 'verb' } + end + post('/').should be_ok body.should be == 'verb' put('/').should be_ok @@ -39,7 +49,12 @@ end it 'takes symbols as verbs' do + mock_app do + register Sinatra::MultiRoute + route(:get, '/baz') { 'symbol as verb' } + end + get('/baz').should be_ok body.should be == 'symbol as verb' end -end \ No newline at end of file +end diff -Nru ruby-sinatra-contrib-1.3.2/spec/namespace_spec.rb ruby-sinatra-contrib-1.4.1/spec/namespace_spec.rb --- ruby-sinatra-contrib-1.3.2/spec/namespace_spec.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/spec/namespace_spec.rb 2013-08-29 10:22:25.000000000 +0000 @@ -18,258 +18,269 @@ verbs.each do |verb| describe "HTTP #{verb.to_s.upcase}" do - describe 'pattern generation' do - it "should add routes including prefix to the base app" do - namespace("/foo") { send(verb, "/bar") { "baz" }} - send(verb, "/foo/bar").should be_ok - body.should == "baz" unless verb == :head - send(verb, "/foo/baz").should_not be_ok - end - it "should allows adding routes with no path" do - namespace("/foo") { send(verb) { "bar" } } - send(verb, "/foo").should be_ok - body.should == "bar" unless verb == :head - end + it 'prefixes the path with the namespace' do + namespace('/foo') { send(verb, '/bar') { 'baz' }} + send(verb, '/foo/bar').should be_ok + body.should == 'baz' unless verb == :head + send(verb, '/foo/baz').should_not be_ok + end - it "allows unsing regular expressions" do - namespace("/foo") { send(verb, /\/\d\d/) { "bar" }} - send(verb, "/foo/12").should be_ok - body.should == "bar" unless verb == :head - send(verb, "/foo/123").should_not be_ok + context 'when namespace is a string' do + it 'accepts routes with no path' do + namespace('/foo') { send(verb) { 'bar' } } + send(verb, '/foo').should be_ok + body.should == 'bar' unless verb == :head end - it "allows using regular expressions for the prefix" do - namespace(/\/\d\d/) { send(verb, /\/\d\d/) { "foo" }} - send(verb, "/23/12").should be_ok - body.should == "foo" unless verb == :head - send(verb, "/123/12").should_not be_ok + it 'accepts the path as a named parameter' do + namespace('/foo') { send(verb, '/:bar') { params[:bar] }} + send(verb, '/foo/bar').should be_ok + body.should == 'bar' unless verb == :head + send(verb, '/foo/baz').should be_ok + body.should == 'baz' unless verb == :head end - it "sets params correctly from namespace" do - namespace("/:foo") { send(verb, "/bar") { params[:foo] }} - send(verb, "/foo/bar").should be_ok - body.should == "foo" unless verb == :head - send(verb, "/foo/baz").should_not be_ok - send(verb, "/fox/bar").should be_ok - body.should == "fox" unless verb == :head + it 'accepts the path as a regular expression' do + namespace('/foo') { send(verb, /\/\d\d/) { 'bar' }} + send(verb, '/foo/12').should be_ok + body.should == 'bar' unless verb == :head + send(verb, '/foo/123').should_not be_ok end - - it "sets params correctly from route" do - namespace("/foo") { send(verb, "/:bar") { params[:bar] }} - send(verb, "/foo/bar").should be_ok - body.should == "bar" unless verb == :head - send(verb, "/foo/baz").should be_ok - body.should == "baz" unless verb == :head + end + + context 'when namespace is a named parameter' do + it 'accepts routes with no path' do + namespace('/:foo') { send(verb) { 'bar' } } + send(verb, '/foo').should be_ok + body.should == 'bar' unless verb == :head end - it "allows splats to be combined from namespace and route" do - namespace("/*") { send(verb, "/*") { params[:splat].join " - " }} + it 'sets the parameter correctly' do + namespace('/:foo') { send(verb, '/bar') { params[:foo] }} send(verb, '/foo/bar').should be_ok - body.should == "foo - bar" unless verb == :head + body.should == 'foo' unless verb == :head + send(verb, '/fox/bar').should be_ok + body.should == 'fox' unless verb == :head + send(verb, '/foo/baz').should_not be_ok end - it "sets params correctly from namespace if simple regexp is used for route" do - namespace("/:foo") { send(verb, %r{/bar}) { params[:foo] }} - send(verb, "/foo/bar").should be_ok - body.should == "foo" unless verb == :head - send(verb, "/foo/baz").should_not be_ok - send(verb, "/fox/bar").should be_ok - body.should == "fox" unless verb == :head + it 'accepts the path as a named parameter' do + namespace('/:foo') { send(verb, '/:bar') { params[:bar] }} + send(verb, '/foo/bar').should be_ok + body.should == 'bar' unless verb == :head + send(verb, '/foo/baz').should be_ok + body.should == 'baz' unless verb == :head end - it "sets params correctly from route if simple regexp is used for namespace" do - namespace(%r{/foo}) { send(verb, "/:bar") { params[:bar] }} - send(verb, "/foo/bar").should be_ok - body.should == "bar" unless verb == :head - send(verb, "/foo/baz").should be_ok - body.should == "baz" unless verb == :head + it 'accepts the path as regular expression' do + namespace('/:foo') { send(verb, %r{/bar}) { params[:foo] }} + send(verb, '/foo/bar').should be_ok + body.should == 'foo' unless verb == :head + send(verb, '/fox/bar').should be_ok + body.should == 'fox' unless verb == :head + send(verb, '/foo/baz').should_not be_ok end + end - it 'allows defining routes without a pattern' do + context 'when namespace is a regular expression' do + it 'accepts routes with no path' do namespace(%r{/foo}) { send(verb) { 'bar' } } send(verb, '/foo').should be_ok - body.should == 'bar' unless verb == :head - end - end - - describe 'conditions' do - it 'allows using conditions for namespaces' do - mock_app do - namespace(:host_name => 'example.com') { send(verb) { 'yes' }} - send(verb, '/') { 'no' } - end - send(verb, '/', {}, 'HTTP_HOST' => 'example.com') - last_response.should be_ok - body.should == 'yes' unless verb == :head - send(verb, '/', {}, 'HTTP_HOST' => 'example.org') - last_response.should be_ok - body.should == 'no' unless verb == :head + body.should == 'bar' unless verb == :head end - it 'allows using conditions for before filters' do - namespace '/foo' do - before(:host_name => 'example.com') { @yes = "yes" } - send(verb) { @yes || "no" } - end - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com') - last_response.should be_ok - body.should == 'yes' unless verb == :head - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org') - last_response.should be_ok - body.should == 'no' unless verb == :head + it 'accepts the path as a named parameter' do + namespace(%r{/foo}) { send(verb, '/:bar') { params[:bar] }} + send(verb, '/foo/bar').should be_ok + body.should == 'bar' unless verb == :head + send(verb, '/foo/baz').should be_ok + body.should == 'baz' unless verb == :head end - it 'allows using conditions for after filters' do - ran = false - namespace '/foo' do - before(:host_name => 'example.com') { ran = true } - send(verb) { "ok" } - end - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org') - ran.should be_false - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com') - ran.should be_true + it 'accepts the path as a regular expression' do + namespace(/\/\d\d/) { send(verb, /\/\d\d/) { 'foo' }} + send(verb, '/23/12').should be_ok + body.should == 'foo' unless verb == :head + send(verb, '/123/12').should_not be_ok end + end - it 'allows using conditions for routes' do - namespace '/foo' do - send(verb, :host_name => 'example.com') { "ok" } - end - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com').should be_ok - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org').should_not be_ok + context 'when namespace is a splat' do + it 'accepts the path as a splat' do + namespace('/*') { send(verb, '/*') { params[:splat].join ' - ' }} + send(verb, '/foo/bar').should be_ok + body.should == 'foo - bar' unless verb == :head end + end - it 'allows using conditions for before filters and the namespace' do + describe 'before-filters' do + specify 'are triggered' do ran = false - namespace '/', :provides => :txt do - before(:host_name => 'example.com') { ran = true } - send(verb) { "ok" } - end - send(verb, '/', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain') - ran.should be_false - send(verb, '/', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html') - ran.should be_false - send(verb, '/', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain') + namespace('/foo') { before { ran = true }} + send(verb, '/foo') ran.should be_true end - it 'allows using conditions for routes and the namespace' do - namespace '/foo', :host_name => 'example.com' do - send(verb, :provides => :txt) { "ok" } - end - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain').should be_ok - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html').should_not be_ok - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain').should_not be_ok - end - - it 'allows combining conditions with a prefix for namespaces' do - namespace '/', :host_name => 'example.com' do - send(verb) { "ok" } - end - send(verb, '/', {}, 'HTTP_HOST' => 'example.com').should be_ok - send(verb, '/', {}, 'HTTP_HOST' => 'example.org').should_not be_ok - end - - it 'allows combining conditions with a prefix for before filters' do + specify 'are not triggered for a different namespace' do ran = false - namespace :provides => :txt do - before('/foo', :host_name => 'example.com') { ran = true } - send(verb, '/*') { "ok" } - end - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain') - ran.should be_false - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html') - ran.should be_false - send(verb, '/bar', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain') + namespace('/foo') { before { ran = true }} + send(verb, '/fox') ran.should be_false - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain') - ran.should be_true end + end - it 'allows combining conditions with a prefix for after filters' do + describe 'after-filters' do + specify 'are triggered' do ran = false - namespace :provides => :txt do - after('/foo', :host_name => 'example.com') { ran = true } - send(verb, '/*') { "ok" } - end - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain') - ran.should be_false - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html') - ran.should be_false - send(verb, '/bar', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain') - ran.should be_false - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain') + namespace('/foo') { after { ran = true }} + send(verb, '/foo') ran.should be_true end - it 'allows combining conditions with a prefix for routes' do - namespace :host_name => 'example.com' do - send(verb, '/foo', :provides => :txt) { "ok" } - end - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain').should be_ok - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html').should_not be_ok - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain').should_not be_ok - end - - it 'allows combining conditions with a prefix for filters and the namespace' do + specify 'are not triggered for a different namespace' do ran = false - namespace '/f', :provides => :txt do - before('oo', :host_name => 'example.com') { ran = true } - send(verb, '/*') { "ok" } - end - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain') - ran.should be_false - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html') - ran.should be_false - send(verb, '/far', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain') + namespace('/foo') { after { ran = true }} + send(verb, '/fox') ran.should be_false - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain') - ran.should be_true end + end - it 'allows combining conditions with a prefix for routes and the namespace' do - namespace '/f', :host_name => 'example.com' do - send(verb, 'oo', :provides => :txt) { "ok" } + describe 'conditions' do + context 'when the namespace has no prefix' do + specify 'are accepted in the namespace' do + mock_app do + namespace(:host_name => 'example.com') { send(verb) { 'yes' }} + send(verb, '/') { 'no' } + end + send(verb, '/', {}, 'HTTP_HOST' => 'example.com') + last_response.should be_ok + body.should == 'yes' unless verb == :head + send(verb, '/', {}, 'HTTP_HOST' => 'example.org') + last_response.should be_ok + body.should == 'no' unless verb == :head + end + + specify 'are accepted in the route definition' do + namespace :host_name => 'example.com' do + send(verb, '/foo', :provides => :txt) { 'ok' } + end + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain').should be_ok + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html').should_not be_ok + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain').should_not be_ok + end + + specify 'are accepted in the before-filter' do + ran = false + namespace :provides => :txt do + before('/foo', :host_name => 'example.com') { ran = true } + send(verb, '/*') { 'ok' } + end + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain') + ran.should be_false + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html') + ran.should be_false + send(verb, '/bar', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain') + ran.should be_false + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain') + ran.should be_true + end + + specify 'are accepted in the after-filter' do + ran = false + namespace :provides => :txt do + after('/foo', :host_name => 'example.com') { ran = true } + send(verb, '/*') { 'ok' } + end + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain') + ran.should be_false + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html') + ran.should be_false + send(verb, '/bar', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain') + ran.should be_false + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain') + ran.should be_true + end + end + + context 'when the namespace is a string' do + specify 'are accepted in the namespace' do + namespace '/foo', :host_name => 'example.com' do + send(verb) { 'ok' } + end + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com').should be_ok + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org').should_not be_ok end - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain').should be_ok - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html').should_not be_ok - send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain').should_not be_ok - end - end - describe 'filters' do - it 'should trigger before filters for namespaces' do - ran = false - namespace('/foo') { before { ran = true }} - send(verb, '/foo') - ran.should be_true - end + specify 'are accepted in the before-filter' do + namespace '/foo' do + before(:host_name => 'example.com') { @yes = 'yes' } + send(verb) { @yes || 'no' } + end + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com') + last_response.should be_ok + body.should == 'yes' unless verb == :head + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org') + last_response.should be_ok + body.should == 'no' unless verb == :head + end - it 'should trigger after filters for namespaces' do - ran = false - namespace('/foo') { after { ran = true }} - send(verb, '/foo') - ran.should be_true - end + specify 'are accepted in the after-filter' do + ran = false + namespace '/foo' do + before(:host_name => 'example.com') { ran = true } + send(verb) { 'ok' } + end + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org') + ran.should be_false + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com') + ran.should be_true + end - it 'should not trigger before filter for different namespaces' do - ran = false - namespace('/foo') { before { ran = true }} - send(verb, '/fox') - ran.should be_false - end + specify 'are accepted in the route definition' do + namespace '/foo' do + send(verb, :host_name => 'example.com') { 'ok' } + end + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com').should be_ok + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org').should_not be_ok + end - it 'should not trigger after filter for different namespaces' do - ran = false - namespace('/foo') { after { ran = true }} - send(verb, '/fox') - ran.should be_false + context 'when the namespace has a condition' do + specify 'are accepted in the before-filter' do + ran = false + namespace '/', :provides => :txt do + before(:host_name => 'example.com') { ran = true } + send(verb) { 'ok' } + end + send(verb, '/', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain') + ran.should be_false + send(verb, '/', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html') + ran.should be_false + send(verb, '/', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain') + ran.should be_true + end + + specify 'are accepted in the filters' do + ran = false + namespace '/f', :provides => :txt do + before('oo', :host_name => 'example.com') { ran = true } + send(verb, '/*') { 'ok' } + end + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain') + ran.should be_false + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html') + ran.should be_false + send(verb, '/far', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain') + ran.should be_false + send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain') + ran.should be_true + end + end end end describe 'helpers' do - it "allows defining helpers with the helpers method" do + it 'are defined using the helpers method' do namespace '/foo' do helpers do def magic @@ -286,7 +297,7 @@ body.should == '42' unless verb == :head end - it "allows defining helpers without the helpers method" do + it 'can be defined as normal methods' do namespace '/foo' do def magic 42 @@ -301,7 +312,7 @@ body.should == '42' unless verb == :head end - it "allows using helper mixins with the helpers method" do + it 'can be defined using module mixins' do mixin = Module.new do def magic 42 @@ -319,7 +330,7 @@ body.should == '42' unless verb == :head end - it "makes helpers defined inside a namespace not available to routes outside that namespace" do + specify 'are unavailable outside the namespace where they are defined' do mock_app do namespace '/foo' do def magic @@ -339,7 +350,7 @@ proc { send verb, '/' }.should raise_error(NameError) end - it "makes helper mixins used inside a namespace not available to routes outside that namespace" do + specify 'are unavailable outside the namespace that they are mixed into' do mixin = Module.new do def magic 42 @@ -362,7 +373,7 @@ proc { send verb, '/' }.should raise_error(NameError) end - it "allows accessing helpers defined outside the namespace" do + specify 'are available to nested namespaces' do mock_app do helpers do def magic @@ -381,7 +392,7 @@ body.should == '42' unless verb == :head end - it "allows calling super in helpers overwritten inside a namespace" do + specify 'can call super from nested definitions' do mock_app do helpers do def magic @@ -436,7 +447,7 @@ body.should == '42' unless verb == :head end - it 'does not use helpers of nested namespaces outside that namespace' do + specify 'does not provide access to nested helper methods' do namespace '/foo' do namespace '/bar' do def magic @@ -456,15 +467,15 @@ proc { send verb, '/foo' }.should raise_error(NameError) end - it 'sets params correctly' do + it 'accepts a nested namespace as a named parameter' do namespace('/:a') { namespace('/:b') { send(verb) { params[:a] }}} send(verb, '/foo/bar').should be_ok body.should == 'foo' unless verb == :head end end - describe 'error handlers' do - it "should allow custom error handlers with not found" do + describe 'error handling' do + it 'can be customized using the not_found block' do namespace('/de') do not_found { 'nicht gefunden' } end @@ -476,7 +487,7 @@ last_response.body.should == 'nicht gefunden' unless verb == :head end - it "should allow custom error handlers with error" do + it 'can be customized for specific error codes' do namespace('/de') do error(404) { 'nicht gefunden' } end @@ -488,15 +499,15 @@ last_response.body.should == 'nicht gefunden' unless verb == :head end - it "should handle custom errors in base. Issue #37." do - mock_app { + it 'falls back to the handler defined in the base app' do + mock_app do error(404) { 'not found...' } namespace('/en') do end namespace('/de') do error(404) { 'nicht gefunden' } end - } + end send(verb, '/foo').status.should == 404 last_response.body.should == 'not found...' unless verb == :head get('/en/foo').status.should == 404 @@ -505,25 +516,33 @@ last_response.body.should == 'nicht gefunden' unless verb == :head end - it "should allow custom error handlers with Exception class. Issue #37." do - mock_app { + it 'can be customized for specific Exception classes' do + mock_app do class AError < StandardError; end class BError < AError; end - - error(AError) { body('auth failed'); 401} + + error(AError) do + body('auth failed') + 401 + end + namespace('/en') do get '/foo' do raise BError end end + namespace('/de') do - error(AError) { body('methode nicht erlaubt'); 406} + error(AError) do + body('methode nicht erlaubt') + 406 + end get '/foo' do raise BError end end - } + end get('/en/foo').status.should == 401 last_response.body.should == 'auth failed' unless verb == :head get('/de/foo').status.should == 406 @@ -531,91 +550,83 @@ end end - describe 'templates' do - it "allows using templates from the base" do - mock_app do - template(:foo) { 'hi' } - send(verb, '/') { erb :foo } - namespace '/foo' do - send(verb) { erb :foo } + unless verb == :head + describe 'templates' do + specify 'default to the base app\'s template' do + mock_app do + template(:foo) { 'hi' } + send(verb, '/') { erb :foo } + namespace '/foo' do + send(verb) { erb :foo } + end end - end - if verb != :head - send(verb, '/').body.should == "hi" - send(verb, '/foo').body.should == "hi" + send(verb, '/').body.should == 'hi' + send(verb, '/foo').body.should == 'hi' end - end - it "allows to define nested templates" do - mock_app do - template(:foo) { 'hi' } - send(verb, '/') { erb :foo } - namespace '/foo' do - template(:foo) { 'ho' } - send(verb) { erb :foo } + specify 'can be nested' do + mock_app do + template(:foo) { 'hi' } + send(verb, '/') { erb :foo } + namespace '/foo' do + template(:foo) { 'ho' } + send(verb) { erb :foo } + end end - end - if verb != :head - send(verb, '/').body.should == "hi" - send(verb, '/foo').body.should == "ho" + send(verb, '/').body.should == 'hi' + send(verb, '/foo').body.should == 'ho' end - end - it "allows to define nested layouts" do - mock_app do - layout { 'Hello <%= yield %>!' } - template(:foo) { 'World' } - send(verb, '/') { erb :foo } - namespace '/foo' do - layout { 'Hi <%= yield %>!' } - send(verb) { erb :foo } + specify 'can use a custom views directory' do + mock_app do + set :views, File.expand_path('../namespace', __FILE__) + send(verb, '/') { erb :foo } + namespace('/foo') do + set :views, File.expand_path('../namespace/nested', __FILE__) + send(verb) { erb :foo } + end end - end - if verb != :head - send(verb, '/').body.should == "Hello World!" - send(verb, '/foo').body.should == "Hi World!" + send(verb, '/').body.should == "hi\n" + send(verb, '/foo').body.should == "ho\n" end - end - it "allows using templates from the base" do - mock_app do - layout { "he said: <%= yield %>" } - template(:foo) { 'hi' } - send(verb, '/') { erb :foo } - namespace '/foo' do - template(:foo) { 'ho' } - send(verb) { erb :foo } + specify 'default to the base app\'s layout' do + mock_app do + layout { 'he said: <%= yield %>' } + template(:foo) { 'hi' } + send(verb, '/') { erb :foo } + namespace '/foo' do + template(:foo) { 'ho' } + send(verb) { erb :foo } + end end - end - if verb != :head - send(verb, '/').body.should == "he said: hi" - send(verb, '/foo').body.should == "he said: ho" + send(verb, '/').body.should == 'he said: hi' + send(verb, '/foo').body.should == 'he said: ho' end - end - it "allows setting a different views directory" do - mock_app do - set :views, File.expand_path('../namespace', __FILE__) - send(verb, '/') { erb :foo } - namespace('/foo') do - set :views, File.expand_path('../namespace/nested', __FILE__) - send(verb) { erb :foo } + specify 'can define nested layouts' do + mock_app do + layout { 'Hello <%= yield %>!' } + template(:foo) { 'World' } + send(verb, '/') { erb :foo } + namespace '/foo' do + layout { 'Hi <%= yield %>!' } + send(verb) { erb :foo } + end end - end - if verb != :head - send(verb, '/').body.should == "hi\n" - send(verb, '/foo').body.should == "ho\n" + send(verb, '/').body.should == 'Hello World!' + send(verb, '/foo').body.should == 'Hi World!' end end end describe 'extensions' do - it 'allows read access to settings' do + specify 'provide read access to settings' do value = nil mock_app do set :foo, 42 @@ -626,9 +637,9 @@ value.should == 42 end - it 'allows registering extensions for a namespace only' do + specify 'can be registered within a namespace' do a = b = nil - extension = Module.new { define_method(:views) { "CUSTOM!!!" } } + extension = Module.new { define_method(:views) { 'CUSTOM!!!' } } mock_app do namespace '/' do register extension @@ -640,7 +651,7 @@ b.should_not == 'CUSTOM!!!' end - it 'triggers route_added hook' do + specify 'trigger the route_added hook' do route = nil extension = Module.new extension.singleton_class.class_eval do @@ -656,7 +667,7 @@ route[1].should == '/foo' end - it 'prevents changing app global settings' do + specify 'prevent app-global settings from being changed' do proc { namespace('/') { set :foo, :bar }}.should raise_error end end diff -Nru ruby-sinatra-contrib-1.3.2/spec/respond_with/baz.yajl ruby-sinatra-contrib-1.4.1/spec/respond_with/baz.yajl --- ruby-sinatra-contrib-1.3.2/spec/respond_with/baz.yajl 1970-01-01 00:00:00.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/spec/respond_with/baz.yajl 2013-08-29 10:22:25.000000000 +0000 @@ -0,0 +1 @@ +json = "yajl!" diff -Nru ruby-sinatra-contrib-1.3.2/spec/respond_with_spec.rb ruby-sinatra-contrib-1.4.1/spec/respond_with_spec.rb --- ruby-sinatra-contrib-1.3.2/spec/respond_with_spec.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/spec/respond_with_spec.rb 2013-08-29 10:22:25.000000000 +0000 @@ -1,4 +1,6 @@ require 'backports' +require 'multi_json' + require_relative 'spec_helper' require_relative 'okjson' @@ -226,6 +228,14 @@ req(:pdf).should be_ok body.should == "hi" end + + unless defined? JRUBY_VERSION + it 'uses yajl for json' do + respond_with :baz + req(:json).should be_ok + body.should == "\"yajl!\"" + end + end end describe 'customizing' do @@ -247,6 +257,23 @@ body.should == "generic!" end end + + describe "inherited" do + it "registers RespondWith in an inherited app" do + app = Sinatra.new do + set :app_file, __FILE__ + set :views, root + '/respond_with' + register Sinatra::RespondWith + + get '/a' do + respond_with :json + end + end + + self.app = Sinatra.new(app) + req('/a', :json).should_not be_ok + end + end end describe :respond_to do diff -Nru ruby-sinatra-contrib-1.3.2/spec/spec_helper.rb ruby-sinatra-contrib-1.4.1/spec/spec_helper.rb --- ruby-sinatra-contrib-1.3.2/spec/spec_helper.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/spec/spec_helper.rb 2013-08-29 10:22:25.000000000 +0000 @@ -1,6 +1,7 @@ +ENV['RACK_ENV'] = 'test' require 'sinatra/contrib' RSpec.configure do |config| - config.expect_with :rspec, :stdlib + config.expect_with :rspec#, :stdlib config.include Sinatra::TestHelpers end diff -Nru ruby-sinatra-contrib-1.3.2/spec/streaming_spec.rb ruby-sinatra-contrib-1.4.1/spec/streaming_spec.rb --- ruby-sinatra-contrib-1.3.2/spec/streaming_spec.rb 2013-03-14 21:44:50.000000000 +0000 +++ ruby-sinatra-contrib-1.4.1/spec/streaming_spec.rb 2013-08-29 10:22:25.000000000 +0000 @@ -62,27 +62,6 @@ end end - context EventMachine::Deferrable do - it 'allows attaching more than one callback' do - a = b = false - stream do |out| - out.callback { a = true } - out.callback { b = true } - end - a.should be_true - b.should be_true - end - - it 'triggers callbacks after streaming' do - triggered = false - stream do |out| - out.callback { triggered = true } - triggered.should be_false - end - triggered.should be_true - end - end - context 'app' do it 'is the app instance the stream was created from' do out = stream { }