aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorRobin Dupret <robin.dupret@gmail.com>2014-02-25 14:57:23 +0100
committerRobin Dupret <robin.dupret@gmail.com>2014-02-26 16:06:11 +0100
commitfc61bca31d899f359671d4b58bceb8b9d6555aa7 (patch)
treed1377c903e19bd68f5fddcbde1cbd9f47ab90c06 /railties
parent6d35190bad0b054c9a1f4c736dc4dda32a7ebc91 (diff)
downloadrails-fc61bca31d899f359671d4b58bceb8b9d6555aa7.tar.gz
rails-fc61bca31d899f359671d4b58bceb8b9d6555aa7.tar.bz2
rails-fc61bca31d899f359671d4b58bceb8b9d6555aa7.zip
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.
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG.md9
-rw-r--r--railties/lib/rails/generators/rails/controller/controller_generator.rb4
-rw-r--r--railties/test/generators/plugin_generator_test.rb12
3 files changed, 23 insertions, 2 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 18f2546c73..9dce38fc93 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -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.
diff --git a/railties/lib/rails/generators/rails/controller/controller_generator.rb b/railties/lib/rails/generators/rails/controller/controller_generator.rb
index 33a0d81bf6..7588a558e7 100644
--- a/railties/lib/rails/generators/rails/controller/controller_generator.rb
+++ b/railties/lib/rails/generators/rails/controller/controller_generator.rb
@@ -27,11 +27,11 @@ module Rails
# 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
diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb
index 932cd75bcb..b2fc3a2a4f 100644
--- a/railties/test/generators/plugin_generator_test.rb
+++ b/railties/test/generators/plugin_generator_test.rb
@@ -355,6 +355,18 @@ class PluginGeneratorTest < Rails::Generators::TestCase
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)