Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
212c28ac
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
212c28ac
编写于
11月 06, 2018
作者:
R
Ryuta Kamizono
提交者:
GitHub
11月 06, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #34384 from eugeneius/inspect_with_non_primary_key_id_attribute
Fix inspect with non-primary key id attribute
上级
a8c06c2d
65cd0fda
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
26 addition
and
3 deletion
+26
-3
activerecord/lib/active_record/attribute_methods.rb
activerecord/lib/active_record/attribute_methods.rb
+1
-1
activerecord/lib/active_record/core.rb
activerecord/lib/active_record/core.rb
+2
-2
activerecord/test/cases/attribute_methods_test.rb
activerecord/test/cases/attribute_methods_test.rb
+7
-0
activerecord/test/cases/core_test.rb
activerecord/test/cases/core_test.rb
+12
-0
activerecord/test/models/topic.rb
activerecord/test/models/topic.rb
+4
-0
未找到文件。
activerecord/lib/active_record/attribute_methods.rb
浏览文件 @
212c28ac
...
...
@@ -328,7 +328,7 @@ def attributes
# person.attribute_for_inspect(:tag_ids)
# # => "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]"
def
attribute_for_inspect
(
attr_name
)
value
=
read_attribute
(
attr_name
)
value
=
_
read_attribute
(
attr_name
)
format_for_inspect
(
value
)
end
...
...
activerecord/lib/active_record/core.rb
浏览文件 @
212c28ac
...
...
@@ -498,7 +498,7 @@ def inspect
inspection
=
if
defined?
(
@attributes
)
&&
@attributes
self
.
class
.
attribute_names
.
collect
do
|
name
|
if
has_attribute?
(
name
)
attr
=
read_attribute
(
name
)
attr
=
_
read_attribute
(
name
)
value
=
if
attr
.
nil?
attr
.
inspect
else
...
...
@@ -528,7 +528,7 @@ def pretty_print(pp)
pp
.
text
attr_name
pp
.
text
":"
pp
.
breakable
value
=
read_attribute
(
attr_name
)
value
=
_
read_attribute
(
attr_name
)
value
=
inspection_filter
.
filter_param
(
attr_name
,
value
)
unless
value
.
nil?
pp
.
pp
value
end
...
...
activerecord/test/cases/attribute_methods_test.rb
浏览文件 @
212c28ac
...
...
@@ -56,6 +56,13 @@ def setup
assert_equal
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]"
,
t
.
attribute_for_inspect
(
:content
)
end
test
"attribute_for_inspect with a non-primary key id attribute"
do
t
=
topics
(
:first
).
becomes
(
TitlePrimaryKeyTopic
)
t
.
title
=
"The First Topic Now Has A Title With
\n
Newlines And More Than 50 Characters"
assert_equal
"1"
,
t
.
attribute_for_inspect
(
:id
)
end
test
"attribute_present"
do
t
=
Topic
.
new
t
.
title
=
"hello there!"
...
...
activerecord/test/cases/core_test.rb
浏览文件 @
212c28ac
...
...
@@ -30,6 +30,11 @@ def test_inspect_limited_select_instance
assert_equal
%(#<Topic id: 1, title: "The First Topic">)
,
Topic
.
all
.
merge!
(
select:
"id, title"
,
where:
"id = 1"
).
first
.
inspect
end
def
test_inspect_instance_with_non_primary_key_id_attribute
topic
=
topics
(
:first
).
becomes
(
TitlePrimaryKeyTopic
)
assert_match
(
/id: 1/
,
topic
.
inspect
)
end
def
test_inspect_class_without_table
assert_equal
"NonExistentTable(Table doesn't exist)"
,
NonExistentTable
.
inspect
end
...
...
@@ -110,4 +115,11 @@ def inspect
PP
.
pp
(
subtopic
.
new
,
StringIO
.
new
(
actual
))
assert_equal
"inspecting topic
\n
"
,
actual
end
def
test_pretty_print_with_non_primary_key_id_attribute
topic
=
topics
(
:first
).
becomes
(
TitlePrimaryKeyTopic
)
actual
=
+
""
PP
.
pp
(
topic
,
StringIO
.
new
(
actual
))
assert_match
(
/id: 1/
,
actual
)
end
end
activerecord/test/models/topic.rb
浏览文件 @
212c28ac
...
...
@@ -138,6 +138,10 @@ def blank?
end
end
class
TitlePrimaryKeyTopic
<
Topic
self
.
primary_key
=
:title
end
module
Web
class
Topic
<
ActiveRecord
::
Base
has_many
:replies
,
dependent: :destroy
,
foreign_key:
"parent_id"
,
class_name:
"Web::Reply"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录