Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
977df647
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,发现更多精彩内容 >>
提交
977df647
编写于
1月 12, 2012
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
moving more column renaming tests
上级
e6f79603
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
75 addition
and
71 deletion
+75
-71
activerecord/test/cases/migration/rename_column_test.rb
activerecord/test/cases/migration/rename_column_test.rb
+75
-0
activerecord/test/cases/migration_test.rb
activerecord/test/cases/migration_test.rb
+0
-71
未找到文件。
activerecord/test/cases/migration/rename_column_test.rb
浏览文件 @
977df647
...
...
@@ -111,6 +111,81 @@ def test_change_type_of_not_null_column
change_column
"test_models"
,
"updated_at"
,
:datetime
,
:null
=>
false
change_column
"test_models"
,
"updated_at"
,
:datetime
,
:null
=>
true
end
def
test_change_column_nullability
add_column
"test_models"
,
"funny"
,
:boolean
assert
TestModel
.
columns_hash
[
"funny"
].
null
,
"Column 'funny' must initially allow nulls"
change_column
"test_models"
,
"funny"
,
:boolean
,
:null
=>
false
,
:default
=>
true
TestModel
.
reset_column_information
refute
TestModel
.
columns_hash
[
"funny"
].
null
,
"Column 'funny' must *not* allow nulls at this point"
change_column
"test_models"
,
"funny"
,
:boolean
,
:null
=>
true
TestModel
.
reset_column_information
assert
TestModel
.
columns_hash
[
"funny"
].
null
,
"Column 'funny' must allow nulls again at this point"
end
def
test_change_column
add_column
'test_models'
,
'age'
,
:integer
add_column
'test_models'
,
'approved'
,
:boolean
,
:default
=>
true
label
=
"test_change_column Columns"
old_columns
=
connection
.
columns
(
TestModel
.
table_name
,
label
)
assert
old_columns
.
find
{
|
c
|
c
.
name
==
'age'
&&
c
.
type
==
:integer
}
change_column
"test_models"
,
"age"
,
:string
new_columns
=
connection
.
columns
(
TestModel
.
table_name
,
label
)
refute
new_columns
.
find
{
|
c
|
c
.
name
==
'age'
and
c
.
type
==
:integer
}
assert
new_columns
.
find
{
|
c
|
c
.
name
==
'age'
and
c
.
type
==
:string
}
old_columns
=
connection
.
columns
(
TestModel
.
table_name
,
label
)
assert
old_columns
.
find
{
|
c
|
c
.
name
==
'approved'
&&
c
.
type
==
:boolean
&&
c
.
default
==
true
}
change_column
:test_models
,
:approved
,
:boolean
,
:default
=>
false
new_columns
=
connection
.
columns
(
TestModel
.
table_name
,
label
)
refute
new_columns
.
find
{
|
c
|
c
.
name
==
'approved'
and
c
.
type
==
:boolean
and
c
.
default
==
true
}
assert
new_columns
.
find
{
|
c
|
c
.
name
==
'approved'
and
c
.
type
==
:boolean
and
c
.
default
==
false
}
change_column
:test_models
,
:approved
,
:boolean
,
:default
=>
true
end
def
test_change_column_with_nil_default
add_column
"test_models"
,
"contributor"
,
:boolean
,
:default
=>
true
assert
TestModel
.
new
.
contributor?
change_column
"test_models"
,
"contributor"
,
:boolean
,
:default
=>
nil
TestModel
.
reset_column_information
refute
TestModel
.
new
.
contributor?
assert_nil
TestModel
.
new
.
contributor
end
def
test_change_column_with_new_default
add_column
"test_models"
,
"administrator"
,
:boolean
,
:default
=>
true
assert
TestModel
.
new
.
administrator?
change_column
"test_models"
,
"administrator"
,
:boolean
,
:default
=>
false
TestModel
.
reset_column_information
refute
TestModel
.
new
.
administrator?
end
def
test_change_column_default
add_column
"test_models"
,
"first_name"
,
:string
connection
.
change_column_default
"test_models"
,
"first_name"
,
"Tester"
assert_equal
"Tester"
,
TestModel
.
new
.
first_name
end
def
test_change_column_default_to_null
add_column
"test_models"
,
"first_name"
,
:string
connection
.
change_column_default
"test_models"
,
"first_name"
,
nil
assert_nil
TestModel
.
new
.
first_name
end
end
end
end
activerecord/test/cases/migration_test.rb
浏览文件 @
977df647
...
...
@@ -142,19 +142,6 @@ def test_rename_table
end
end
def
test_change_column_nullability
Person
.
delete_all
Person
.
connection
.
add_column
"people"
,
"funny"
,
:boolean
Person
.
reset_column_information
assert
Person
.
columns_hash
[
"funny"
].
null
,
"Column 'funny' must initially allow nulls"
Person
.
connection
.
change_column
"people"
,
"funny"
,
:boolean
,
:null
=>
false
,
:default
=>
true
Person
.
reset_column_information
assert
!
Person
.
columns_hash
[
"funny"
].
null
,
"Column 'funny' must *not* allow nulls at this point"
Person
.
connection
.
change_column
"people"
,
"funny"
,
:boolean
,
:null
=>
true
Person
.
reset_column_information
assert
Person
.
columns_hash
[
"funny"
].
null
,
"Column 'funny' must allow nulls again at this point"
end
def
test_rename_table_with_an_index
begin
ActiveRecord
::
Base
.
connection
.
create_table
:octopuses
do
|
t
|
...
...
@@ -178,64 +165,6 @@ def test_rename_table_with_an_index
end
end
def
test_change_column
Person
.
connection
.
add_column
'people'
,
'age'
,
:integer
label
=
"test_change_column Columns"
old_columns
=
Person
.
connection
.
columns
(
Person
.
table_name
,
label
)
assert
old_columns
.
find
{
|
c
|
c
.
name
==
'age'
and
c
.
type
==
:integer
}
assert_nothing_raised
{
Person
.
connection
.
change_column
"people"
,
"age"
,
:string
}
new_columns
=
Person
.
connection
.
columns
(
Person
.
table_name
,
label
)
assert_nil
new_columns
.
find
{
|
c
|
c
.
name
==
'age'
and
c
.
type
==
:integer
}
assert
new_columns
.
find
{
|
c
|
c
.
name
==
'age'
and
c
.
type
==
:string
}
old_columns
=
Topic
.
connection
.
columns
(
Topic
.
table_name
,
label
)
assert
old_columns
.
find
{
|
c
|
c
.
name
==
'approved'
and
c
.
type
==
:boolean
and
c
.
default
==
true
}
assert_nothing_raised
{
Topic
.
connection
.
change_column
:topics
,
:approved
,
:boolean
,
:default
=>
false
}
new_columns
=
Topic
.
connection
.
columns
(
Topic
.
table_name
,
label
)
assert_nil
new_columns
.
find
{
|
c
|
c
.
name
==
'approved'
and
c
.
type
==
:boolean
and
c
.
default
==
true
}
assert
new_columns
.
find
{
|
c
|
c
.
name
==
'approved'
and
c
.
type
==
:boolean
and
c
.
default
==
false
}
assert_nothing_raised
{
Topic
.
connection
.
change_column
:topics
,
:approved
,
:boolean
,
:default
=>
true
}
end
def
test_change_column_with_nil_default
Person
.
connection
.
add_column
"people"
,
"contributor"
,
:boolean
,
:default
=>
true
Person
.
reset_column_information
assert
Person
.
new
.
contributor?
assert_nothing_raised
{
Person
.
connection
.
change_column
"people"
,
"contributor"
,
:boolean
,
:default
=>
nil
}
Person
.
reset_column_information
assert
!
Person
.
new
.
contributor?
assert_nil
Person
.
new
.
contributor
ensure
Person
.
connection
.
remove_column
(
"people"
,
"contributor"
)
rescue
nil
end
def
test_change_column_with_new_default
Person
.
connection
.
add_column
"people"
,
"administrator"
,
:boolean
,
:default
=>
true
Person
.
reset_column_information
assert
Person
.
new
.
administrator?
assert_nothing_raised
{
Person
.
connection
.
change_column
"people"
,
"administrator"
,
:boolean
,
:default
=>
false
}
Person
.
reset_column_information
assert
!
Person
.
new
.
administrator?
ensure
Person
.
connection
.
remove_column
(
"people"
,
"administrator"
)
rescue
nil
end
def
test_change_column_default
Person
.
connection
.
change_column_default
"people"
,
"first_name"
,
"Tester"
Person
.
reset_column_information
assert_equal
"Tester"
,
Person
.
new
.
first_name
end
def
test_change_column_default_to_null
Person
.
connection
.
change_column_default
"people"
,
"first_name"
,
nil
Person
.
reset_column_information
assert_nil
Person
.
new
.
first_name
end
def
test_add_table
assert
!
Reminder
.
table_exists?
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录