diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2013-10-30 12:05:13 +0100 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2013-12-10 21:38:41 +0100 |
commit | e6c602da9046a653747ce99c9cab7f08f572fa40 (patch) | |
tree | 4c1e831fca000ef772ddbac9f8e26df1c89f1323 /actionpack/test | |
parent | b5c5121f67c88a2be1c56e810f5c64013351ce79 (diff) | |
download | rails-e6c602da9046a653747ce99c9cab7f08f572fa40.tar.gz rails-e6c602da9046a653747ce99c9cab7f08f572fa40.tar.bz2 rails-e6c602da9046a653747ce99c9cab7f08f572fa40.zip |
Fix mounting engines inside a resources block
When a route is mounted inside a resources block, it's automatically
prefixed, so a following code:
resources :users do
mount Blog::Engine => '/blog'
end
will generate a user_blog path helper.
In order to access engine helpers, we also use "mounted_helpers", a list
of helpers associated with each mounted engine, so a path to blog's post
can be generated using user_blog.post_path(user, post).
The problem I'm fixing here is that mount used a raw :as option, without
taking nestings into account. As a result, blog was added to a route set
as a `user_blog`, but helper was generated for just `blog`.
This commit applies the proper logic for defining a helper for a mounted
engine nested in resources or resource block.
(closes #8533)
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/dispatch/mount_test.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/actionpack/test/dispatch/mount_test.rb b/actionpack/test/dispatch/mount_test.rb index 30e95a0b75..683a4f01e2 100644 --- a/actionpack/test/dispatch/mount_test.rb +++ b/actionpack/test/dispatch/mount_test.rb @@ -5,7 +5,7 @@ class TestRoutingMount < ActionDispatch::IntegrationTest class FakeEngine def self.routes - Object.new + @routes ||= ActionDispatch::Routing::RouteSet.new end def self.call(env) @@ -27,12 +27,23 @@ class TestRoutingMount < ActionDispatch::IntegrationTest scope "/its_a" do mount SprocketsApp, :at => "/sprocket" end + + resources :users do + mount FakeEngine, :at => "/fakeengine", :as => :fake_mounted_at_resource + end end def app Router end + def test_app_name_is_properly_generated_when_engine_is_mounted_in_resources + assert Router.mounted_helpers.method_defined?(:user_fake_mounted_at_resource), + "A mounted helper should be defined with a parent's prefix" + assert Router.named_routes.routes[:user_fake_mounted_at_resource], + "A named route should be defined with a parent's prefix" + end + def test_trailing_slash_is_not_removed_from_path_info get "/sprockets/omg/" assert_equal "/sprockets -- /omg/", response.body |