Merge pull request #14195 from robin850/issue-14079

Avoid namespacing routes inside engines
This commit is contained in:
Guillermo Iguaran 2014-02-28 19:26:04 -05:00
commit b0767afac5
3 changed files with 23 additions and 2 deletions

View File

@ -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.

View File

@ -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

View File

@ -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)