diff options
Diffstat (limited to 'railties/test/generators/model_generator_test.rb')
-rw-r--r-- | railties/test/generators/model_generator_test.rb | 61 |
1 files changed, 49 insertions, 12 deletions
diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index b06db6dd8a..f860e328f2 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -104,7 +104,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase ActiveRecord::Base.pluralize_table_names = true end - def test_migration_with_namespaces_in_model_name_without_plurization + def test_migration_with_namespaces_in_model_name_without_pluralization ActiveRecord::Base.pluralize_table_names = false run_generator ["Gallery::Image"] assert_migration "db/migrate/create_gallery_image", /class CreateGalleryImage < ActiveRecord::Migration\[[0-9.]+\]/ @@ -403,23 +403,23 @@ class ModelGeneratorTest < Rails::Generators::TestCase end end - def test_required_belongs_to_adds_required_association - run_generator ["account", "supplier:references{required}"] - - expected_file = <<~FILE - class Account < ApplicationRecord - belongs_to :supplier, required: true + def test_database_puts_migrations_in_configured_folder_with_aliases + with_secondary_database_configuration do + run_generator ["account", "--db=secondary"] + assert_migration "db/secondary_migrate/create_accounts.rb" do |content| + assert_method :change, content do |change| + assert_match(/create_table :accounts/, change) + end end - FILE - assert_file "app/models/account.rb", expected_file + end end - def test_required_polymorphic_belongs_to_generages_correct_model + def test_required_polymorphic_belongs_to_generates_correct_model run_generator ["account", "supplier:references{required,polymorphic}"] expected_file = <<~FILE class Account < ApplicationRecord - belongs_to :supplier, polymorphic: true, required: true + belongs_to :supplier, polymorphic: true end FILE assert_file "app/models/account.rb", expected_file @@ -430,7 +430,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase expected_file = <<~FILE class Account < ApplicationRecord - belongs_to :supplier, polymorphic: true, required: true + belongs_to :supplier, polymorphic: true end FILE assert_file "app/models/account.rb", expected_file @@ -488,6 +488,43 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_file "app/models/user.rb", expected_file end + def test_model_with_rich_text_attribute_adds_has_rich_text + run_generator ["message", "content:rich_text"] + expected_file = <<~FILE + class Message < ApplicationRecord + has_rich_text :content + end + FILE + assert_file "app/models/message.rb", expected_file + end + + def test_model_with_attachment_attribute_adds_has_one_attached + run_generator ["message", "video:attachment"] + expected_file = <<~FILE + class Message < ApplicationRecord + has_one_attached :video + end + FILE + assert_file "app/models/message.rb", expected_file + end + + def test_model_with_attachments_attribute_adds_has_many_attached + run_generator ["message", "photos:attachments"] + expected_file = <<~FILE + class Message < ApplicationRecord + has_many_attached :photos + end + FILE + assert_file "app/models/message.rb", expected_file + end + + def test_skip_virtual_fields_in_fixtures + run_generator ["message", "content:rich_text", "video:attachment", "photos:attachments"] + + assert_generated_fixture("test/fixtures/messages.yml", + "one" => nil, "two" => nil) + end + private def assert_generated_fixture(path, parsed_contents) fixture_file = File.new File.expand_path(path, destination_root) |