Permalink
Browse files

Merge pull request #12699 from drogus/fix-mounting-engine-in-resources

Fix mounting engines inside a resources block
  • Loading branch information...
2 parents b5c5121 + e6c602d commit 308f37f94ddec2d2d37519ea751c70128c2a0e6b @drogus drogus committed Dec 10, 2013
View
@@ -1,3 +1,7 @@
+* Fix generating a path for engine inside a resources block (#8533)
+
+ *Piotr Sarnacki*
+
* Add Mime::Type.register "text/vcard", :vcf to the default list of mime types
*DHH*
@@ -502,11 +502,12 @@ def mount(app, options = nil)
raise "A rack application must be specified" unless path
options[:as] ||= app_name(app)
+ target_as = name_for_action(options[:as], path)
options[:via] ||= :all
match(path, options.merge(:to => app, :anchor => false, :format => false))
- define_generate_prefix(app, options[:as])
+ define_generate_prefix(app, target_as)
self
end
@@ -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 @@ def self.call(env)
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

0 comments on commit 308f37f

Please sign in to comment.