Permalink
Browse files

Avoid namespacing routes inside engines

Since #11544, invoking the controller generator, any generated route is
namespaced according to the class_path method. Since a mountable plugin
is namespaced, creating a controller inside would generate a namespaced
route based on the engine's name.

The controller generator now relies on regular_class_path which does not
contain the class hierarchy but the given path.

Fixes #14079.
  • Loading branch information...
robin850 committed Feb 25, 2014
1 parent 6d35190 commit fc61bca31d899f359671d4b58bceb8b9d6555aa7
View
@@ -1 +1,10 @@
+* Avoid namespacing routes inside engines.
+
+ Mountable engines are namespaced by default so the generated routes
+ were too while they should not.
+
+ Fixes #14079.
+
+ *Yves Senn*, *Carlos Antonio da Silva*, *Robin Dupret*
+
Please check [4-1-stable](https://github.com/rails/rails/blob/4-1-stable/railties/CHANGELOG.md) for previous changes.
@@ -27,11 +27,11 @@ def add_routes
# end
# end
def generate_routing_code(action)
- depth = class_path.length
+ depth = regular_class_path.length
# Create 'namespace' ladder
# namespace :foo do
# namespace :bar do
- namespace_ladder = class_path.each_with_index.map do |ns, i|
+ namespace_ladder = regular_class_path.each_with_index.map do |ns, i|
indent("namespace :#{ns} do\n", i * 2)
end.join
@@ -355,6 +355,18 @@ def test_skipping_gemfile_entry
FileUtils.rm gemfile_path
end
+ def test_generating_controller_inside_mountable_engine
+ run_generator [destination_root, "--mountable"]
+
+ capture(:stdout) do
+ `#{destination_root}/bin/rails g controller admin/dashboard foo`
+ end
+
+ assert_file "config/routes.rb" do |contents|
+ assert_match(/namespace :admin/, contents)
+ assert_no_match(/namespace :bukkit/, contents)
+ end
+ end
protected
def action(*args, &block)

0 comments on commit fc61bca

Please sign in to comment.