From 5804fd599c9495723f6cac1ac62352bd1220432e Mon Sep 17 00:00:00 2001 From: namusyaka Date: Mon, 1 Sep 2014 11:37:38 +0900 Subject: [PATCH] Don't set the @_use_format variable if the provides method is called from inline Fixes a test that has been skipped Remove unused parameter --- .../lib/padrino-core/application/routing.rb | 22 ++++++++++++++----- padrino-core/test/test_routing.rb | 2 -- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/padrino-core/lib/padrino-core/application/routing.rb b/padrino-core/lib/padrino-core/application/routing.rb index bc5213599..d838e7f0c 100644 --- a/padrino-core/lib/padrino-core/application/routing.rb +++ b/padrino-core/lib/padrino-core/application/routing.rb @@ -517,7 +517,15 @@ def route(verb, path, *args, &block) end # Add Sinatra conditions. - options.each{ |option, _args| route.respond_to?(option) ? route.send(option, *_args) : send(option, *_args) } + options.each do |option, _args| + if route.respond_to?(option) + route.send(option, *_args) + else + _args = Array(_args) + _args << true if option == :provides + send(option, *_args) + end + end conditions, @conditions = @conditions, [] route.custom_conditions.concat(conditions) @@ -576,8 +584,8 @@ def parse_route(path, options, verb) options.delete(:accepts) if options[:accepts].nil? - if @_use_format or format_params = options[:provides] - process_path_for_provides(path, format_params) + if @_use_format || options[:provides] + process_path_for_provides(path) # options[:add_match_with] ||= {} # options[:add_match_with][:format] = /[^\.]+/ end @@ -655,7 +663,7 @@ def process_path_for_parent_params(path, parent_params) # Processes the existing path and appends the 'format' suffix onto the route. # Used for calculating path in route method. # - def process_path_for_provides(path, format_params) + def process_path_for_provides(path) path << "(.:format)" unless path[-10, 10] == '(.:format)' end @@ -687,7 +695,11 @@ def process_path_for_provides(path, format_params) # # => GET /c.xml => 406 # def provides(*types) - @_use_format = true + if types.last.instance_of?(TrueClass) + types.pop + else + @_use_format = true + end mime_types = types.map{ |type| mime_type(CONTENT_TYPE_ALIASES[type] || type) } condition do return provides_format?(types, params[:format].to_sym) if params[:format] diff --git a/padrino-core/test/test_routing.rb b/padrino-core/test/test_routing.rb index a64cf9469..ce62e6edf 100644 --- a/padrino-core/test/test_routing.rb +++ b/padrino-core/test/test_routing.rb @@ -1824,8 +1824,6 @@ def authorize(username, password) end it 'should reset provides for routes that did not use it' do - skip - #FIXME mock_app do get('/foo', :provides => :js){} get('/bar'){}