aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/url_generation_test.rb
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-03-04 21:59:42 -0800
committerCarl Lerche <carllerche@mac.com>2010-03-04 22:00:30 -0800
commit9a17416d8bda0df0a6961e547c3cf1d677e66b5e (patch)
tree4c6dba8298cc9f1e1224521edc696e66aeda82f9 /actionpack/test/dispatch/url_generation_test.rb
parent48672cd1997618f21f50e1204e60dc681e647ddb (diff)
downloadrails-9a17416d8bda0df0a6961e547c3cf1d677e66b5e.tar.gz
rails-9a17416d8bda0df0a6961e547c3cf1d677e66b5e.tar.bz2
rails-9a17416d8bda0df0a6961e547c3cf1d677e66b5e.zip
Tweak out url_for uses :script_name and add some tests
Diffstat (limited to 'actionpack/test/dispatch/url_generation_test.rb')
-rw-r--r--actionpack/test/dispatch/url_generation_test.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/url_generation_test.rb b/actionpack/test/dispatch/url_generation_test.rb
new file mode 100644
index 0000000000..b55e001fa7
--- /dev/null
+++ b/actionpack/test/dispatch/url_generation_test.rb
@@ -0,0 +1,58 @@
+require 'abstract_unit'
+
+module TestUrlGeneration
+ class WithoutMountpoint < ActiveSupport::TestCase
+ setup do
+ app = lambda { |env| [200, {}, "Hello"] }
+ @router = ActionDispatch::Routing::RouteSet.new
+ @router.draw do
+ match "/foo", :to => app, :as => :foo
+ end
+
+ singleton_class.send(:include, @router.url_helpers)
+ end
+
+ test "generating URLS normally" do
+ assert_equal "/foo", foo_path
+ end
+
+ test "accepting a :script_name option" do
+ assert_equal "/bar/foo", foo_path(:script_name => "/bar")
+ end
+ end
+
+ class WithMountPoint < ActionDispatch::IntegrationTest
+ Router = ActionDispatch::Routing::RouteSet.new(:mount_point => "/baz")
+ Router.draw { match "/foo", :to => "my_route_generating#index", :as => :foo }
+
+ class ::MyRouteGeneratingController < ActionController::Base
+ include Router.url_helpers
+ def index
+ render :text => foo_path
+ end
+ end
+
+ include Router.url_helpers
+
+ def _router
+ Router
+ end
+
+ def app
+ Router
+ end
+
+ test "using the default :script_name option" do
+ assert_equal "/baz/foo", foo_path
+ end
+
+ test "overriding the default :script_name option" do
+ assert_equal "/bar/foo", foo_path(:script_name => "/bar")
+ end
+
+ test "the request's SCRIPT_NAME takes precedence over the router's" do
+ get "/foo", {}, 'SCRIPT_NAME' => "/new"
+ assert_equal "/new/foo", response.body
+ end
+ end
+end \ No newline at end of file