diff options
Diffstat (limited to 'railties/lib/rails/generators')
4 files changed, 7 insertions, 3 deletions
diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 7b527831b0..243694f38e 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -183,6 +183,10 @@ module Rails !defined?(ActiveRecord::Base) || ActiveRecord::Base.pluralize_table_names end + def mountable_engine? + defined?(ENGINE_ROOT) && namespaced? + end + # Add a class collisions name to be checked on class initialization. You # can supply a hash with a :prefix or :suffix to be tested. # diff --git a/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb b/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb index 7106096b60..5a8a3ca5e0 100644 --- a/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb +++ b/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb @@ -2,7 +2,7 @@ require 'test_helper' <% module_namespacing do -%> class <%= class_name %>ControllerTest < ActionController::TestCase -<% if defined?(ENGINE_ROOT) -%> +<% if mountable_engine? -%> setup do @routes = Engine.routes end 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 d634584beb..0171da7cc7 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb @@ -21,7 +21,7 @@ module TestUnit # :nodoc: def fixture_name @fixture_name ||= - if defined?(ENGINE_ROOT) + if mountable_engine? "%s_%s" % [namespaced_path, table_name] else table_name diff --git a/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb b/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb index d12a5ba733..50b98b2631 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb @@ -4,7 +4,7 @@ require 'test_helper' class <%= controller_class_name %>ControllerTest < ActionController::TestCase setup do @<%= singular_table_name %> = <%= fixture_name %>(:one) -<% if defined?(ENGINE_ROOT) -%> +<% if mountable_engine? -%> @routes = Engine.routes <% end -%> end |