Skip to content

Commit

Permalink
Test for, and explicitly support, two-form call with existing options…
Browse files Browse the repository at this point in the history
… hash
  • Loading branch information
mpalmer committed Mar 6, 2011
1 parent f1ff199 commit b48041c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/sinatra/url_for.rb
Expand Up @@ -25,6 +25,11 @@ module UrlForHelper
# See README.rdoc for a list of some of the people who helped me clean # See README.rdoc for a list of some of the people who helped me clean
# up earlier versions of this code. # up earlier versions of this code.
def url_for url_fragment, mode=nil, options = nil def url_for url_fragment, mode=nil, options = nil
if mode.is_a? Hash
options = mode
mode = nil
end

if mode.nil? if mode.nil?
mode = :path_only mode = :path_only
end end
Expand Down
12 changes: 12 additions & 0 deletions spec/url_for_spec.rb
Expand Up @@ -13,6 +13,11 @@
url_for params[:url], params[:mode], params[:options] url_for params[:url], params[:mode], params[:options]
end end


get "/nomode" do
content_type "text/plain"
url_for params[:url], params[:options]
end

describe Sinatra::UrlForHelper do describe Sinatra::UrlForHelper do
include Rack::Test::Methods include Rack::Test::Methods


Expand Down Expand Up @@ -68,4 +73,11 @@ def app
last_response.should be_ok last_response.should be_ok
last_response.body.should == "/foo?return_to=http%3A%2F%2Fexample.com%2Fbar%3Fx%3Dy" last_response.body.should == "/foo?return_to=http%3A%2F%2Fexample.com%2Fbar%3Fx%3Dy"
end end

it "should handle not being passed a mode" do
get "/nomode", :url => "/foo", :options => { :x => "y" }

last_response.should be_ok
last_response.body.should == "/foo?x=y"
end
end end

0 comments on commit b48041c

Please sign in to comment.