aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/primary_keys_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/primary_keys_test.rb')
-rw-r--r--activerecord/test/cases/primary_keys_test.rb43
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