Skip to content

Commit 46bb4de

Browse files
committed
Fix failing tests due to datetime with precision is not supported on MySQL 5.5
1 parent 6baa6d2 commit 46bb4de

File tree

8 files changed

+25
-6
lines changed

8 files changed

+25
-6
lines changed

activerecord/test/cases/adapters/mysql2/table_options_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def teardown
4646
test "charset and collation options" do
4747
@connection.create_table "mysql_table_options", force: true, charset: "utf8mb4", collation: "utf8mb4_bin"
4848
output = dump_table_schema("mysql_table_options")
49-
expected = /create_table "mysql_table_options", charset: "utf8mb4", collation: "utf8mb4_bin", force: :cascade/
49+
expected = /create_table "mysql_table_options", charset: "utf8mb4", collation: "utf8mb4_bin"(:?, options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC")?, force: :cascade/
5050
assert_match expected, output
5151
end
5252

@@ -103,7 +103,7 @@ def teardown
103103
assert_no_match %r{ENGINE=InnoDB}, @log.string
104104

105105
output = dump_table_schema("mysql_table_options")
106-
expected = /create_table "mysql_table_options", charset: "utf8mb4"(?:, collation: "\w+")?, force: :cascade/
106+
expected = /create_table "mysql_table_options", charset: "utf8mb4"(?:, collation: "\w+")?(:?, options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC")?, force: :cascade/
107107
assert_match expected, output
108108
end
109109

activerecord/test/cases/calculations_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,8 @@ def test_minimum_and_maximum_on_tz_aware_attributes
12021202
end
12031203

12041204
def assert_minimum_and_maximum_on_time_attributes(time_class)
1205+
skip unless supports_datetime_with_precision? # Remove once MySQL 5.5 support is dropped.
1206+
12051207
actual = Topic.minimum(:written_on)
12061208
assert_equal Time.utc(2003, 7, 16, 14, 28, 11, 223300), actual
12071209
assert_instance_of time_class, actual

activerecord/test/cases/collection_cache_key_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class CollectionCacheKeyTest < ActiveRecord::TestCase
106106
developers = Developer.where(name: "David")
107107
cache_key = developers.cache_key
108108

109+
sleep 1.0 unless supports_datetime_with_precision? # Remove once MySQL 5.5 support is dropped.
109110
developers.update_all(updated_at: Time.now.utc)
110111

111112
assert_not_equal cache_key, developers.cache_key
@@ -115,6 +116,7 @@ class CollectionCacheKeyTest < ActiveRecord::TestCase
115116
developers = Developer.includes(:projects).where("projects.name": "Active Record")
116117
cache_key = developers.cache_key
117118

119+
sleep 1.0 unless supports_datetime_with_precision? # Remove once MySQL 5.5 support is dropped.
118120
developers.update_all(updated_at: Time.now.utc)
119121

120122
assert_not_equal cache_key, developers.cache_key

activerecord/test/cases/locking_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ def test_touch_existing_lock
180180
p1 = Person.find(1)
181181
assert_equal 0, p1.lock_version
182182

183+
sleep 1.0 unless supports_datetime_with_precision? # Remove once MySQL 5.5 support is dropped.
183184
p1.touch
185+
184186
assert_equal 1, p1.lock_version
185187
assert_not_predicate p1, :changed?, "Changes should have been cleared"
186188
assert_predicate p1, :saved_changes?
@@ -297,6 +299,7 @@ def test_touch_existing_lock_without_default_should_work_with_null_in_the_databa
297299
assert_equal 0, t1.lock_version
298300
assert_nil t1.lock_version_before_type_cast
299301

302+
sleep 1.0 unless supports_datetime_with_precision? # Remove once MySQL 5.5 support is dropped.
300303
t1.touch
301304

302305
assert_equal 1, t1.lock_version

activerecord/test/cases/migration/change_schema_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ def test_add_column_with_postgresql_datetime_type
302302
if current_adapter?(:PostgreSQLAdapter)
303303
assert_equal "timestamp(6) without time zone", column.sql_type
304304
elsif current_adapter?(:Mysql2Adapter)
305-
assert_equal "datetime(6)", column.sql_type
305+
sql_type = supports_datetime_with_precision? ? "datetime(6)" : "datetime"
306+
assert_equal sql_type, column.sql_type
306307
else
307308
assert_equal connection.type_to_sql("datetime(6)"), column.sql_type
308309
end

activerecord/test/cases/migration/foreign_key_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,8 @@ def test_add_foreign_key_with_if_not_exists_not_set
692692
if current_adapter?(:Mysql2Adapter)
693693
if ActiveRecord::Base.connection.mariadb?
694694
assert_match(/Duplicate key on write or update/, error.message)
695+
elsif ActiveRecord::Base.connection.database_version < "5.6"
696+
assert_match(/Can't create table/, error.message)
695697
else
696698
assert_match(/Duplicate foreign key constraint name/, error.message)
697699
end

activerecord/test/cases/schema_dumper_test.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,13 @@ def test_schema_dump_defaults_with_universally_supported_types
838838

839839
assert_match %r{t\.string\s+"string_with_default",.*?default: "Hello!"}, output
840840
assert_match %r{t\.date\s+"date_with_default",\s+default: "2014-06-05"}, output
841-
assert_match %r{t\.datetime\s+"datetime_with_default",\s+precision: 6,\s+default: "2014-06-05 07:17:04"}, output
841+
842+
if supports_datetime_with_precision?
843+
assert_match %r{t\.datetime\s+"datetime_with_default",\s+precision: 6,\s+default: "2014-06-05 07:17:04"}, output
844+
else
845+
assert_match %r{t\.datetime\s+"datetime_with_default",\s+default: "2014-06-05 07:17:04"}, output
846+
end
847+
842848
assert_match %r{t\.time\s+"time_with_default",\s+default: "2000-01-01 07:17:04"}, output
843849
assert_match %r{t\.decimal\s+"decimal_with_default",\s+precision: 20,\s+scale: 10,\s+default: "1234567890.0123456789"}, output
844850
end
@@ -850,13 +856,12 @@ def test_schema_dump_with_text_column
850856
end if supports_text_column_with_default?
851857

852858
def test_schema_dump_with_column_infinity_default
853-
skip unless current_adapter?(:PostgreSQLAdapter)
854859
output = dump_table_schema("infinity_defaults")
855860
assert_match %r{t\.float\s+"float_with_inf_default",\s+default: ::Float::INFINITY}, output
856861
assert_match %r{t\.float\s+"float_with_nan_default",\s+default: ::Float::NAN}, output
857862
assert_match %r{t\.datetime\s+"beginning_of_time",\s+precision: 6,\s+default: -::Float::INFINITY}, output
858863
assert_match %r{t\.datetime\s+"end_of_time",\s+precision: 6,\s+default: ::Float::INFINITY}, output
859864
assert_match %r{t\.date\s+"date_with_neg_inf_default",\s+default: -::Float::INFINITY}, output
860865
assert_match %r{t\.date\s+"date_with_pos_inf_default",\s+default: ::Float::INFINITY}, output
861-
end
866+
end if current_adapter?(:PostgreSQLAdapter)
862867
end

activerecord/test/cases/timestamp_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def test_saving_a_unchanged_record_doesnt_update_its_timestamp
3434
end
3535

3636
def test_touching_a_record_updates_its_timestamp
37+
sleep 1.0 unless supports_datetime_with_precision? # Remove once MySQL 5.5 support is dropped.
38+
3739
previous_salary = @developer.salary
3840
@developer.salary = previous_salary + 10000
3941
@developer.touch
@@ -51,6 +53,8 @@ def test_touching_a_record_updates_its_timestamp
5153
end
5254

5355
def test_touching_a_record_with_default_scope_that_excludes_it_updates_its_timestamp
56+
sleep 1.0 unless supports_datetime_with_precision? # Remove once MySQL 5.5 support is dropped.
57+
5458
developer = @developer.becomes(DeveloperCalledJamis)
5559
developer.touch
5660

0 commit comments

Comments
 (0)