mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Generators fix: properly check if module should be created when creating a namespaced model
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
committed by
José Valim
parent
fb08e334d6
commit
00aa13bc0e
@@ -21,7 +21,7 @@ module ActiveRecord
|
||||
end
|
||||
|
||||
def create_module_file
|
||||
return if class_path.empty?
|
||||
return if regular_class_path.empty?
|
||||
template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke
|
||||
end
|
||||
|
||||
|
||||
@@ -66,7 +66,11 @@ module Rails
|
||||
end
|
||||
|
||||
def class_path
|
||||
inside_namespace? || !namespaced? ? @class_path : namespaced_class_path
|
||||
inside_namespace? || !namespaced? ? regular_class_path : namespaced_class_path
|
||||
end
|
||||
|
||||
def regular_class_path
|
||||
@class_path
|
||||
end
|
||||
|
||||
def namespaced_class_path
|
||||
|
||||
@@ -73,6 +73,11 @@ class NamespacedModelGeneratorTest < NamespacedGeneratorTestCase
|
||||
arguments %w(Account name:string age:integer)
|
||||
tests Rails::Generators::ModelGenerator
|
||||
|
||||
def test_module_file_is_not_created
|
||||
run_generator
|
||||
assert_no_file "app/models/test_app.rb"
|
||||
end
|
||||
|
||||
def test_adds_namespace_to_model
|
||||
run_generator
|
||||
assert_file "app/models/test_app/account.rb", /module TestApp/, / class Account < ActiveRecord::Base/
|
||||
|
||||
Reference in New Issue
Block a user