Skip to content
Browse files

Generators fix: properly check if module should be created when creat…

…ing a namespaced model

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent fb08e33 commit 00aa13bc0e3fdcc92152e22cc48a6d8bd21122ae @drogus drogus committed with josevalim Sep 24, 2010
View
2 activerecord/lib/rails/generators/active_record/model/model_generator.rb
@@ -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
View
6 railties/lib/rails/generators/named_base.rb
@@ -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
View
5 railties/test/generators/namespaced_generators_test.rb
@@ -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/

0 comments on commit 00aa13b

Please sign in to comment.
Something went wrong with that request. Please try again.