From 93d2090011b5ccab504b8aeabf6a95b23193a689 Mon Sep 17 00:00:00 2001 From: Michael Duchemin Date: Sun, 27 Jan 2019 00:23:47 -0500 Subject: Add class option timestamps to migration generator Fixes GH#28706. Now rails g migration create_users and rails g model User have the same behavior for timestamps since they implement the same migration template. The expected behavior is that this create table migration will create the table with timestamps unless you pass --no-timestamps or --skip-timestamps to the generator. The expected migration should match what you get when you use the model generator. Using the migration generator, which doesn't have a class_option for timestamps would cause them to not be added to the migration file. Now the migration behavior of the migration generator, create_table only, is aligned with the migration behavior of the model generator. Also modified relevant example of ActiveRecord Migrations Guide. --- railties/test/generators/migration_generator_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'railties') diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 5812cbdfc9..b8958f6f99 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -245,6 +245,21 @@ class MigrationGeneratorTest < Rails::Generators::TestCase end end + def test_create_table_migration_with_timestamps + run_generator ["create_books", "title:string", "content:text"] + assert_migration "db/migrate/create_books.rb", /t.timestamps/ + end + + def test_create_table_timestamps_are_skipped + run_generator ["create_books", "title:string", "content:text", "--no-timestamps"] + + assert_migration "db/migrate/create_books.rb" do |m| + assert_method :change, m do |change| + assert_no_match(/t.timestamps/, change) + end + end + end + def test_add_uuid_to_create_table_migration run_generator ["create_books", "--primary_key_type=uuid"] assert_migration "db/migrate/create_books.rb" do |content| -- cgit v1.2.3