Fix failing tests due to datetime with precision is not supported on MySQL 5.5

This commit is contained in:
Ryuta Kamizono 2021-10-14 17:27:13 +09:00
parent 6baa6d2ca9
commit 46bb4dee09
8 changed files with 25 additions and 6 deletions

@ -46,7 +46,7 @@ def teardown
test "charset and collation options" do
@connection.create_table "mysql_table_options", force: true, charset: "utf8mb4", collation: "utf8mb4_bin"
output = dump_table_schema("mysql_table_options")
expected = /create_table "mysql_table_options", charset: "utf8mb4", collation: "utf8mb4_bin", force: :cascade/
expected = /create_table "mysql_table_options", charset: "utf8mb4", collation: "utf8mb4_bin"(:?, options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC")?, force: :cascade/
assert_match expected, output
end
@ -103,7 +103,7 @@ def teardown
assert_no_match %r{ENGINE=InnoDB}, @log.string
output = dump_table_schema("mysql_table_options")
expected = /create_table "mysql_table_options", charset: "utf8mb4"(?:, collation: "\w+")?, force: :cascade/
expected = /create_table "mysql_table_options", charset: "utf8mb4"(?:, collation: "\w+")?(:?, options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC")?, force: :cascade/
assert_match expected, output
end

@ -1202,6 +1202,8 @@ def test_minimum_and_maximum_on_tz_aware_attributes
end
def assert_minimum_and_maximum_on_time_attributes(time_class)
skip unless supports_datetime_with_precision? # Remove once MySQL 5.5 support is dropped.
actual = Topic.minimum(:written_on)
assert_equal Time.utc(2003, 7, 16, 14, 28, 11, 223300), actual
assert_instance_of time_class, actual

@ -106,6 +106,7 @@ class CollectionCacheKeyTest < ActiveRecord::TestCase
developers = Developer.where(name: "David")
cache_key = developers.cache_key
sleep 1.0 unless supports_datetime_with_precision? # Remove once MySQL 5.5 support is dropped.
developers.update_all(updated_at: Time.now.utc)
assert_not_equal cache_key, developers.cache_key
@ -115,6 +116,7 @@ class CollectionCacheKeyTest < ActiveRecord::TestCase
developers = Developer.includes(:projects).where("projects.name": "Active Record")
cache_key = developers.cache_key
sleep 1.0 unless supports_datetime_with_precision? # Remove once MySQL 5.5 support is dropped.
developers.update_all(updated_at: Time.now.utc)
assert_not_equal cache_key, developers.cache_key

@ -180,7 +180,9 @@ def test_touch_existing_lock
p1 = Person.find(1)
assert_equal 0, p1.lock_version
sleep 1.0 unless supports_datetime_with_precision? # Remove once MySQL 5.5 support is dropped.
p1.touch
assert_equal 1, p1.lock_version
assert_not_predicate p1, :changed?, "Changes should have been cleared"
assert_predicate p1, :saved_changes?
@ -297,6 +299,7 @@ def test_touch_existing_lock_without_default_should_work_with_null_in_the_databa
assert_equal 0, t1.lock_version
assert_nil t1.lock_version_before_type_cast
sleep 1.0 unless supports_datetime_with_precision? # Remove once MySQL 5.5 support is dropped.
t1.touch
assert_equal 1, t1.lock_version

@ -302,7 +302,8 @@ def test_add_column_with_postgresql_datetime_type
if current_adapter?(:PostgreSQLAdapter)
assert_equal "timestamp(6) without time zone", column.sql_type
elsif current_adapter?(:Mysql2Adapter)
assert_equal "datetime(6)", column.sql_type
sql_type = supports_datetime_with_precision? ? "datetime(6)" : "datetime"
assert_equal sql_type, column.sql_type
else
assert_equal connection.type_to_sql("datetime(6)"), column.sql_type
end

@ -692,6 +692,8 @@ def test_add_foreign_key_with_if_not_exists_not_set
if current_adapter?(:Mysql2Adapter)
if ActiveRecord::Base.connection.mariadb?
assert_match(/Duplicate key on write or update/, error.message)
elsif ActiveRecord::Base.connection.database_version < "5.6"
assert_match(/Can't create table/, error.message)
else
assert_match(/Duplicate foreign key constraint name/, error.message)
end

@ -838,7 +838,13 @@ def test_schema_dump_defaults_with_universally_supported_types
assert_match %r{t\.string\s+"string_with_default",.*?default: "Hello!"}, output
assert_match %r{t\.date\s+"date_with_default",\s+default: "2014-06-05"}, output
assert_match %r{t\.datetime\s+"datetime_with_default",\s+precision: 6,\s+default: "2014-06-05 07:17:04"}, output
if supports_datetime_with_precision?
assert_match %r{t\.datetime\s+"datetime_with_default",\s+precision: 6,\s+default: "2014-06-05 07:17:04"}, output
else
assert_match %r{t\.datetime\s+"datetime_with_default",\s+default: "2014-06-05 07:17:04"}, output
end
assert_match %r{t\.time\s+"time_with_default",\s+default: "2000-01-01 07:17:04"}, output
assert_match %r{t\.decimal\s+"decimal_with_default",\s+precision: 20,\s+scale: 10,\s+default: "1234567890.0123456789"}, output
end
@ -850,7 +856,6 @@ def test_schema_dump_with_text_column
end if supports_text_column_with_default?
def test_schema_dump_with_column_infinity_default
skip unless current_adapter?(:PostgreSQLAdapter)
output = dump_table_schema("infinity_defaults")
assert_match %r{t\.float\s+"float_with_inf_default",\s+default: ::Float::INFINITY}, output
assert_match %r{t\.float\s+"float_with_nan_default",\s+default: ::Float::NAN}, output
@ -858,5 +863,5 @@ def test_schema_dump_with_column_infinity_default
assert_match %r{t\.datetime\s+"end_of_time",\s+precision: 6,\s+default: ::Float::INFINITY}, output
assert_match %r{t\.date\s+"date_with_neg_inf_default",\s+default: -::Float::INFINITY}, output
assert_match %r{t\.date\s+"date_with_pos_inf_default",\s+default: ::Float::INFINITY}, output
end
end if current_adapter?(:PostgreSQLAdapter)
end

@ -34,6 +34,8 @@ def test_saving_a_unchanged_record_doesnt_update_its_timestamp
end
def test_touching_a_record_updates_its_timestamp
sleep 1.0 unless supports_datetime_with_precision? # Remove once MySQL 5.5 support is dropped.
previous_salary = @developer.salary
@developer.salary = previous_salary + 10000
@developer.touch
@ -51,6 +53,8 @@ def test_touching_a_record_updates_its_timestamp
end
def test_touching_a_record_with_default_scope_that_excludes_it_updates_its_timestamp
sleep 1.0 unless supports_datetime_with_precision? # Remove once MySQL 5.5 support is dropped.
developer = @developer.becomes(DeveloperCalledJamis)
developer.touch