aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test/generators')
-rw-r--r--railties/test/generators/model_generator_test.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb
index a9b772d67b..501c7d10c6 100644
--- a/railties/test/generators/model_generator_test.rb
+++ b/railties/test/generators/model_generator_test.rb
@@ -31,6 +31,50 @@ class ModelGeneratorTest < GeneratorsTestCase
assert_migration "db/migrate/create_accounts.rb", /class CreateAccounts < ActiveRecord::Migration/
end
+ def test_migration_with_namespace
+ run_generator ["Gallery::Image"]
+ assert_migration "db/migrate/create_gallery_images", /class CreateGalleryImages < ActiveRecord::Migration/
+ assert_no_migration "db/migrate/create_images"
+ end
+
+ def test_migration_with_nested_namespace
+ run_generator ["Admin::Gallery::Image"]
+ assert_no_migration "db/migrate/create_images"
+ assert_no_migration "db/migrate/create_gallery_images"
+ assert_migration "db/migrate/create_admin_gallery_images", /class CreateAdminGalleryImages < ActiveRecord::Migration/
+ assert_migration "db/migrate/create_admin_gallery_images", /create_table :admin_gallery_images/
+ end
+
+ def test_migration_with_nested_namespace_without_pluralization
+ ActiveRecord::Base.pluralize_table_names = false
+ run_generator ["Admin::Gallery::Image"]
+ assert_no_migration "db/migrate/create_images"
+ assert_no_migration "db/migrate/create_gallery_images"
+ assert_no_migration "db/migrate/create_admin_gallery_images"
+ assert_migration "db/migrate/create_admin_gallery_image", /class CreateAdminGalleryImage < ActiveRecord::Migration/
+ assert_migration "db/migrate/create_admin_gallery_image", /create_table :admin_gallery_image/
+ ensure
+ ActiveRecord::Base.pluralize_table_names = true
+ end
+
+ def test_migration_with_namespaces_in_model_name_without_plurization
+ ActiveRecord::Base.pluralize_table_names = false
+ run_generator ["Gallery::Image"]
+ assert_migration "db/migrate/create_gallery_image", /class CreateGalleryImage < ActiveRecord::Migration/
+ assert_no_migration "db/migrate/create_gallery_images"
+ ensure
+ ActiveRecord::Base.pluralize_table_names = true
+ end
+
+ def test_migration_without_pluralization
+ ActiveRecord::Base.pluralize_table_names = false
+ run_generator
+ assert_migration "db/migrate/create_account", /class CreateAccount < ActiveRecord::Migration/
+ assert_no_migration "db/migrate/create_accounts"
+ ensure
+ ActiveRecord::Base.pluralize_table_names = true
+ end
+
def test_migration_is_skipped
run_generator ["account", "--no-migration"]
assert_no_migration "db/migrate/create_accounts.rb"