提交 9bd21b17 编写于 作者: R Ryuta Kamizono

Use `supports_datetime_with_precision?` rather than `subsecond_precision_supported?`

上级 4c5e4ea4
...@@ -160,7 +160,7 @@ def test_timestamps_without_null_set_null_to_false_on_add_timestamps ...@@ -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) assert @connection.column_exists?(:has_timestamps, :updated_at, null: false)
end end
if subsecond_precision_supported? if supports_datetime_with_precision?
def test_timestamps_sets_precision_on_create_table def test_timestamps_sets_precision_on_create_table
ActiveRecord::Schema.define do ActiveRecord::Schema.define do
create_table :has_timestamps do |t| create_table :has_timestamps do |t|
......
...@@ -221,7 +221,7 @@ def test_preserving_time_objects ...@@ -221,7 +221,7 @@ def test_preserving_time_objects
) )
# For adapters which support microsecond resolution. # 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 11, Topic.find(1).written_on.sec
assert_equal 223300, Topic.find(1).written_on.usec assert_equal 223300, Topic.find(1).written_on.usec
assert_equal 9900, Topic.find(2).written_on.usec assert_equal 9900, Topic.find(2).written_on.usec
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require "cases/helper" require "cases/helper"
require "support/schema_dumping_helper" require "support/schema_dumping_helper"
if subsecond_precision_supported? if supports_datetime_with_precision?
class DateTimePrecisionTest < ActiveRecord::TestCase class DateTimePrecisionTest < ActiveRecord::TestCase
include SchemaDumpingHelper include SchemaDumpingHelper
self.use_transactional_tests = false self.use_transactional_tests = false
......
...@@ -62,7 +62,7 @@ def test_assign_in_local_timezone ...@@ -62,7 +62,7 @@ def test_assign_in_local_timezone
end end
def test_date_time_with_string_value_with_subsecond_precision 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" string_value = "2017-07-04 14:19:00.5"
topic = Topic.create(written_on: string_value) topic = Topic.create(written_on: string_value)
assert_equal topic, Topic.find_by(written_on: string_value) assert_equal topic, Topic.find_by(written_on: string_value)
......
...@@ -113,7 +113,7 @@ class MysqlDefaultExpressionTest < ActiveRecord::TestCase ...@@ -113,7 +113,7 @@ class MysqlDefaultExpressionTest < ActiveRecord::TestCase
end end
end end
if subsecond_precision_supported? if supports_datetime_with_precision?
test "schema dump datetime includes default expression" do test "schema dump datetime includes default expression" do
output = dump_table_schema("datetime_defaults") output = dump_table_schema("datetime_defaults")
assert_match %r/t\.datetime\s+"modified_datetime",\s+default: -> { "CURRENT_TIMESTAMP(?:\(\))?" }/i, output assert_match %r/t\.datetime\s+"modified_datetime",\s+default: -> { "CURRENT_TIMESTAMP(?:\(\))?" }/i, output
......
...@@ -596,7 +596,7 @@ def test_field_named_field ...@@ -596,7 +596,7 @@ def test_field_named_field
end end
def test_datetime_attribute_can_be_updated_with_fractional_seconds 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 in_time_zone "Paris" do
target = Class.new(ActiveRecord::Base) target = Class.new(ActiveRecord::Base)
target.table_name = "topics" target.table_name = "topics"
......
...@@ -40,10 +40,6 @@ def in_memory_db? ...@@ -40,10 +40,6 @@ def in_memory_db?
ActiveRecord::Base.connection_pool.db_config.database == ":memory:" ActiveRecord::Base.connection_pool.db_config.database == ":memory:"
end end
def subsecond_precision_supported?
ActiveRecord::Base.connection.supports_datetime_with_precision?
end
def mysql_enforcing_gtid_consistency? def mysql_enforcing_gtid_consistency?
current_adapter?(:Mysql2Adapter) && "ON" == ActiveRecord::Base.connection.show_variable("enforce_gtid_consistency") current_adapter?(:Mysql2Adapter) && "ON" == ActiveRecord::Base.connection.show_variable("enforce_gtid_consistency")
end end
...@@ -66,6 +62,7 @@ def supports_default_expression? ...@@ -66,6 +62,7 @@ def supports_default_expression?
supports_insert_on_duplicate_update? supports_insert_on_duplicate_update?
supports_insert_conflict_target? supports_insert_conflict_target?
supports_optimizer_hints? supports_optimizer_hints?
supports_datetime_with_precision?
].each do |method_name| ].each do |method_name|
define_method method_name do define_method method_name do
ActiveRecord::Base.connection.public_send(method_name) ActiveRecord::Base.connection.public_send(method_name)
......
...@@ -154,7 +154,7 @@ def test_cache_key_for_newer_updated_on ...@@ -154,7 +154,7 @@ def test_cache_key_for_newer_updated_on
end end
def test_cache_key_format_is_precise_enough 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 dev = Developer.first
key = dev.cache_key key = dev.cache_key
travel_to dev.updated_at + 0.000001 do travel_to dev.updated_at + 0.000001 do
...@@ -171,7 +171,7 @@ def test_cache_key_format_is_not_too_precise ...@@ -171,7 +171,7 @@ def test_cache_key_format_is_not_too_precise
end end
def test_cache_version_format_is_precise_enough 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 with_cache_versioning do
dev = Developer.first dev = Developer.first
version = dev.cache_version.to_param version = dev.cache_version.to_param
......
...@@ -316,7 +316,7 @@ def test_any_type_primary_key ...@@ -316,7 +316,7 @@ def test_any_type_primary_key
assert_no_match %r{t\.index \["code"\]}, schema assert_no_match %r{t\.index \["code"\]}, schema
end end
if current_adapter?(:Mysql2Adapter) && subsecond_precision_supported? if current_adapter?(:Mysql2Adapter) && supports_datetime_with_precision?
test "schema typed primary key column" do test "schema typed primary key column" do
@connection.create_table(:scheduled_logs, id: :timestamp, precision: 6, force: true) @connection.create_table(:scheduled_logs, id: :timestamp, precision: 6, force: true)
schema = dump_table_schema("scheduled_logs") schema = dump_table_schema("scheduled_logs")
......
...@@ -267,7 +267,7 @@ def test_type_cast_returns_frozen_value ...@@ -267,7 +267,7 @@ def test_type_cast_returns_frozen_value
end end
end end
if subsecond_precision_supported? if supports_datetime_with_precision?
class QuoteARBaseTest < ActiveRecord::TestCase class QuoteARBaseTest < ActiveRecord::TestCase
class DatetimePrimaryKey < ActiveRecord::Base class DatetimePrimaryKey < ActiveRecord::Base
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require "cases/helper" require "cases/helper"
require "support/schema_dumping_helper" require "support/schema_dumping_helper"
if subsecond_precision_supported? if supports_datetime_with_precision?
class TimePrecisionTest < ActiveRecord::TestCase class TimePrecisionTest < ActiveRecord::TestCase
include SchemaDumpingHelper include SchemaDumpingHelper
self.use_transactional_tests = false self.use_transactional_tests = false
......
...@@ -7,7 +7,7 @@ module ActiveRecord ...@@ -7,7 +7,7 @@ module ActiveRecord
module Type module Type
class DateTimeTest < ActiveRecord::TestCase class DateTimeTest < ActiveRecord::TestCase
def test_datetime_seconds_precision_applied_to_timestamp 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) p = Task.create!(starting: ::Time.now)
assert_equal p.starting.usec, p.reload.starting.usec assert_equal p.starting.usec, p.reload.starting.usec
end end
......
# frozen_string_literal: true # frozen_string_literal: true
ActiveRecord::Schema.define do ActiveRecord::Schema.define do
if subsecond_precision_supported? if supports_datetime_with_precision?
create_table :datetime_defaults, force: true do |t| create_table :datetime_defaults, force: true do |t|
t.datetime :modified_datetime, default: -> { "CURRENT_TIMESTAMP" } t.datetime :modified_datetime, default: -> { "CURRENT_TIMESTAMP" }
t.datetime :precise_datetime, precision: 6, default: -> { "CURRENT_TIMESTAMP(6)" } t.datetime :precise_datetime, precision: 6, default: -> { "CURRENT_TIMESTAMP(6)" }
......
...@@ -294,7 +294,7 @@ ...@@ -294,7 +294,7 @@
t.integer :salary, default: 70000 t.integer :salary, default: 70000
t.references :firm, index: false t.references :firm, index: false
t.integer :mentor_id t.integer :mentor_id
if subsecond_precision_supported? if supports_datetime_with_precision?
t.datetime :created_at, precision: 6 t.datetime :created_at, precision: 6
t.datetime :updated_at, precision: 6 t.datetime :updated_at, precision: 6
t.datetime :created_on, precision: 6 t.datetime :created_on, precision: 6
...@@ -420,7 +420,7 @@ ...@@ -420,7 +420,7 @@
create_table :invoices, force: true do |t| create_table :invoices, force: true do |t|
t.integer :balance t.integer :balance
if subsecond_precision_supported? if supports_datetime_with_precision?
t.datetime :updated_at, precision: 6 t.datetime :updated_at, precision: 6
else else
t.datetime :updated_at t.datetime :updated_at
...@@ -611,7 +611,7 @@ ...@@ -611,7 +611,7 @@
create_table :owners, primary_key: :owner_id, force: true do |t| create_table :owners, primary_key: :owner_id, force: true do |t|
t.string :name t.string :name
if subsecond_precision_supported? if supports_datetime_with_precision?
t.column :updated_at, :datetime, precision: 6 t.column :updated_at, :datetime, precision: 6
else else
t.column :updated_at, :datetime t.column :updated_at, :datetime
...@@ -635,7 +635,7 @@ ...@@ -635,7 +635,7 @@
t.string :parrot_sti_class t.string :parrot_sti_class
t.integer :killer_id t.integer :killer_id
t.integer :updated_count, :integer, default: 0 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_at, precision: 0
t.datetime :created_on, precision: 0 t.datetime :created_on, precision: 0
t.datetime :updated_at, precision: 0 t.datetime :updated_at, precision: 0
...@@ -652,7 +652,7 @@ ...@@ -652,7 +652,7 @@
t.string :catchphrase t.string :catchphrase
t.integer :parrot_id t.integer :parrot_id
t.integer :non_validated_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 :created_on, precision: 6
t.datetime :updated_on, precision: 6 t.datetime :updated_on, precision: 6
else else
...@@ -847,7 +847,7 @@ ...@@ -847,7 +847,7 @@
create_table :ship_parts, force: true do |t| create_table :ship_parts, force: true do |t|
t.string :name t.string :name
t.integer :ship_id t.integer :ship_id
if subsecond_precision_supported? if supports_datetime_with_precision?
t.datetime :updated_at, precision: 6 t.datetime :updated_at, precision: 6
else else
t.datetime :updated_at t.datetime :updated_at
...@@ -927,7 +927,7 @@ ...@@ -927,7 +927,7 @@
t.string :title, limit: 250, **case_sensitive_options t.string :title, limit: 250, **case_sensitive_options
t.string :author_name, **case_sensitive_options t.string :author_name, **case_sensitive_options
t.string :author_email_address t.string :author_email_address
if subsecond_precision_supported? if supports_datetime_with_precision?
t.datetime :written_on, precision: 6 t.datetime :written_on, precision: 6
else else
t.datetime :written_on t.datetime :written_on
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册