Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a88b6f25
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 搜索 >>
提交
a88b6f25
编写于
3月 07, 2019
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor AR::Querying to extract `QUERYING_METHODS` list
This makes to ease testing `QUERYING_METHODS`.
上级
b02a6936
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
27 deletion
+33
-27
activerecord/lib/active_record/querying.rb
activerecord/lib/active_record/querying.rb
+17
-13
activerecord/test/cases/relation/delegation_test.rb
activerecord/test/cases/relation/delegation_test.rb
+16
-14
未找到文件。
activerecord/lib/active_record/querying.rb
浏览文件 @
a88b6f25
...
...
@@ -2,19 +2,23 @@
module
ActiveRecord
module
Querying
delegate
:find
,
:take
,
:take!
,
:first
,
:first!
,
:last
,
:last!
,
:exists?
,
:any?
,
:many?
,
:none?
,
:one?
,
to: :all
delegate
:second
,
:second!
,
:third
,
:third!
,
:fourth
,
:fourth!
,
:fifth
,
:fifth!
,
:forty_two
,
:forty_two!
,
:third_to_last
,
:third_to_last!
,
:second_to_last
,
:second_to_last!
,
to: :all
delegate
:first_or_create
,
:first_or_create!
,
:first_or_initialize
,
to: :all
delegate
:find_or_create_by
,
:find_or_create_by!
,
:create_or_find_by
,
:create_or_find_by!
,
:find_or_initialize_by
,
to: :all
delegate
:find_by
,
:find_by!
,
to: :all
delegate
:destroy_all
,
:delete_all
,
:update_all
,
:destroy_by
,
:delete_by
,
to: :all
delegate
:find_each
,
:find_in_batches
,
:in_batches
,
to: :all
delegate
:select
,
:group
,
:order
,
:except
,
:reorder
,
:limit
,
:offset
,
:joins
,
:left_joins
,
:left_outer_joins
,
:or
,
:where
,
:rewhere
,
:preload
,
:eager_load
,
:includes
,
:from
,
:lock
,
:readonly
,
:extending
,
:having
,
:create_with
,
:distinct
,
:references
,
:none
,
:unscope
,
:merge
,
:reselect
,
to: :all
delegate
:count
,
:average
,
:minimum
,
:maximum
,
:sum
,
:calculate
,
to: :all
delegate
:pluck
,
:pick
,
:ids
,
to: :all
QUERYING_METHODS
=
[
:find
,
:find_by
,
:find_by!
,
:take
,
:take!
,
:first
,
:first!
,
:last
,
:last!
,
:second
,
:second!
,
:third
,
:third!
,
:fourth
,
:fourth!
,
:fifth
,
:fifth!
,
:forty_two
,
:forty_two!
,
:third_to_last
,
:third_to_last!
,
:second_to_last
,
:second_to_last!
,
:exists?
,
:any?
,
:many?
,
:none?
,
:one?
,
:first_or_create
,
:first_or_create!
,
:first_or_initialize
,
:find_or_create_by
,
:find_or_create_by!
,
:find_or_initialize_by
,
:create_or_find_by
,
:create_or_find_by!
,
:destroy_all
,
:delete_all
,
:update_all
,
:destroy_by
,
:delete_by
,
:find_each
,
:find_in_batches
,
:in_batches
,
:select
,
:reselect
,
:order
,
:reorder
,
:group
,
:limit
,
:offset
,
:joins
,
:left_joins
,
:left_outer_joins
,
:where
,
:rewhere
,
:preload
,
:eager_load
,
:includes
,
:from
,
:lock
,
:readonly
,
:extending
,
:or
,
:having
,
:create_with
,
:distinct
,
:references
,
:none
,
:unscope
,
:merge
,
:except
,
:count
,
:average
,
:minimum
,
:maximum
,
:sum
,
:calculate
,
:pluck
,
:pick
,
:ids
].
freeze
# :nodoc:
delegate
(
*
QUERYING_METHODS
,
to: :all
)
# Executes a custom SQL query against your database and returns all the results. The results will
# be returned as an array, with the requested columns encapsulated as attributes of the model you call
...
...
activerecord/test/cases/relation/delegation_test.rb
浏览文件 @
a88b6f25
...
...
@@ -44,26 +44,28 @@ def target
end
class
QueryingMethodsDelegationTest
<
ActiveRecord
::
TestCase
QUERYING_METHODS
=
[
:find
,
:take
,
:take!
,
:first
,
:first!
,
:last
,
:last!
,
:exists?
,
:any?
,
:many?
,
:none?
,
:one?
,
:second
,
:second!
,
:third
,
:third!
,
:fourth
,
:fourth!
,
:fifth
,
:fifth!
,
:forty_two
,
:forty_two!
,
:third_to_last
,
:third_to_last!
,
:second_to_last
,
:second_to_last!
,
:first_or_create
,
:first_or_create!
,
:first_or_initialize
,
:find_or_create_by
,
:find_or_create_by!
,
:create_or_find_by
,
:create_or_find_by!
,
:find_or_initialize_by
,
:find_by
,
:find_by!
,
:destroy_all
,
:delete_all
,
:update_all
,
:delete_by
,
:destroy_by
,
:find_each
,
:find_in_batches
,
:in_batches
,
:select
,
:group
,
:order
,
:except
,
:reorder
,
:limit
,
:offset
,
:joins
,
:left_joins
,
:left_outer_joins
,
:or
,
:where
,
:rewhere
,
:preload
,
:eager_load
,
:includes
,
:from
,
:lock
,
:readonly
,
:extending
,
:having
,
:create_with
,
:distinct
,
:references
,
:none
,
:unscope
,
:merge
,
:count
,
:average
,
:minimum
,
:maximum
,
:sum
,
:calculate
,
:pluck
,
:pick
,
:ids
,
:reselect
,
]
QUERYING_METHODS
=
ActiveRecord
::
Batches
.
public_instance_methods
(
false
)
+
ActiveRecord
::
Calculations
.
public_instance_methods
(
false
)
+
ActiveRecord
::
FinderMethods
.
public_instance_methods
(
false
)
-
[
:raise_record_not_found_exception!
]
+
ActiveRecord
::
SpawnMethods
.
public_instance_methods
(
false
)
-
[
:spawn
,
:merge!
,
:only
]
+
ActiveRecord
::
QueryMethods
.
public_instance_methods
(
false
).
reject
{
|
method
|
method
.
to_s
.
end_with?
(
"="
,
"!"
,
"value"
,
"values"
,
"clause"
)
}
-
[
:reverse_order
,
:arel
,
:extensions
]
+
[
:any?
,
:many?
,
:none?
,
:one?
,
:first_or_create
,
:first_or_create!
,
:first_or_initialize
,
:find_or_create_by
,
:find_or_create_by!
,
:find_or_initialize_by
,
:create_or_find_by
,
:create_or_find_by!
,
:destroy_all
,
:delete_all
,
:update_all
,
:delete_by
,
:destroy_by
]
def
test_delegate_querying_methods
klass
=
Class
.
new
(
ActiveRecord
::
Base
)
do
self
.
table_name
=
"posts"
end
assert_equal
QUERYING_METHODS
.
sort
,
ActiveRecord
::
Querying
::
QUERYING_METHODS
.
sort
QUERYING_METHODS
.
each
do
|
method
|
assert_respond_to
klass
.
all
,
method
assert_respond_to
klass
,
method
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录