aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorNicholas Seckar <nseckar@gmail.com>2006-09-06 22:21:36 +0000
committerNicholas Seckar <nseckar@gmail.com>2006-09-06 22:21:36 +0000
commit00685ad8fdc9f15d935aebe52597037f3ca93be8 (patch)
treebf1298623047c9b5f3262bd0db651c92318a726b /actionpack
parent93659978d50cd95936f81f38a57028cc68a235ee (diff)
downloadrails-00685ad8fdc9f15d935aebe52597037f3ca93be8.tar.gz
rails-00685ad8fdc9f15d935aebe52597037f3ca93be8.tar.bz2
rails-00685ad8fdc9f15d935aebe52597037f3ca93be8.zip
Update UrlWriter to support :only_path.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5054 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/url_rewriter.rb17
-rw-r--r--actionpack/test/controller/url_rewriter_test.rb26
3 files changed, 37 insertions, 8 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index f1a8b581cd..063e407210 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Update UrlWriter to support :only_path. [Nicholas Seckar, Dave Thomas]
+
* Fixed JavaScriptHelper#link_to_function and JavaScriptHelper#button_to_function to have the script argument be optional [DHH]. So what used to require a nil, like this:
link_to("Hider", nil, :class => "hider_link") { |p| p[:something].hide }
diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb
index 4735d03035..0a5aab14d1 100644
--- a/actionpack/lib/action_controller/url_rewriter.rb
+++ b/actionpack/lib/action_controller/url_rewriter.rb
@@ -40,13 +40,18 @@ module ActionController
def url_for(options)
options = self.class.default_url_options.merge(options)
- raise "Missing host to link to! Please provide :host parameter or set default_url_options[:host]" unless options[:host]
-
url = ''
- url << (options.delete(:protocol) || 'http')
- url << '://'
- url << options.delete(:host)
- url << ":#{options.delete(:port)}" if options.key?(:port)
+ unless options.delete :only_path
+ url << (options.delete(:protocol) || 'http')
+ url << '://'
+
+ raise "Missing host to link to! Please provide :host parameter or set default_url_options[:host]" unless options[:host]
+ url << options.delete(:host)
+ url << ":#{options.delete(:port)}" if options.key?(:port)
+ else
+ # Delete the unused options to prevent their appearance in the query string
+ [:protocol, :host, :port].each { |k| options.delete k }
+ end
url << Routing::Routes.generate(options, {})
return url
end
diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb
index f71f79db47..53cd278b6b 100644
--- a/actionpack/test/controller/url_rewriter_test.rb
+++ b/actionpack/test/controller/url_rewriter_test.rb
@@ -84,10 +84,32 @@ class UrlWriterTests < Test::Unit::TestCase
# We need to create a new class in order to install the new named route.
kls = Class.new { include ActionController::UrlWriter }
- assert kls.new.respond_to?(:home_url)
+ controller = kls.new
+ assert controller.respond_to?(:home_url)
assert_equal 'http://www.basecamphq.com/home/sweet/home/again',
- kls.new.send(:home_url, :host => 'www.basecamphq.com', :user => 'again')
+ controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again')
+
+ assert_equal("/home/sweet/home/alabama", controller.send(:home_path, :user => 'alabama', :host => 'unused'))
ensure
ActionController::Routing::Routes.load!
end
+
+ def test_only_path
+ ActionController::Routing::Routes.draw do |map|
+ map.home '/home/sweet/home/:user'
+ map.connect ':controller/:action/:id'
+ end
+
+ # We need to create a new class in order to install the new named route.
+ kls = Class.new { include ActionController::UrlWriter }
+ controller = kls.new
+ assert controller.respond_to?(:home_url)
+ assert_equal '/brave/new/world',
+ controller.send(:url_for, :controller => 'brave', :action => 'new', :id => 'world', :only_path => true)
+
+ assert_equal("/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'unused', :only_path => true))
+ ensure
+ ActionController::Routing::Routes.load!
+ end
+
end