diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2014-12-27 19:35:30 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2014-12-27 19:35:30 -0700 |
commit | cd84b27ca45aa6f18f38202fdbc0ecc0ce9f98ef (patch) | |
tree | 8ac4d2e3d1e3c0a3bec8a720ce315f8cb1758c6d /activerecord/test/cases | |
parent | baaad864e8cf3a3f2bf8722bd824635d31d8d280 (diff) | |
parent | a327a9dc583e8b7fea030cfe9cda74af632ef210 (diff) | |
download | rails-cd84b27ca45aa6f18f38202fdbc0ecc0ce9f98ef.tar.gz rails-cd84b27ca45aa6f18f38202fdbc0ecc0ce9f98ef.tar.bz2 rails-cd84b27ca45aa6f18f38202fdbc0ecc0ce9f98ef.zip |
Merge pull request #18220 from kamipo/bigint_primary_key_support
Add bigint primary key support for MySQL.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/primary_keys_test.rb | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/activerecord/test/cases/primary_keys_test.rb b/activerecord/test/cases/primary_keys_test.rb index f19a6ea5e3..2dfc53f132 100644 --- a/activerecord/test/cases/primary_keys_test.rb +++ b/activerecord/test/cases/primary_keys_test.rb @@ -195,6 +195,30 @@ class PrimaryKeyWithNoConnectionTest < ActiveRecord::TestCase end end +class PrimaryKeyAnyTypeTest < ActiveRecord::TestCase + self.use_transactional_fixtures = false + + class Barcode < ActiveRecord::Base + end + + setup do + @connection = ActiveRecord::Base.connection + @connection.create_table(:barcodes, primary_key: "code", id: :string, limit: 42, force: true) + end + + teardown do + @connection.execute("DROP TABLE IF EXISTS barcodes") + end + + def test_any_type_primary_key + assert_equal "code", Barcode.primary_key + + column_type = Barcode.type_for_attribute(Barcode.primary_key) + assert_equal :string, column_type.type + assert_equal 42, column_type.limit + end +end + if current_adapter?(:MysqlAdapter, :Mysql2Adapter) class PrimaryKeyWithAnsiQuotesTest < ActiveRecord::TestCase self.use_transactional_fixtures = false @@ -209,7 +233,7 @@ if current_adapter?(:MysqlAdapter, :Mysql2Adapter) end end -if current_adapter?(:PostgreSQLAdapter) +if current_adapter?(:PostgreSQLAdapter, :MysqlAdapter, :Mysql2Adapter) class PrimaryKeyBigSerialTest < ActiveRecord::TestCase self.use_transactional_fixtures = false @@ -218,17 +242,24 @@ if current_adapter?(:PostgreSQLAdapter) setup do @connection = ActiveRecord::Base.connection - @connection.create_table(:widgets, id: :bigserial) { |t| } + if current_adapter?(:PostgreSQLAdapter) + @connection.create_table(:widgets, id: :bigserial, force: true) + else + @connection.create_table(:widgets, id: :bigint, force: true) + end end teardown do - @connection.drop_table :widgets + @connection.execute("DROP TABLE IF EXISTS widgets") end - def test_bigserial_primary_key - assert_equal "id", Widget.primary_key - assert_equal :integer, Widget.columns_hash[Widget.primary_key].type + test "primary key column type with bigserial" do + column_type = Widget.type_for_attribute(Widget.primary_key) + assert_equal :integer, column_type.type + assert_equal 8, column_type.limit + end + test "primary key with bigserial are automatically numbered" do widget = Widget.create! assert_not_nil widget.id end |