Permalink
Browse files

Test for, and explicitly support, two-form call with existing options…

… hash
  • Loading branch information...
1 parent f1ff199 commit b48041c8e921ea338afaab6fcff7180d20859e26 @mpalmer mpalmer committed Mar 6, 2011
Showing with 17 additions and 0 deletions.
  1. +5 −0 lib/sinatra/url_for.rb
  2. +12 −0 spec/url_for_spec.rb
View
@@ -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
View
@@ -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

0 comments on commit b48041c

Please sign in to comment.