提交 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
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|
......
......@@ -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
......
......@@ -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
......
......@@ -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)
......
......@@ -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
......
......@@ -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"
......
......@@ -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)
......
......@@ -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
......
......@@ -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")
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
# 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)" }
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册