aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2010-07-09 10:25:10 +0200
committerPiotr Sarnacki <drogus@gmail.com>2010-09-03 22:59:06 +0200
commitb697ba9fd72ac8701747863b42082e59f13ba678 (patch)
treeb89e392dbfccd29a7fc2d6c0d877503a96a4f016 /actionpack/test/dispatch
parent8a077089d9b7aa89cb56ef754b4540f411453375 (diff)
downloadrails-b697ba9fd72ac8701747863b42082e59f13ba678.tar.gz
rails-b697ba9fd72ac8701747863b42082e59f13ba678.tar.bz2
rails-b697ba9fd72ac8701747863b42082e59f13ba678.zip
Added some more tests for url generation between Engine and Application
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r--actionpack/test/dispatch/prefix_generation_test.rb38
1 files changed, 28 insertions, 10 deletions
diff --git a/actionpack/test/dispatch/prefix_generation_test.rb b/actionpack/test/dispatch/prefix_generation_test.rb
index 6ceb07a4f1..af83ced5e9 100644
--- a/actionpack/test/dispatch/prefix_generation_test.rb
+++ b/actionpack/test/dispatch/prefix_generation_test.rb
@@ -11,7 +11,7 @@ module TestGenerationPrefix
routes = ActionDispatch::Routing::RouteSet.new
routes.draw do
match "/posts/:id", :to => "inside_engine_generating#index", :as => :post
- match "/bare_url_for", :to => "inside_engine_generating#bare_url_for", :as => :bare_url_for
+ match "/url_to_application", :to => "inside_engine_generating#url_to_application"
end
routes
@@ -42,10 +42,6 @@ module TestGenerationPrefix
def self.call(env)
env['action_dispatch.routes'] = routes
-
- # the next to values should be set only in application
- env['ORIGINAL_SCRIPT_NAME'] = env['SCRIPT_NAME']
- env['action_dispatch.parent_routes'] = routes
routes.call(env)
end
end
@@ -56,7 +52,7 @@ module TestGenerationPrefix
render :text => post_path(:id => params[:id])
end
- def bare_url_for
+ def url_to_application
path = url_for( :routes => RailsApplication.routes,
:controller => "outside_engine_generating",
:action => "index",
@@ -111,12 +107,23 @@ module TestGenerationPrefix
end
test "prepend prefix outside the engine" do
+ get "/generate"
+ assert_equal "/awesome/blog/posts/1", last_response.body
+ end
+
+ test "prepend prefix outside the engine and use default_url_options[:script_name]" do
+ RailsApplication.routes.default_url_options = {:script_name => "/something"}
+ get "/generate"
+ assert_equal "/something/awesome/blog/posts/1", last_response.body
+ end
+
+ test "give higher priority to default_url_options[:script_name]" do
RailsApplication.routes.default_url_options = {:script_name => "/something"}
- get "/generate", {}, 'SCRIPT_NAME' => "/something"
+ get "/generate", {}, 'SCRIPT_NAME' => "/foo"
assert_equal "/something/awesome/blog/posts/1", last_response.body
end
- test "generating urls with options for both prefix and named_route" do
+ test "generating urls with options for prefix and named_route" do
assert_equal "/pure-awesomness/blog/posts/3", post_path(:id => 3, :omg => "pure-awesomness")
end
@@ -129,9 +136,20 @@ module TestGenerationPrefix
assert_equal "/awesome/blog/posts/42", Foo.new.foo
end
- test "passing :routes to url_for to change current routes" do
+ test "generating application's url from engine" do
+ get "/pure-awesomness/blog/url_to_application"
+ assert_equal "/generate", last_response.body
+ end
+
+ test "generating application's url from engine with default_url_options[:script_name]" do
+ RailsApplication.routes.default_url_options = {:script_name => "/something"}
+ get "/pure-awesomness/blog/url_to_application"
+ assert_equal "/something/generate", last_response.body
+ end
+
+ test "generating application's url from engine should give higher priority to default_url_options[:script_name]" do
RailsApplication.routes.default_url_options = {:script_name => "/something"}
- get "/pure-awesomness/blog/bare_url_for", {}, 'SCRIPT_NAME' => "/something"
+ get "/pure-awesomness/blog/url_to_application", {}, 'SCRIPT_NAME' => '/foo'
assert_equal "/something/generate", last_response.body
end