Skip to content

Commit 308f37f

Browse files
committed
Merge pull request rails#12699 from drogus/fix-mounting-engine-in-resources
Fix mounting engines inside a resources block
2 parents b5c5121 + e6c602d commit 308f37f

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

actionpack/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Fix generating a path for engine inside a resources block (#8533)
2+
3+
*Piotr Sarnacki*
4+
15
* Add Mime::Type.register "text/vcard", :vcf to the default list of mime types
26

37
*DHH*

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,11 +502,12 @@ def mount(app, options = nil)
502502
raise "A rack application must be specified" unless path
503503

504504
options[:as] ||= app_name(app)
505+
target_as = name_for_action(options[:as], path)
505506
options[:via] ||= :all
506507

507508
match(path, options.merge(:to => app, :anchor => false, :format => false))
508509

509-
define_generate_prefix(app, options[:as])
510+
define_generate_prefix(app, target_as)
510511
self
511512
end
512513

actionpack/test/dispatch/mount_test.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TestRoutingMount < ActionDispatch::IntegrationTest
55

66
class FakeEngine
77
def self.routes
8-
Object.new
8+
@routes ||= ActionDispatch::Routing::RouteSet.new
99
end
1010

1111
def self.call(env)
@@ -27,12 +27,23 @@ def self.call(env)
2727
scope "/its_a" do
2828
mount SprocketsApp, :at => "/sprocket"
2929
end
30+
31+
resources :users do
32+
mount FakeEngine, :at => "/fakeengine", :as => :fake_mounted_at_resource
33+
end
3034
end
3135

3236
def app
3337
Router
3438
end
3539

40+
def test_app_name_is_properly_generated_when_engine_is_mounted_in_resources
41+
assert Router.mounted_helpers.method_defined?(:user_fake_mounted_at_resource),
42+
"A mounted helper should be defined with a parent's prefix"
43+
assert Router.named_routes.routes[:user_fake_mounted_at_resource],
44+
"A named route should be defined with a parent's prefix"
45+
end
46+
3647
def test_trailing_slash_is_not_removed_from_path_info
3748
get "/sprockets/omg/"
3849
assert_equal "/sprockets -- /omg/", response.body

0 commit comments

Comments
 (0)