Skip to content

Commit

Permalink
Don't set the @_use_format variable if the provides method is called
Browse files Browse the repository at this point in the history
from inline

Fixes a test that has been skipped

Remove unused parameter
  • Loading branch information
namusyaka committed Sep 1, 2014
1 parent 0048193 commit 5804fd5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 17 additions & 5 deletions padrino-core/lib/padrino-core/application/routing.rb
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions padrino-core/test/test_routing.rb
Expand Up @@ -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'){}
Expand Down

0 comments on commit 5804fd5

Please sign in to comment.