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:
Piotr Sarnacki
2010-09-24 21:54:16 +02:00
committed by José Valim
parent fb08e334d6
commit 00aa13bc0e
3 changed files with 11 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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/