Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6783bcab
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6783bcab
编写于
12月 26, 2017
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SQLite: Add more test cases for adding primary key
上级
9507b4f0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
100 addition
and
58 deletion
+100
-58
activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
...ecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
+52
-0
activerecord/test/cases/migration/compatibility_test.rb
activerecord/test/cases/migration/compatibility_test.rb
+48
-58
未找到文件。
activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
浏览文件 @
6783bcab
...
...
@@ -401,6 +401,58 @@ def test_copy_table_with_composite_primary_keys
Barcode
.
reset_column_information
end
def
test_custom_primary_key_in_create_table
connection
=
Barcode
.
connection
connection
.
create_table
:barcodes
,
id:
false
,
force:
true
do
|
t
|
t
.
primary_key
:id
,
:string
end
assert_equal
"id"
,
connection
.
primary_key
(
"barcodes"
)
custom_pk
=
Barcode
.
columns_hash
[
"id"
]
assert_equal
:string
,
custom_pk
.
type
assert_not
custom_pk
.
null
ensure
Barcode
.
reset_column_information
end
def
test_custom_primary_key_in_change_table
connection
=
Barcode
.
connection
connection
.
create_table
:barcodes
,
id:
false
,
force:
true
do
|
t
|
t
.
integer
:dummy
end
connection
.
change_table
:barcodes
do
|
t
|
t
.
primary_key
:id
,
:string
end
assert_equal
"id"
,
connection
.
primary_key
(
"barcodes"
)
custom_pk
=
Barcode
.
columns_hash
[
"id"
]
assert_equal
:string
,
custom_pk
.
type
assert_not
custom_pk
.
null
ensure
Barcode
.
reset_column_information
end
def
test_add_column_with_custom_primary_key
connection
=
Barcode
.
connection
connection
.
create_table
:barcodes
,
id:
false
,
force:
true
do
|
t
|
t
.
integer
:dummy
end
connection
.
add_column
:barcodes
,
:id
,
:string
,
primary_key:
true
assert_equal
"id"
,
connection
.
primary_key
(
"barcodes"
)
custom_pk
=
Barcode
.
columns_hash
[
"id"
]
assert_equal
:string
,
custom_pk
.
type
assert_not
custom_pk
.
null
ensure
Barcode
.
reset_column_information
end
def
test_supports_extensions
assert_not
@conn
.
supports_extensions?
,
"does not support extensions"
end
...
...
activerecord/test/cases/migration/compatibility_test.rb
浏览文件 @
6783bcab
...
...
@@ -179,9 +179,7 @@ def change
@migration
.
migrate
(
:up
)
legacy_pk
=
LegacyPrimaryKey
.
columns_hash
[
"id"
]
assert_not
legacy_pk
.
bigint?
assert_not
legacy_pk
.
null
assert_legacy_primary_key
legacy_ref
=
LegacyPrimaryKey
.
columns_hash
[
"legacy_ref_id"
]
assert_not
legacy_ref
.
bigint?
...
...
@@ -216,74 +214,50 @@ def change
assert_match
%r{create_table "legacy_primary_keys", id: :integer, default: nil}
,
schema
end
if
current_adapter?
(
:Mysql2Adapter
,
:PostgreSQLAdapter
)
def
test_legacy_primary_key_in_create_table_should_be_integer
@migration
=
Class
.
new
(
migration_class
)
{
def
change
create_table
:legacy_primary_keys
,
id:
false
do
|
t
|
t
.
primary_key
:id
end
def
test_legacy_primary_key_in_create_table_should_be_integer
@migration
=
Class
.
new
(
migration_class
)
{
def
change
create_table
:legacy_primary_keys
,
id:
false
do
|
t
|
t
.
primary_key
:id
end
}.
new
end
}.
new
@migration
.
migrate
(
:up
)
@migration
.
migrate
(
:up
)
schema
=
dump_table_schema
"legacy_primary_keys"
assert_match
%r{create_table "legacy_primary_keys", id: :(?:integer|serial), (?!default: nil)}
,
schema
end
assert_legacy_primary_key
end
def
test_legacy_primary_key_in_change_table_should_be_integer
@migration
=
Class
.
new
(
migration_class
)
{
def
change
create_table
:legacy_primary_keys
,
id:
false
do
|
t
|
t
.
integer
:dummy
end
change_table
:legacy_primary_keys
do
|
t
|
t
.
primary_key
:id
end
def
test_legacy_primary_key_in_change_table_should_be_integer
@migration
=
Class
.
new
(
migration_class
)
{
def
change
create_table
:legacy_primary_keys
,
id:
false
do
|
t
|
t
.
integer
:dummy
end
}.
new
@migration
.
migrate
(
:up
)
schema
=
dump_table_schema
"legacy_primary_keys"
assert_match
%r{create_table "legacy_primary_keys", id: :(?:integer|serial), (?!default: nil)}
,
schema
end
def
test_add_column_with_legacy_primary_key_should_be_integer
@migration
=
Class
.
new
(
migration_class
)
{
def
change
create_table
:legacy_primary_keys
,
id:
false
do
|
t
|
t
.
integer
:dummy
end
add_column
:legacy_primary_keys
,
:id
,
:primary_key
change_table
:legacy_primary_keys
do
|
t
|
t
.
primary_key
:id
end
}.
new
end
}.
new
@migration
.
migrate
(
:up
)
@migration
.
migrate
(
:up
)
schema
=
dump_table_schema
"legacy_primary_keys"
assert_match
%r{create_table "legacy_primary_keys", id: :(?:integer|serial), (?!default: nil)}
,
schema
end
assert_legacy_primary_key
end
if
current_adapter?
(
:SQLite3Adapter
)
def
test_add_column_with_legacy_primary_key_should_work
@migration
=
Class
.
new
(
migration_class
)
{
def
change
create_table
:legacy_primary_keys
,
id:
false
do
|
t
|
t
.
integer
:dummy
end
add_column
:legacy_primary_keys
,
:id
,
:primary_key
def
test_add_column_with_legacy_primary_key_should_be_integer
@migration
=
Class
.
new
(
migration_class
)
{
def
change
create_table
:legacy_primary_keys
,
id:
false
do
|
t
|
t
.
integer
:dummy
end
}.
new
add_column
:legacy_primary_keys
,
:id
,
:primary_key
end
}.
new
@migration
.
migrate
(
:up
)
@migration
.
migrate
(
:up
)
assert_equal
"id"
,
LegacyPrimaryKey
.
primary_key
legacy_pk
=
LegacyPrimaryKey
.
columns_hash
[
"id"
]
assert_not
legacy_pk
.
null
end
assert_legacy_primary_key
end
def
test_legacy_join_table_foreign_keys_should_be_integer
...
...
@@ -352,6 +326,22 @@ def change
assert_match
%r{create_table "legacy_primary_keys", id: :bigint, default: nil}
,
schema
end
end
private
def
assert_legacy_primary_key
assert_equal
"id"
,
LegacyPrimaryKey
.
primary_key
legacy_pk
=
LegacyPrimaryKey
.
columns_hash
[
"id"
]
assert_equal
:integer
,
legacy_pk
.
type
assert_not
legacy_pk
.
bigint?
assert_not
legacy_pk
.
null
if
current_adapter?
(
:Mysql2Adapter
,
:PostgreSQLAdapter
)
schema
=
dump_table_schema
"legacy_primary_keys"
assert_match
%r{create_table "legacy_primary_keys", id: :(?:integer|serial), (?!default: nil)}
,
schema
end
end
end
module
LegacyPrimaryKeyTest
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录