diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-09-24 21:54:16 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-09-25 10:46:22 +0200 |
commit | 00aa13bc0e3fdcc92152e22cc48a6d8bd21122ae (patch) | |
tree | 697afb805c5ca1e0186b09357ad49071a717944b | |
parent | fb08e334d61b1706db754733b209075b0154b57e (diff) | |
download | rails-00aa13bc0e3fdcc92152e22cc48a6d8bd21122ae.tar.gz rails-00aa13bc0e3fdcc92152e22cc48a6d8bd21122ae.tar.bz2 rails-00aa13bc0e3fdcc92152e22cc48a6d8bd21122ae.zip |
Generators fix: properly check if module should be created when creating a namespaced model
Signed-off-by: José Valim <jose.valim@gmail.com>
3 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/lib/rails/generators/active_record/model/model_generator.rb b/activerecord/lib/rails/generators/active_record/model/model_generator.rb index 960c29c49c..c75abd043c 100644 --- a/activerecord/lib/rails/generators/active_record/model/model_generator.rb +++ b/activerecord/lib/rails/generators/active_record/model/model_generator.rb @@ -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 diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 6db294290a..a1d39987e4 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -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 diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb index 2be5bea117..a4e93a4ecc 100644 --- a/railties/test/generators/namespaced_generators_test.rb +++ b/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/ |