aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/railties/mounted_engine_routes_test.rb
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 /railties/test/railties/mounted_engine_routes_test.rb
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 'railties/test/railties/mounted_engine_routes_test.rb')
-rw-r--r--railties/test/railties/mounted_engine_routes_test.rb31
1 files changed, 27 insertions, 4 deletions
diff --git a/railties/test/railties/mounted_engine_routes_test.rb b/railties/test/railties/mounted_engine_routes_test.rb
index 18789ab9e3..1a0f5f2c21 100644
--- a/railties/test/railties/mounted_engine_routes_test.rb
+++ b/railties/test/railties/mounted_engine_routes_test.rb
@@ -70,7 +70,7 @@ module ApplicationTests
end
def url_for_engine_route
- render :text => url_for(:controller => "posts", :action => "index", :user => "john", :only_path => true)
+ render :text => url_for(:controller => "posts", :action => "index", :user => "john", :only_path => true, :routes => Blog::Engine.routes)
end
end
RUBY
@@ -85,24 +85,47 @@ module ApplicationTests
end
end
+ def reset_script_name!
+ Rails.application.routes.default_url_options = {}
+ end
+
+ def script_name(script_name)
+ Rails.application.routes.default_url_options = {:script_name => script_name}
+ end
+
test "routes generation in engine and application" do
# test generating engine's route from engine
get "/john/blog/posts"
assert_equal "/john/blog/posts/1", last_response.body
+ # test generating engine's route from engine with default_url_options
+ script_name "/foo"
+ get "/john/blog/posts", {}, 'SCRIPT_NAME' => "/foo"
+ assert_equal "/foo/john/blog/posts/1", last_response.body
+ reset_script_name!
+
# test generating engine's route from application
get "/engine_route"
assert_equal "/anonymous/blog/posts", last_response.body
get "/url_for_engine_route"
assert_equal "/john/blog/posts", last_response.body
+ # test generating engine's route from application with default_url_options
+ script_name "/foo"
+ get "/engine_route", {}, 'SCRIPT_NAME' => "/foo"
+ assert_equal "/foo/anonymous/blog/posts", last_response.body
+ script_name "/foo"
+ get "/url_for_engine_route", {}, 'SCRIPT_NAME' => "/foo"
+ assert_equal "/foo/john/blog/posts", last_response.body
+ reset_script_name!
+
# test generating application's route from engine
get "/someone/blog/generate_application_route"
assert_equal "/", last_response.body
- # with script_name
- Rails.application.default_url_options = {:script_name => "/foo"}
- get "/someone/blog/generate_application_route", {}, "SCRIPT_NAME" => "/foo"
+ # test generating application's route from engine with default_url_options
+ script_name "/foo"
+ get "/someone/blog/generate_application_route", {}, 'SCRIPT_NAME' => '/foo'
assert_equal "/foo/", last_response.body
end
end