diff --git a/lib/sinatra/url_for.rb b/lib/sinatra/url_for.rb index b32631b..02a84d3 100644 --- a/lib/sinatra/url_for.rb +++ b/lib/sinatra/url_for.rb @@ -25,6 +25,11 @@ module UrlForHelper # See README.rdoc for a list of some of the people who helped me clean # up earlier versions of this code. def url_for url_fragment, mode=nil, options = nil + if mode.is_a? Hash + options = mode + mode = nil + end + if mode.nil? mode = :path_only end diff --git a/spec/url_for_spec.rb b/spec/url_for_spec.rb index 5f1e8e2..77855c4 100644 --- a/spec/url_for_spec.rb +++ b/spec/url_for_spec.rb @@ -13,6 +13,11 @@ url_for params[:url], params[:mode], params[:options] end +get "/nomode" do + content_type "text/plain" + url_for params[:url], params[:options] +end + describe Sinatra::UrlForHelper do include Rack::Test::Methods @@ -68,4 +73,11 @@ def app last_response.should be_ok last_response.body.should == "/foo?return_to=http%3A%2F%2Fexample.com%2Fbar%3Fx%3Dy" 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