Skip to content

Commit 3cd0530

Browse files
committed
Merge pull request rails#20724 from y-yagi/fix_scaffold_in_full_engine
fix NoMethodError that occurs when generating scaffold inside full mode engine
2 parents d4b0e5f + b1738e1 commit 3cd0530

File tree

7 files changed

+36
-3
lines changed

7 files changed

+36
-3
lines changed

railties/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Fix `NoMethodError` when generating a scaffold inside a full engine.
2+
3+
*Yuji Yaginuma*
4+
15
* Adding support for passing a block to the `add_source` action of a custom generator
26

37
*Mike Dalton*, *Hirofumi Wakasugi*

railties/lib/rails/generators/named_base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ def pluralize_table_names?
183183
!defined?(ActiveRecord::Base) || ActiveRecord::Base.pluralize_table_names
184184
end
185185

186+
def mountable_engine?
187+
defined?(ENGINE_ROOT) && namespaced?
188+
end
189+
186190
# Add a class collisions name to be checked on class initialization. You
187191
# can supply a hash with a :prefix or :suffix to be tested.
188192
#

railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<% module_namespacing do -%>
44
class <%= class_name %>ControllerTest < ActionController::TestCase
5-
<% if defined?(ENGINE_ROOT) -%>
5+
<% if mountable_engine? -%>
66
setup do
77
@routes = Engine.routes
88
end

railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def create_test_files
2121

2222
def fixture_name
2323
@fixture_name ||=
24-
if defined?(ENGINE_ROOT)
24+
if mountable_engine?
2525
"%s_%s" % [namespaced_path, table_name]
2626
else
2727
table_name

railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
55
setup do
66
@<%= singular_table_name %> = <%= fixture_name %>(:one)
7-
<% if defined?(ENGINE_ROOT) -%>
7+
<% if mountable_engine? -%>
88
@routes = Engine.routes
99
<% end -%>
1010
end

railties/test/generators/scaffold_controller_generator_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,17 @@ def test_controller_tests_pass_by_default_inside_mountable_engine
186186
end
187187
end
188188

189+
def test_controller_tests_pass_by_default_inside_full_engine
190+
Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --full` }
191+
192+
engine_path = File.join(destination_root, "bukkits")
193+
194+
Dir.chdir(engine_path) do
195+
quietly { `bin/rails g controller dashboard foo` }
196+
assert_match(/2 runs, 2 assertions, 0 failures, 0 errors/, `bundle exec rake test 2>&1`)
197+
end
198+
end
199+
189200
def test_api_only_generates_a_proper_api_controller
190201
run_generator ["User", "--api"]
191202

railties/test/generators/scaffold_generator_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,4 +491,18 @@ def test_scaffold_tests_pass_by_default_inside_mountable_engine
491491
assert_match(/8 runs, 13 assertions, 0 failures, 0 errors/, `bundle exec rake test 2>&1`)
492492
end
493493
end
494+
495+
def test_scaffold_tests_pass_by_default_inside_full_engine
496+
Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --full` }
497+
498+
engine_path = File.join(destination_root, "bukkits")
499+
500+
Dir.chdir(engine_path) do
501+
quietly do
502+
`bin/rails g scaffold User name:string age:integer;
503+
bundle exec rake db:migrate`
504+
end
505+
assert_match(/8 runs, 13 assertions, 0 failures, 0 errors/, `bundle exec rake test 2>&1`)
506+
end
507+
end
494508
end

0 commit comments

Comments
 (0)