提交 00aa13bc 编写于 作者: P Piotr Sarnacki 提交者: José Valim

Generators fix: properly check if module should be created when creating a namespaced model

Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 fb08e334
......@@ -21,7 +21,7 @@ def create_model_file
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 @@ def file_path
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/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册