diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2015-09-23 09:09:50 -0600 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2015-09-23 09:09:50 -0600 |
commit | f696494aedf453d8fd51a13005dfbd34477ccc45 (patch) | |
tree | 75fef7b5a8e1a23a9e82c00deeea6ba8f0d0cdf2 | |
parent | 66337b62ad5fe8004394608584baff137f4cc93e (diff) | |
download | rails-f696494aedf453d8fd51a13005dfbd34477ccc45.tar.gz rails-f696494aedf453d8fd51a13005dfbd34477ccc45.tar.bz2 rails-f696494aedf453d8fd51a13005dfbd34477ccc45.zip |
Don't attempt to specify datetime precision unless supported
Specifically, versions of MySQL prior to 5.6 do not support this, which
is what's used on Travis by default. The method `mysql_56?` appeared to
only ever be used to conditionally apply subsecond precision, so I've
generalized it and used it more liberally.
This should fix the test failures caused by #20317
-rw-r--r-- | activerecord/test/cases/base_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/helper.rb | 8 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 35 |
3 files changed, 32 insertions, 13 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 3aa0849cb5..991145bed4 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -204,7 +204,7 @@ class BasicsTest < ActiveRecord::TestCase ) # For adapters which support microsecond resolution. - if current_adapter?(:PostgreSQLAdapter, :SQLite3Adapter) || mysql_56? + if subsecond_precision_supported? 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/helper.rb b/activerecord/test/cases/helper.rb index b61a5126e0..8773986882 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -46,10 +46,10 @@ def in_memory_db? ActiveRecord::Base.connection_pool.spec.config[:database] == ":memory:" end -def mysql_56? - current_adapter?(:MysqlAdapter, :Mysql2Adapter) && - ActiveRecord::Base.connection.send(:version) >= '5.6.0' && - ActiveRecord::Base.connection.send(:version) < '5.7.0' +def subsecond_precision_supported? + !current_adapter?(:MysqlAdapter, :Mysql2Adapter) || + (ActiveRecord::Base.connection.send(:version) >= '5.6.0' && + ActiveRecord::Base.connection.send(:version) < '5.7.0') end def mysql_enforcing_gtid_consistency? diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index ae183ade81..c39b8d28ca 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -251,10 +251,17 @@ ActiveRecord::Schema.define do create_table :developers, force: true do |t| t.string :name t.integer :salary, default: 70000 - t.datetime :created_at, precision: 6 - t.datetime :updated_at, precision: 6 - t.datetime :created_on, precision: 6 - t.datetime :updated_on, precision: 6 + if subsecond_precision_supported? + t.datetime :created_at, precision: 6 + t.datetime :updated_at, precision: 6 + t.datetime :created_on, precision: 6 + t.datetime :updated_on, precision: 6 + else + t.datetime :created_at + t.datetime :updated_at + t.datetime :created_on + t.datetime :updated_on + end end create_table :developers_projects, force: true, id: false do |t| @@ -353,7 +360,11 @@ ActiveRecord::Schema.define do create_table :invoices, force: true do |t| t.integer :balance - t.datetime :updated_at, precision: 6 + if subsecond_precision_supported? + t.datetime :updated_at, precision: 6 + else + t.datetime :updated_at + end end create_table :iris, force: true do |t| @@ -503,7 +514,11 @@ ActiveRecord::Schema.define do create_table :owners, primary_key: :owner_id, force: true do |t| t.string :name - t.column :updated_at, :datetime, precision: 6 + if subsecond_precision_supported? + t.column :updated_at, :datetime, precision: 6 + else + t.column :updated_at, :datetime + end t.column :happy_at, :datetime t.string :essay_id end @@ -755,7 +770,7 @@ ActiveRecord::Schema.define do t.string :title, limit: 250 t.string :author_name t.string :author_email_address - if mysql_56? + if subsecond_precision_supported? t.datetime :written_on, precision: 6 else t.datetime :written_on @@ -778,7 +793,11 @@ ActiveRecord::Schema.define do t.string :parent_title t.string :type t.string :group - t.timestamps null: true, precision: 6 + if subsecond_precision_supported? + t.timestamps null: true, precision: 6 + else + t.timestamps null: true + end end create_table :toys, primary_key: :toy_id, force: true do |t| |