aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2017-02-14 16:34:08 -0800
committerGitHub <noreply@github.com>2017-02-14 16:34:08 -0800
commit6e5e8bae227a8e3cb97d634196796bbd27b94c82 (patch)
tree35da5dfee06151b9bb49cc55bb0658c4e984e158
parente1a15859808147aad5237bdcdc90e50b1d1eaacf (diff)
parent4459a18db6fc9294d1f2553e45f59c859602dbad (diff)
downloadrails-6e5e8bae227a8e3cb97d634196796bbd27b94c82.tar.gz
rails-6e5e8bae227a8e3cb97d634196796bbd27b94c82.tar.bz2
rails-6e5e8bae227a8e3cb97d634196796bbd27b94c82.zip
Merge pull request #27605 from mtsmfm/fix-generator-command-for-nested-rails-engine-take-2
Fix generator command for nested (namespaced) rails engine (take 2)
-rw-r--r--railties/lib/rails/generators/named_base.rb8
-rw-r--r--railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb2
-rw-r--r--railties/test/generators/scaffold_generator_test.rb20
3 files changed, 27 insertions, 3 deletions
diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb
index 6f1925928b..02557b098a 100644
--- a/railties/lib/rails/generators/named_base.rb
+++ b/railties/lib/rails/generators/named_base.rb
@@ -82,6 +82,10 @@ module Rails
!options[:skip_namespace] && namespace
end
+ def namespace_dirs
+ @namespace_dirs ||= namespace.name.split("::").map(&:underscore)
+ end
+
def file_path # :doc:
@file_path ||= (class_path + [file_name]).join("/")
end
@@ -95,11 +99,11 @@ module Rails
end
def namespaced_class_path # :doc:
- @namespaced_class_path ||= [namespaced_path] + @class_path
+ @namespaced_class_path ||= namespace_dirs + @class_path
end
def namespaced_path # :doc:
- @namespaced_path ||= namespace.name.split("::").first.underscore
+ @namespaced_path ||= namespace_dirs.join("/")
end
def class_name # :doc:
diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
index 8840a86d0d..292db35121 100644
--- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
@@ -22,7 +22,7 @@ module TestUnit # :nodoc:
def fixture_name
@fixture_name ||=
if mountable_engine?
- "%s_%s" % [namespaced_path, table_name]
+ (namespace_dirs + [table_name]).join("_")
else
table_name
end
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index 6b7e2c91d7..e2b2acab0f 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -492,6 +492,26 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
end
end
+ def test_scaffold_tests_pass_by_default_inside_namespaced_mountable_engine
+ Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits-admin --mountable` }
+
+ engine_path = File.join(destination_root, "bukkits-admin")
+
+ Dir.chdir(engine_path) do
+ quietly do
+ `bin/rails g scaffold User name:string age:integer;
+ bin/rails db:migrate`
+ end
+
+ assert_file "bukkits-admin/app/controllers/bukkits/admin/users_controller.rb" do |content|
+ assert_match(/module Bukkits::Admin/, content)
+ assert_match(/class UsersController < ApplicationController/, content)
+ end
+
+ assert_match(/8 runs, 10 assertions, 0 failures, 0 errors/, `bin/rails test 2>&1`)
+ end
+ end
+
def test_scaffold_tests_pass_by_default_inside_full_engine
Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --full` }