diff options
author | Akira Matsuda <ronnie@dio.jp> | 2012-04-19 22:04:13 +0900 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2012-04-19 06:46:18 -0700 |
commit | f51557deb0a591a442e94d07d90e57853693ad14 (patch) | |
tree | 0e3c644daa401921922d2dea4cd08c1c8526b958 /activerecord/test | |
parent | b9e5c5aca3313bd67b35a608c504175f99172d7f (diff) | |
download | rails-f51557deb0a591a442e94d07d90e57853693ad14.tar.gz rails-f51557deb0a591a442e94d07d90e57853693ad14.tar.bz2 rails-f51557deb0a591a442e94d07d90e57853693ad14.zip |
Be sure to correctly fetch PK name from MySQL even if the PK has some custom option
Backports #5900
Conflicts:
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb b/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb index 146b77a95c..65328522c3 100644 --- a/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb +++ b/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb @@ -52,6 +52,36 @@ module ActiveRecord assert_equal str, value end + def test_pk_and_sequence_for + pk, seq = @conn.pk_and_sequence_for('ex') + assert_equal 'id', pk + assert_equal @conn.default_sequence_name('ex', 'id'), seq + end + + def test_pk_and_sequence_for_with_non_standard_primary_key + @conn.exec_query('drop table if exists ex_with_non_standard_pk') + @conn.exec_query(<<-eosql) + CREATE TABLE `ex_with_non_standard_pk` ( + `code` INT(11) DEFAULT NULL auto_increment, + PRIMARY KEY (`code`)) + eosql + pk, seq = @conn.pk_and_sequence_for('ex_with_non_standard_pk') + assert_equal 'code', pk + assert_equal @conn.default_sequence_name('ex_with_non_standard_pk', 'code'), seq + end + + def test_pk_and_sequence_for_with_custom_index_type_pk + @conn.exec_query('drop table if exists ex_with_custom_index_type_pk') + @conn.exec_query(<<-eosql) + CREATE TABLE `ex_with_custom_index_type_pk` ( + `id` INT(11) DEFAULT NULL auto_increment, + PRIMARY KEY USING BTREE (`id`)) + eosql + pk, seq = @conn.pk_and_sequence_for('ex_with_custom_index_type_pk') + assert_equal 'id', pk + assert_equal @conn.default_sequence_name('ex_with_custom_index_type_pk', 'id'), seq + end + private def insert(ctx, data) binds = data.map { |name, value| |