@@ -336,22 +336,6 @@ def migrate(x)
336
336
connection . drop_table :more_testings rescue nil
337
337
end
338
338
339
- def test_datetime_doesnt_set_precision_on_create_table
340
- migration = Class . new ( ActiveRecord ::Migration [ 6.1 ] ) {
341
- def migrate ( x )
342
- create_table :more_testings do |t |
343
- t . datetime :published_at
344
- end
345
- end
346
- } . new
347
-
348
- ActiveRecord ::Migrator . new ( :up , [ migration ] , @schema_migration , @internal_metadata ) . migrate
349
-
350
- assert connection . column_exists? ( :more_testings , :published_at , **precision_implicit_default )
351
- ensure
352
- connection . drop_table :more_testings rescue nil
353
- end
354
-
355
339
def test_datetime_doesnt_set_precision_on_add_column_5_0
356
340
migration = Class . new ( ActiveRecord ::Migration [ 5.0 ] ) {
357
341
def migrate ( x )
@@ -376,28 +360,6 @@ def migrate(x)
376
360
assert connection . column_exists? ( :testings , :published_at , **precision_implicit_default )
377
361
end
378
362
379
- def test_datetime_doesnt_set_precision_on_change_column_6_1
380
- create_migration = Class . new ( ActiveRecord ::Migration [ 6.1 ] ) {
381
- def migrate ( x )
382
- create_table :more_testings do |t |
383
- t . date :published_at
384
- end
385
- end
386
- } . new ( nil , 0 )
387
-
388
- change_migration = Class . new ( ActiveRecord ::Migration [ 6.1 ] ) {
389
- def migrate ( x )
390
- change_column :more_testings , :published_at , :datetime
391
- end
392
- } . new ( nil , 1 )
393
-
394
- ActiveRecord ::Migrator . new ( :up , [ create_migration , change_migration ] , @schema_migration , @internal_metadata ) . migrate
395
-
396
- assert connection . column_exists? ( :more_testings , :published_at , **precision_implicit_default )
397
- ensure
398
- connection . drop_table :more_testings rescue nil
399
- end
400
-
401
363
def test_change_table_allows_if_exists_option_on_7_0
402
364
migration = Class . new ( ActiveRecord ::Migration [ 7.0 ] ) {
403
365
def migrate ( x )
@@ -723,6 +685,44 @@ def migrate(x)
723
685
connection . drop_table :more_testings rescue nil
724
686
end
725
687
688
+ def test_datetime_doesnt_set_precision_on_create_table
689
+ migration = Class . new ( migration_class ) {
690
+ def migrate ( x )
691
+ create_table :more_testings do |t |
692
+ t . datetime :published_at
693
+ end
694
+ end
695
+ } . new
696
+
697
+ ActiveRecord ::Migrator . new ( :up , [ migration ] , @schema_migration , @internal_metadata ) . migrate
698
+
699
+ assert connection . column_exists? ( :more_testings , :published_at , **precision_implicit_default )
700
+ ensure
701
+ connection . drop_table :more_testings rescue nil
702
+ end
703
+
704
+ def test_datetime_doesnt_set_precision_on_change_column
705
+ create_migration = Class . new ( migration_class ) {
706
+ def migrate ( x )
707
+ create_table :more_testings do |t |
708
+ t . date :published_at
709
+ end
710
+ end
711
+ } . new ( nil , 0 )
712
+
713
+ change_migration = Class . new ( migration_class ) {
714
+ def migrate ( x )
715
+ change_column :more_testings , :published_at , :datetime
716
+ end
717
+ } . new ( nil , 1 )
718
+
719
+ ActiveRecord ::Migrator . new ( :up , [ create_migration , change_migration ] , @schema_migration , @internal_metadata ) . migrate
720
+
721
+ assert connection . column_exists? ( :more_testings , :published_at , **precision_implicit_default )
722
+ ensure
723
+ connection . drop_table :more_testings rescue nil
724
+ end
725
+
726
726
private
727
727
def precision_implicit_default
728
728
if current_adapter? ( :Mysql2Adapter , :TrilogyAdapter )
@@ -757,6 +757,46 @@ def migrate(x)
757
757
ensure
758
758
connection . drop_table :more_testings rescue nil
759
759
end
760
+
761
+ def test_datetime_sets_precision_6_on_create_table
762
+ migration = Class . new ( migration_class ) {
763
+ def migrate ( x )
764
+ create_table :more_testings do |t |
765
+ t . datetime :published_at
766
+ end
767
+ end
768
+ } . new
769
+
770
+ ActiveRecord ::Migrator . new ( :up , [ migration ] , @schema_migration , @internal_metadata ) . migrate
771
+
772
+ assert connection . column_exists? ( :more_testings , :published_at , precision : 6 )
773
+ ensure
774
+ connection . drop_table :more_testings rescue nil
775
+ end
776
+
777
+ def test_datetime_sets_precision_6_on_change_column
778
+ create_migration = Class . new ( migration_class ) {
779
+ def migrate ( x )
780
+ create_table :more_testings do |t |
781
+ t . date :published_at
782
+ end
783
+ end
784
+ } . new ( nil , 0 )
785
+
786
+ $global = true
787
+
788
+ change_migration = Class . new ( migration_class ) {
789
+ def migrate ( x )
790
+ change_column :more_testings , :published_at , :datetime
791
+ end
792
+ } . new ( nil , 1 )
793
+
794
+ ActiveRecord ::Migrator . new ( :up , [ create_migration , change_migration ] , @schema_migration , @internal_metadata ) . migrate
795
+
796
+ assert connection . column_exists? ( :more_testings , :published_at , precision : 6 )
797
+ ensure
798
+ connection . drop_table :more_testings rescue nil
799
+ end
760
800
end
761
801
762
802
class BaseCompatibilityTest < ActiveRecord ::TestCase
0 commit comments