diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-03-30 05:54:15 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-03-30 06:07:57 +0900 |
commit | 6ccbc638494e41e1f9320a00b51ddfc16a387191 (patch) | |
tree | b1e7dfe0e8b950d4a60af0e04e412ab61ba88c3a /activerecord | |
parent | cd736dbfa4c81166797a55d4877aac92e45327f8 (diff) | |
download | rails-6ccbc638494e41e1f9320a00b51ddfc16a387191.tar.gz rails-6ccbc638494e41e1f9320a00b51ddfc16a387191.tar.bz2 rails-6ccbc638494e41e1f9320a00b51ddfc16a387191.zip |
Add a test case for create a record with primary key as zero
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/adapter_test.rb | 6 |
2 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 0e22062913..e31d2237eb 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -856,6 +856,7 @@ module ActiveRecord sql_mode = "REPLACE(#{sql_mode}, 'STRICT_ALL_TABLES', '')" sql_mode = "REPLACE(#{sql_mode}, 'TRADITIONAL', '')" end + sql_mode = "CONCAT(#{sql_mode}, ',NO_AUTO_VALUE_ON_ZERO')" end sql_mode_assignment = "@@SESSION.sql_mode = #{sql_mode}, " if sql_mode diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb index a9f1993842..4f389e9249 100644 --- a/activerecord/test/cases/adapter_test.rb +++ b/activerecord/test/cases/adapter_test.rb @@ -23,6 +23,12 @@ module ActiveRecord end end + def test_create_record_with_pk_as_zero + Book.create(id: 0) + assert_equal 0, Book.find(0).id + assert_nothing_raised { Book.destroy(0) } + end + def test_tables tables = nil ActiveSupport::Deprecation.silence { tables = @connection.tables } |