aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2013-05-03 16:42:31 +0200
committerPiotr Sarnacki <drogus@gmail.com>2013-05-03 18:15:40 +0200
commit9a4268db99d93190c58bddcb150832727a0d5129 (patch)
treefc45c239e93bbac8396c4566325bd663eb8cc980 /railties/test
parentf1af9f83757278f5f852f9c747dd367f1a591833 (diff)
downloadrails-9a4268db99d93190c58bddcb150832727a0d5129.tar.gz
rails-9a4268db99d93190c58bddcb150832727a0d5129.tar.bz2
rails-9a4268db99d93190c58bddcb150832727a0d5129.zip
Fix generating route from engine to other engine
A regression was introduced in 5b3bb6, generating route from within an engine to an another engine resulted in prefixing a path with the SCRIPT_NAME value. The regression was caused by the fact that SCRIPT_NAME should be appended only if it's the SCRIPT_NAME for the application, not if it's SCRIPT_NAME from the current engine. closes #10409
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/railties/mounted_engine_test.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/railties/test/railties/mounted_engine_test.rb b/railties/test/railties/mounted_engine_test.rb
index 80559a6e36..c94937f964 100644
--- a/railties/test/railties/mounted_engine_test.rb
+++ b/railties/test/railties/mounted_engine_test.rb
@@ -13,6 +13,7 @@ module ApplicationTests
@simple_plugin = engine "weblog"
@plugin = engine "blog"
+ @metrics_plugin = engine "metrics"
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
@@ -28,6 +29,7 @@ module ApplicationTests
scope "/:user", :user => "anonymous" do
mount Blog::Engine => "/blog"
end
+ mount Metrics::Engine => "/metrics"
root :to => 'main#index'
end
RUBY
@@ -54,6 +56,34 @@ module ApplicationTests
end
RUBY
+ @metrics_plugin.write "lib/metrics.rb", <<-RUBY
+ module Metrics
+ class Engine < ::Rails::Engine
+ isolate_namespace(Metrics)
+ end
+ end
+ RUBY
+
+ @metrics_plugin.write "config/routes.rb", <<-RUBY
+ Metrics::Engine.routes.draw do
+ get '/generate_blog_route', to: 'generating#generate_blog_route'
+ get '/generate_blog_route_in_view', to: 'generating#generate_blog_route_in_view'
+ end
+ RUBY
+
+ @metrics_plugin.write "app/controllers/metrics/generating_controller.rb", <<-RUBY
+ module Metrics
+ class GeneratingController < ActionController::Base
+ def generate_blog_route
+ render text: blog.post_path(1)
+ end
+
+ def generate_blog_route_in_view
+ render inline: "<%= blog.post_path(1) -%>"
+ end
+ end
+ end
+ RUBY
@plugin.write "app/models/blog/post.rb", <<-RUBY
module Blog
@@ -201,6 +231,21 @@ module ApplicationTests
get "/somone/blog/application_route_in_view"
assert_equal "/", last_response.body
+ # test generating engine's route from other engine
+ get "/metrics/generate_blog_route"
+ assert_equal '/anonymous/blog/posts/1', last_response.body
+
+ get "/metrics/generate_blog_route_in_view"
+ assert_equal '/anonymous/blog/posts/1', last_response.body
+
+ # test generating engine's route from other engine with default_url_options
+ get "/metrics/generate_blog_route", {}, 'SCRIPT_NAME' => '/foo'
+ assert_equal '/foo/anonymous/blog/posts/1', last_response.body
+
+ get "/metrics/generate_blog_route_in_view", {}, 'SCRIPT_NAME' => '/foo'
+ assert_equal '/foo/anonymous/blog/posts/1', last_response.body
+
+
# test generating application's route from engine with default_url_options
get "/someone/blog/generate_application_route", {}, 'SCRIPT_NAME' => '/foo'
assert_equal "/foo/", last_response.body