From 9bd21b174bc52c6863b444704f5970d4d5cc9215 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sat, 25 Apr 2020 02:56:53 +0900 Subject: [PATCH] Use `supports_datetime_with_precision?` rather than `subsecond_precision_supported?` --- activerecord/test/cases/ar_schema_test.rb | 2 +- activerecord/test/cases/base_test.rb | 2 +- .../test/cases/date_time_precision_test.rb | 2 +- activerecord/test/cases/date_time_test.rb | 2 +- activerecord/test/cases/defaults_test.rb | 2 +- activerecord/test/cases/dirty_test.rb | 2 +- activerecord/test/cases/helper.rb | 5 +---- activerecord/test/cases/integration_test.rb | 4 ++-- activerecord/test/cases/primary_keys_test.rb | 2 +- activerecord/test/cases/quoting_test.rb | 2 +- activerecord/test/cases/time_precision_test.rb | 2 +- activerecord/test/cases/type/date_time_test.rb | 2 +- activerecord/test/schema/mysql2_specific_schema.rb | 2 +- activerecord/test/schema/schema.rb | 14 +++++++------- 14 files changed, 21 insertions(+), 24 deletions(-) diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb index 2d5a06a4ac..1bfb480b5e 100644 --- a/activerecord/test/cases/ar_schema_test.rb +++ b/activerecord/test/cases/ar_schema_test.rb @@ -160,7 +160,7 @@ def test_timestamps_without_null_set_null_to_false_on_add_timestamps assert @connection.column_exists?(:has_timestamps, :updated_at, null: false) end - if subsecond_precision_supported? + if supports_datetime_with_precision? def test_timestamps_sets_precision_on_create_table ActiveRecord::Schema.define do create_table :has_timestamps do |t| diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 6d552629ea..d869e55a64 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -221,7 +221,7 @@ def test_preserving_time_objects ) # For adapters which support microsecond resolution. - if subsecond_precision_supported? + if supports_datetime_with_precision? assert_equal 11, Topic.find(1).written_on.sec assert_equal 223300, Topic.find(1).written_on.usec assert_equal 9900, Topic.find(2).written_on.usec diff --git a/activerecord/test/cases/date_time_precision_test.rb b/activerecord/test/cases/date_time_precision_test.rb index 79d63949ca..001b633676 100644 --- a/activerecord/test/cases/date_time_precision_test.rb +++ b/activerecord/test/cases/date_time_precision_test.rb @@ -3,7 +3,7 @@ require "cases/helper" require "support/schema_dumping_helper" -if subsecond_precision_supported? +if supports_datetime_with_precision? class DateTimePrecisionTest < ActiveRecord::TestCase include SchemaDumpingHelper self.use_transactional_tests = false diff --git a/activerecord/test/cases/date_time_test.rb b/activerecord/test/cases/date_time_test.rb index b5f35aff0e..6c25208192 100644 --- a/activerecord/test/cases/date_time_test.rb +++ b/activerecord/test/cases/date_time_test.rb @@ -62,7 +62,7 @@ def test_assign_in_local_timezone end def test_date_time_with_string_value_with_subsecond_precision - skip unless subsecond_precision_supported? + skip unless supports_datetime_with_precision? string_value = "2017-07-04 14:19:00.5" topic = Topic.create(written_on: string_value) assert_equal topic, Topic.find_by(written_on: string_value) diff --git a/activerecord/test/cases/defaults_test.rb b/activerecord/test/cases/defaults_test.rb index d5fc402df1..81db26b79f 100644 --- a/activerecord/test/cases/defaults_test.rb +++ b/activerecord/test/cases/defaults_test.rb @@ -113,7 +113,7 @@ class MysqlDefaultExpressionTest < ActiveRecord::TestCase end end - if subsecond_precision_supported? + if supports_datetime_with_precision? test "schema dump datetime includes default expression" do output = dump_table_schema("datetime_defaults") assert_match %r/t\.datetime\s+"modified_datetime",\s+default: -> { "CURRENT_TIMESTAMP(?:\(\))?" }/i, output diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index 3f7d90175e..f289408ef7 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -596,7 +596,7 @@ def test_field_named_field end def test_datetime_attribute_can_be_updated_with_fractional_seconds - skip "Fractional seconds are not supported" unless subsecond_precision_supported? + skip "Fractional seconds are not supported" unless supports_datetime_with_precision? in_time_zone "Paris" do target = Class.new(ActiveRecord::Base) target.table_name = "topics" diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index 7e7053f311..f6dd74f3a7 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -40,10 +40,6 @@ def in_memory_db? ActiveRecord::Base.connection_pool.db_config.database == ":memory:" end -def subsecond_precision_supported? - ActiveRecord::Base.connection.supports_datetime_with_precision? -end - def mysql_enforcing_gtid_consistency? current_adapter?(:Mysql2Adapter) && "ON" == ActiveRecord::Base.connection.show_variable("enforce_gtid_consistency") end @@ -66,6 +62,7 @@ def supports_default_expression? supports_insert_on_duplicate_update? supports_insert_conflict_target? supports_optimizer_hints? + supports_datetime_with_precision? ].each do |method_name| define_method method_name do ActiveRecord::Base.connection.public_send(method_name) diff --git a/activerecord/test/cases/integration_test.rb b/activerecord/test/cases/integration_test.rb index 4185e8d682..145ae97e63 100644 --- a/activerecord/test/cases/integration_test.rb +++ b/activerecord/test/cases/integration_test.rb @@ -154,7 +154,7 @@ def test_cache_key_for_newer_updated_on end def test_cache_key_format_is_precise_enough - skip("Subsecond precision is not supported") unless subsecond_precision_supported? + skip("Subsecond precision is not supported") unless supports_datetime_with_precision? dev = Developer.first key = dev.cache_key travel_to dev.updated_at + 0.000001 do @@ -171,7 +171,7 @@ def test_cache_key_format_is_not_too_precise end def test_cache_version_format_is_precise_enough - skip("Subsecond precision is not supported") unless subsecond_precision_supported? + skip("Subsecond precision is not supported") unless supports_datetime_with_precision? with_cache_versioning do dev = Developer.first version = dev.cache_version.to_param diff --git a/activerecord/test/cases/primary_keys_test.rb b/activerecord/test/cases/primary_keys_test.rb index 511d7fc982..faebbbd39c 100644 --- a/activerecord/test/cases/primary_keys_test.rb +++ b/activerecord/test/cases/primary_keys_test.rb @@ -316,7 +316,7 @@ def test_any_type_primary_key assert_no_match %r{t\.index \["code"\]}, schema end - if current_adapter?(:Mysql2Adapter) && subsecond_precision_supported? + if current_adapter?(:Mysql2Adapter) && supports_datetime_with_precision? test "schema typed primary key column" do @connection.create_table(:scheduled_logs, id: :timestamp, precision: 6, force: true) schema = dump_table_schema("scheduled_logs") diff --git a/activerecord/test/cases/quoting_test.rb b/activerecord/test/cases/quoting_test.rb index 723fccc8d9..4e3f0ab848 100644 --- a/activerecord/test/cases/quoting_test.rb +++ b/activerecord/test/cases/quoting_test.rb @@ -267,7 +267,7 @@ def test_type_cast_returns_frozen_value end end - if subsecond_precision_supported? + if supports_datetime_with_precision? class QuoteARBaseTest < ActiveRecord::TestCase class DatetimePrimaryKey < ActiveRecord::Base end diff --git a/activerecord/test/cases/time_precision_test.rb b/activerecord/test/cases/time_precision_test.rb index 1abd857216..967037e6c9 100644 --- a/activerecord/test/cases/time_precision_test.rb +++ b/activerecord/test/cases/time_precision_test.rb @@ -3,7 +3,7 @@ require "cases/helper" require "support/schema_dumping_helper" -if subsecond_precision_supported? +if supports_datetime_with_precision? class TimePrecisionTest < ActiveRecord::TestCase include SchemaDumpingHelper self.use_transactional_tests = false diff --git a/activerecord/test/cases/type/date_time_test.rb b/activerecord/test/cases/type/date_time_test.rb index c9558e25b5..4c5064eeb4 100644 --- a/activerecord/test/cases/type/date_time_test.rb +++ b/activerecord/test/cases/type/date_time_test.rb @@ -7,7 +7,7 @@ module ActiveRecord module Type class DateTimeTest < ActiveRecord::TestCase def test_datetime_seconds_precision_applied_to_timestamp - skip "This test is invalid if subsecond precision isn't supported" unless subsecond_precision_supported? + skip "This test is invalid if subsecond precision isn't supported" unless supports_datetime_with_precision? p = Task.create!(starting: ::Time.now) assert_equal p.starting.usec, p.reload.starting.usec end diff --git a/activerecord/test/schema/mysql2_specific_schema.rb b/activerecord/test/schema/mysql2_specific_schema.rb index 911ac808c6..c976653246 100644 --- a/activerecord/test/schema/mysql2_specific_schema.rb +++ b/activerecord/test/schema/mysql2_specific_schema.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true ActiveRecord::Schema.define do - if subsecond_precision_supported? + if supports_datetime_with_precision? create_table :datetime_defaults, force: true do |t| t.datetime :modified_datetime, default: -> { "CURRENT_TIMESTAMP" } t.datetime :precise_datetime, precision: 6, default: -> { "CURRENT_TIMESTAMP(6)" } diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index b8cb88d7fa..901fae8dd0 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -294,7 +294,7 @@ t.integer :salary, default: 70000 t.references :firm, index: false t.integer :mentor_id - if subsecond_precision_supported? + if supports_datetime_with_precision? t.datetime :created_at, precision: 6 t.datetime :updated_at, precision: 6 t.datetime :created_on, precision: 6 @@ -420,7 +420,7 @@ create_table :invoices, force: true do |t| t.integer :balance - if subsecond_precision_supported? + if supports_datetime_with_precision? t.datetime :updated_at, precision: 6 else t.datetime :updated_at @@ -611,7 +611,7 @@ create_table :owners, primary_key: :owner_id, force: true do |t| t.string :name - if subsecond_precision_supported? + if supports_datetime_with_precision? t.column :updated_at, :datetime, precision: 6 else t.column :updated_at, :datetime @@ -635,7 +635,7 @@ t.string :parrot_sti_class t.integer :killer_id t.integer :updated_count, :integer, default: 0 - if subsecond_precision_supported? + if supports_datetime_with_precision? t.datetime :created_at, precision: 0 t.datetime :created_on, precision: 0 t.datetime :updated_at, precision: 0 @@ -652,7 +652,7 @@ t.string :catchphrase t.integer :parrot_id t.integer :non_validated_parrot_id - if subsecond_precision_supported? + if supports_datetime_with_precision? t.datetime :created_on, precision: 6 t.datetime :updated_on, precision: 6 else @@ -847,7 +847,7 @@ create_table :ship_parts, force: true do |t| t.string :name t.integer :ship_id - if subsecond_precision_supported? + if supports_datetime_with_precision? t.datetime :updated_at, precision: 6 else t.datetime :updated_at @@ -927,7 +927,7 @@ t.string :title, limit: 250, **case_sensitive_options t.string :author_name, **case_sensitive_options t.string :author_email_address - if subsecond_precision_supported? + if supports_datetime_with_precision? t.datetime :written_on, precision: 6 else t.datetime :written_on -- GitLab