Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
1683410c
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,发现更多精彩内容 >>
未验证
提交
1683410c
编写于
4月 19, 2016
作者:
J
Jeremy Daer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Database comments: Treat blank comments as no comment. Don't dump blank comments.
上级
5fa91521
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
98 addition
and
57 deletion
+98
-57
activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
...tive_record/connection_adapters/abstract/schema_dumper.rb
+1
-1
activerecord/lib/active_record/schema_dumper.rb
activerecord/lib/active_record/schema_dumper.rb
+1
-1
activerecord/test/cases/comment_test.rb
activerecord/test/cases/comment_test.rb
+96
-55
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
浏览文件 @
1683410c
...
@@ -46,7 +46,7 @@ def prepare_column_options(column)
...
@@ -46,7 +46,7 @@ def prepare_column_options(column)
spec
[
:collation
]
=
collation
spec
[
:collation
]
=
collation
end
end
spec
[
:comment
]
=
column
.
comment
.
inspect
if
column
.
comment
spec
[
:comment
]
=
column
.
comment
.
inspect
if
column
.
comment
.
present?
spec
spec
end
end
...
...
activerecord/lib/active_record/schema_dumper.rb
浏览文件 @
1683410c
...
@@ -138,7 +138,7 @@ def table(table, stream)
...
@@ -138,7 +138,7 @@ def table(table, stream)
table_options
=
@connection
.
table_options
(
table
)
table_options
=
@connection
.
table_options
(
table
)
tbl
.
print
", options:
#{
table_options
.
inspect
}
"
unless
table_options
.
blank?
tbl
.
print
", options:
#{
table_options
.
inspect
}
"
unless
table_options
.
blank?
if
comment
=
@connection
.
table_comment
(
table
)
if
comment
=
@connection
.
table_comment
(
table
)
.
presence
tbl
.
print
", comment:
#{
comment
.
inspect
}
"
tbl
.
print
", comment:
#{
comment
.
inspect
}
"
end
end
...
...
activerecord/test/cases/comment_test.rb
浏览文件 @
1683410c
require
'cases/helper'
require
'cases/helper'
require
'support/schema_dumping_helper'
require
'support/schema_dumping_helper'
if
ActiveRecord
::
Base
.
connection
.
supports_comments?
class
CommentTest
<
ActiveRecord
::
TestCase
class
CommentTest
<
ActiveRecord
::
TestCase
include
SchemaDumpingHelper
include
SchemaDumpingHelper
self
.
use_transactional_tests
=
false
if
current_adapter?
(
:Mysql2Adapter
)
self
.
use_transactional_tests
=
false
if
current_adapter?
(
:Mysql2Adapter
)
...
@@ -9,31 +11,49 @@ class Commented < ActiveRecord::Base
...
@@ -9,31 +11,49 @@ class Commented < ActiveRecord::Base
self
.
table_name
=
'commenteds'
self
.
table_name
=
'commenteds'
end
end
def
setup
class
BlankComment
<
ActiveRecord
::
Base
end
setup
do
@connection
=
ActiveRecord
::
Base
.
connection
@connection
=
ActiveRecord
::
Base
.
connection
@connection
.
transaction
do
@connection
.
create_table
(
'commenteds'
,
comment:
'A table with comment'
,
force:
true
)
do
|
t
|
@connection
.
create_table
(
'commenteds'
,
comment:
'A table with comment'
,
force:
true
)
do
|
t
|
t
.
string
'name'
,
comment:
'Comment should help clarify the column purpose'
t
.
string
'name'
,
comment:
'Comment should help clarify the column purpose'
t
.
boolean
'obvious'
,
comment:
'Question is: should you comment obviously named objects?'
t
.
boolean
'obvious'
,
comment:
'Question is: should you comment obviously named objects?'
t
.
string
'content'
t
.
string
'content'
t
.
index
'name'
,
comment:
%Q["Very important" index that powers all the performance.
\n
And it's fun!]
t
.
index
'name'
,
comment:
%Q["Very important" index that powers all the performance.
\n
And it's fun!]
end
end
@connection
.
create_table
(
'blank_comments'
,
comment:
' '
,
force:
true
)
do
|
t
|
t
.
string
:space_comment
,
comment:
' '
t
.
string
:empty_comment
,
comment:
''
t
.
string
:nil_comment
,
comment:
nil
t
.
string
:absent_comment
end
end
Commented
.
reset_column_information
BlankComment
.
reset_column_information
end
end
teardown
do
teardown
do
@connection
.
drop_table
'commenteds'
,
if_exists:
true
@connection
.
drop_table
'commenteds'
,
if_exists:
true
@connection
.
drop_table
'blank_comments'
,
if_exists:
true
end
end
if
ActiveRecord
::
Base
.
connection
.
supports_comments?
def
test_column_created_in_block
def
test_column_created_in_block
Commented
.
reset_column_information
column
=
Commented
.
columns_hash
[
'name'
]
column
=
Commented
.
columns_hash
[
'name'
]
assert_equal
:string
,
column
.
type
assert_equal
:string
,
column
.
type
assert_equal
'Comment should help clarify the column purpose'
,
column
.
comment
assert_equal
'Comment should help clarify the column purpose'
,
column
.
comment
end
end
def
test_blank_columns_created_in_block
%w[ space_comment empty_comment nil_comment absent_comment ]
.
each
do
|
field
|
column
=
BlankComment
.
columns_hash
[
field
]
assert_equal
:string
,
column
.
type
assert_nil
column
.
comment
end
end
def
test_add_column_with_comment_later
def
test_add_column_with_comment_later
@connection
.
add_column
:commenteds
,
:rating
,
:integer
,
comment:
'I am running out of imagination'
@connection
.
add_column
:commenteds
,
:rating
,
:integer
,
comment:
'I am running out of imagination'
Commented
.
reset_column_information
Commented
.
reset_column_information
...
@@ -75,6 +95,7 @@ def test_schema_dump_with_comments
...
@@ -75,6 +95,7 @@ def test_schema_dump_with_comments
@connection
.
change_column
:commenteds
,
:content
,
:string
,
comment:
'Whoa, content describes itself!'
@connection
.
change_column
:commenteds
,
:content
,
:string
,
comment:
'Whoa, content describes itself!'
@connection
.
change_column
:commenteds
,
:obvious
,
:string
,
comment:
nil
@connection
.
change_column
:commenteds
,
:obvious
,
:string
,
comment:
nil
@connection
.
add_index
:commenteds
,
:obvious
,
name:
'idx_obvious'
,
comment:
'We need to see obvious comments'
@connection
.
add_index
:commenteds
,
:obvious
,
name:
'idx_obvious'
,
comment:
'We need to see obvious comments'
# And check that these changes are reflected in dump
# And check that these changes are reflected in dump
output
=
dump_table_schema
'commenteds'
output
=
dump_table_schema
'commenteds'
assert_match
%r[create_table "commenteds",.+
\s
+comment: "A table with comment"]
,
output
assert_match
%r[create_table "commenteds",.+
\s
+comment: "A table with comment"]
,
output
...
@@ -85,5 +106,25 @@ def test_schema_dump_with_comments
...
@@ -85,5 +106,25 @@ def test_schema_dump_with_comments
assert_match
%r[add_index
\s
+.+
\s
+comment: "
\\\"
Very important
\\\"
index that powers all the performance.
\\
nAnd it's fun!"]
,
output
assert_match
%r[add_index
\s
+.+
\s
+comment: "
\\\"
Very important
\\\"
index that powers all the performance.
\\
nAnd it's fun!"]
,
output
assert_match
%r[add_index
\s
+.+
\s
+name: "idx_obvious",.+
\s
+comment: "We need to see obvious comments"]
,
output
assert_match
%r[add_index
\s
+.+
\s
+name: "idx_obvious",.+
\s
+comment: "We need to see obvious comments"]
,
output
end
end
def
test_schema_dump_omits_blank_comments
output
=
dump_table_schema
'blank_comments'
assert_match
%r[create_table "blank_comments"]
,
output
assert_no_match
%r[create_table "blank_comments",.+comment:]
,
output
assert_match
%r[t
\.
string
\s
+"space_comment"
\n
]
,
output
assert_no_match
%r[t
\.
string
\s
+"space_comment", comment:
\n
]
,
output
assert_match
%r[t
\.
string
\s
+"empty_comment"
\n
]
,
output
assert_no_match
%r[t
\.
string
\s
+"empty_comment", comment:
\n
]
,
output
assert_match
%r[t
\.
string
\s
+"nil_comment"
\n
]
,
output
assert_no_match
%r[t
\.
string
\s
+"nil_comment", comment:
\n
]
,
output
assert_match
%r[t
\.
string
\s
+"absent_comment"
\n
]
,
output
assert_no_match
%r[t
\.
string
\s
+"absent_comment", comment:
\n
]
,
output
end
end
end
end
end
# if ActiveRecord::Base.connection.supports_comments?
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录