Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
20ea8df6
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 搜索 >>
提交
20ea8df6
编写于
4月 27, 2012
作者:
J
Jon Leighton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more deprecations manually fixed
上级
0ed05b0e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
53 addition
and
58 deletion
+53
-58
activerecord/test/cases/associations/eager_test.rb
activerecord/test/cases/associations/eager_test.rb
+31
-31
activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
...associations/has_and_belongs_to_many_associations_test.rb
+7
-7
activerecord/test/cases/finder_test.rb
activerecord/test/cases/finder_test.rb
+15
-20
未找到文件。
activerecord/test/cases/associations/eager_test.rb
浏览文件 @
20ea8df6
...
...
@@ -61,10 +61,10 @@ def test_loading_with_one_association_with_non_preload
end
def
test_loading_conditions_with_or
posts
=
authors
(
:david
).
posts
.
references
(
:comments
).
fin
d
(
:
all
,
:include
=>
:comments
,
:
conditions
=>
"comments.body like 'Normal%' OR comments.
#{
QUOTED_TYPE
}
= 'SpecialComment'"
)
posts
=
authors
(
:david
).
posts
.
references
(
:comments
).
scope
d
(
:
includes
=>
:comments
,
:
where
=>
"comments.body like 'Normal%' OR comments.
#{
QUOTED_TYPE
}
= 'SpecialComment'"
)
.
all
assert_nil
posts
.
detect
{
|
p
|
p
.
author_id
!=
authors
(
:david
).
id
},
"expected to find only david's posts"
end
...
...
@@ -154,8 +154,8 @@ def test_including_duplicate_objects_from_belongs_to
popular_post
.
readers
.
create!
(
:person
=>
people
(
:michael
))
popular_post
.
readers
.
create!
(
:person
=>
people
(
:david
))
readers
=
Reader
.
scoped
(
:
conditions
=>
[
"post_id = ?"
,
popular_post
.
id
],
:include
=>
{
:post
=>
:comments
}).
all
readers
=
Reader
.
scoped
(
:
where
=>
[
"post_id = ?"
,
popular_post
.
id
],
:include
s
=>
{
:post
=>
:comments
}).
all
readers
.
each
do
|
reader
|
assert_equal
[
comment
],
reader
.
post
.
comments
end
...
...
@@ -167,8 +167,8 @@ def test_including_duplicate_objects_from_has_many
car_post
.
categories
<<
categories
(
:technology
)
comment
=
car_post
.
comments
.
create!
(
:body
=>
"hmm"
)
categories
=
Category
.
scoped
(
:
conditions
=>
{
'posts.id'
=>
car_post
.
id
},
:include
=>
{
:posts
=>
:comments
}).
all
categories
=
Category
.
scoped
(
:
where
=>
{
'posts.id'
=>
car_post
.
id
},
:include
s
=>
{
:posts
=>
:comments
}).
all
categories
.
each
do
|
category
|
assert_equal
[
comment
],
category
.
posts
[
0
].
comments
end
...
...
@@ -491,7 +491,7 @@ def test_eager_with_has_many_through_an_sti_join_model_with_conditions_on_both
end
def
test_eager_with_has_many_through_join_model_with_conditions
assert_equal
Author
.
scoped
(
:include
=>
:hello_post_comments
,
assert_equal
Author
.
scoped
(
:include
s
=>
:hello_post_comments
,
:order
=>
'authors.id'
).
first
.
hello_post_comments
.
sort_by
(
&
:id
),
Author
.
scoped
(
:order
=>
'authors.id'
).
first
.
hello_post_comments
.
sort_by
(
&
:id
)
end
...
...
@@ -565,16 +565,16 @@ def test_eager_with_has_many_and_limit_and_high_offset
def
test_eager_with_has_many_and_limit_and_high_offset_and_multiple_array_conditions
assert_queries
(
1
)
do
posts
=
Post
.
references
(
:authors
,
:comments
).
scoped
(
:include
=>
[
:author
,
:comments
],
:limit
=>
2
,
:offset
=>
10
,
:
conditions
=>
[
"authors.name = ? and comments.body = ?"
,
'David'
,
'go crazy'
]).
all
scoped
(
:include
s
=>
[
:author
,
:comments
],
:limit
=>
2
,
:offset
=>
10
,
:
where
=>
[
"authors.name = ? and comments.body = ?"
,
'David'
,
'go crazy'
]).
all
assert_equal
0
,
posts
.
size
end
end
def
test_eager_with_has_many_and_limit_and_high_offset_and_multiple_hash_conditions
assert_queries
(
1
)
do
posts
=
Post
.
scoped
(
:include
=>
[
:author
,
:comments
],
:limit
=>
2
,
:offset
=>
10
,
:
conditions
=>
{
'authors.name'
=>
'David'
,
'comments.body'
=>
'go crazy'
}).
all
posts
=
Post
.
scoped
(
:include
s
=>
[
:author
,
:comments
],
:limit
=>
2
,
:offset
=>
10
,
:
where
=>
{
'authors.name'
=>
'David'
,
'comments.body'
=>
'go crazy'
}).
all
assert_equal
0
,
posts
.
size
end
end
...
...
@@ -702,8 +702,8 @@ def test_eager_habtm_with_association_inheritance
def
test_eager_with_has_one_dependent_does_not_destroy_dependent
assert_not_nil
companies
(
:first_firm
).
account
f
=
Firm
.
scoped
(
:include
=>
:account
,
:
conditions
=>
[
"companies.name = ?"
,
"37signals"
]).
first
f
=
Firm
.
scoped
(
:include
s
=>
:account
,
:
where
=>
[
"companies.name = ?"
,
"37signals"
]).
first
assert_not_nil
f
.
account
assert_equal
companies
(
:first_firm
,
:reload
).
account
,
f
.
account
end
...
...
@@ -777,45 +777,45 @@ def find_all_ordered(className, include=nil)
def
test_limited_eager_with_order
assert_equal
(
posts
(
:thinking
,
:sti_comments
),
Post
.
fin
d
(
:
all
,
:include
=>
[
:author
,
:comments
],
:conditions
=>
{
'authors.name'
=>
'David'
},
Post
.
scope
d
(
:
includes
=>
[
:author
,
:comments
],
:where
=>
{
'authors.name'
=>
'David'
},
:order
=>
'UPPER(posts.title)'
,
:limit
=>
2
,
:offset
=>
1
)
)
.
all
)
assert_equal
(
posts
(
:sti_post_and_comments
,
:sti_comments
),
Post
.
fin
d
(
:
all
,
:include
=>
[
:author
,
:comments
],
:conditions
=>
{
'authors.name'
=>
'David'
},
Post
.
scope
d
(
:
includes
=>
[
:author
,
:comments
],
:where
=>
{
'authors.name'
=>
'David'
},
:order
=>
'UPPER(posts.title) DESC'
,
:limit
=>
2
,
:offset
=>
1
)
)
.
all
)
end
def
test_limited_eager_with_multiple_order_columns
assert_equal
(
posts
(
:thinking
,
:sti_comments
),
Post
.
fin
d
(
:
all
,
:include
=>
[
:author
,
:comments
],
:conditions
=>
{
'authors.name'
=>
'David'
},
Post
.
scope
d
(
:
includes
=>
[
:author
,
:comments
],
:where
=>
{
'authors.name'
=>
'David'
},
:order
=>
[
'UPPER(posts.title)'
,
'posts.id'
],
:limit
=>
2
,
:offset
=>
1
)
)
.
all
)
assert_equal
(
posts
(
:sti_post_and_comments
,
:sti_comments
),
Post
.
fin
d
(
:
all
,
:include
=>
[
:author
,
:comments
],
:conditions
=>
{
'authors.name'
=>
'David'
},
Post
.
scope
d
(
:
includes
=>
[
:author
,
:comments
],
:where
=>
{
'authors.name'
=>
'David'
},
:order
=>
[
'UPPER(posts.title) DESC'
,
'posts.id'
],
:limit
=>
2
,
:offset
=>
1
)
)
.
all
)
end
def
test_limited_eager_with_numeric_in_association
assert_equal
(
people
(
:david
,
:susan
),
Person
.
references
(
:number1_fans_people
).
fin
d
(
:
all
,
:include
=>
[
:readers
,
:primary_contact
,
:number1_fan
],
:
conditions
=>
"number1_fans_people.first_name like 'M%'"
,
Person
.
references
(
:number1_fans_people
).
scope
d
(
:
includes
=>
[
:readers
,
:primary_contact
,
:number1_fan
],
:
where
=>
"number1_fans_people.first_name like 'M%'"
,
:order
=>
'people.id'
,
:limit
=>
2
,
:offset
=>
0
)
)
.
all
)
end
...
...
activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
浏览文件 @
20ea8df6
...
...
@@ -681,10 +681,10 @@ def test_habtm_respects_select_query_method
def
test_join_table_alias
assert_equal
(
3
,
Developer
.
references
(
:developers_projects_join
).
fin
d
(
:
all
,
:include
=>
{
:projects
=>
:developers
},
:
conditions
=>
'developers_projects_join.joined_on IS NOT NULL'
).
size
Developer
.
references
(
:developers_projects_join
).
scope
d
(
:
includes
=>
{
:projects
=>
:developers
},
:
where
=>
'developers_projects_join.joined_on IS NOT NULL'
).
to_a
.
size
)
end
...
...
@@ -697,10 +697,10 @@ def test_join_with_group
assert_equal
(
3
,
Developer
.
references
(
:developers_projects_join
).
fin
d
(
:
all
,
:include
=>
{
:projects
=>
:developers
},
:conditions
=>
'developers_projects_join.joined_on IS NOT NULL'
,
Developer
.
references
(
:developers_projects_join
).
scope
d
(
:
includes
=>
{
:projects
=>
:developers
},
:where
=>
'developers_projects_join.joined_on IS NOT NULL'
,
:group
=>
group
.
join
(
","
)
).
size
).
to_a
.
size
)
end
...
...
activerecord/test/cases/finder_test.rb
浏览文件 @
20ea8df6
...
...
@@ -981,11 +981,10 @@ def test_dynamic_finder_with_invalid_params
end
def
test_find_all_with_join
developers_on_project_one
=
Developer
.
find
(
:all
,
developers_on_project_one
=
Developer
.
scoped
(
:joins
=>
'LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id'
,
:
conditions
=>
'project_id=1'
)
:
where
=>
'project_id=1'
)
.
all
assert_equal
3
,
developers_on_project_one
.
length
developer_names
=
developers_on_project_one
.
map
{
|
d
|
d
.
name
}
assert
developer_names
.
include?
(
'David'
)
...
...
@@ -993,17 +992,15 @@ def test_find_all_with_join
end
def
test_joins_dont_clobber_id
first
=
Firm
.
find
(
:first
,
first
=
Firm
.
scoped
(
:joins
=>
'INNER JOIN companies clients ON clients.firm_id = companies.id'
,
:
conditions
=>
'companies.id = 1'
)
:
where
=>
'companies.id = 1'
)
.
first
assert_equal
1
,
first
.
id
end
def
test_joins_with_string_array
person_with_reader_and_post
=
Post
.
find
(
:all
,
person_with_reader_and_post
=
Post
.
scoped
(
:joins
=>
[
"INNER JOIN categorizations ON categorizations.post_id = posts.id"
,
"INNER JOIN categories ON categories.id = categorizations.category_id AND categories.type = 'SpecialCategory'"
...
...
@@ -1065,14 +1062,13 @@ def test_select_rows
def
test_find_with_order_on_included_associations_with_construct_finder_sql_for_association_limiting_and_is_distinct
assert_equal
2
,
Post
.
scoped
(
:includes
=>
{
:authors
=>
:author_address
},
:order
=>
'author_addresses.id DESC '
,
:limit
=>
2
).
all
.
size
assert_equal
3
,
Post
.
scoped
(
:include
=>
{
:author
=>
:author_address
,
:authors
=>
:author_address
},
assert_equal
3
,
Post
.
scoped
(
:include
s
=>
{
:author
=>
:author_address
,
:authors
=>
:author_address
},
:order
=>
'author_addresses_authors.id DESC '
,
:limit
=>
3
).
all
.
size
end
def
test_find_with_nil_inside_set_passed_for_one_attribute
client_of
=
Company
.
find
(
:all
,
:conditions
=>
{
client_of
=
Company
.
scoped
(
:where
=>
{
:client_of
=>
[
2
,
1
,
nil
],
:name
=>
[
'37signals'
,
'Summit'
,
'Microsoft'
]
},
:order
=>
'client_of DESC'
...
...
@@ -1083,9 +1079,8 @@ def test_find_with_nil_inside_set_passed_for_one_attribute
end
def
test_find_with_nil_inside_set_passed_for_attribute
client_of
=
Company
.
find
(
:all
,
:conditions
=>
{
:client_of
=>
[
nil
]
},
client_of
=
Company
.
scoped
(
:where
=>
{
:client_of
=>
[
nil
]
},
:order
=>
'client_of DESC'
).
map
{
|
x
|
x
.
client_of
}
...
...
@@ -1093,10 +1088,10 @@ def test_find_with_nil_inside_set_passed_for_attribute
end
def
test_with_limiting_with_custom_select
posts
=
Post
.
references
(
:authors
).
fin
d
(
:
all
,
:include
=>
:author
,
:select
=>
' posts.*, authors.id as "author_id"'
,
posts
=
Post
.
references
(
:authors
).
scope
d
(
:
includes
=>
:author
,
:select
=>
' posts.*, authors.id as "author_id"'
,
:limit
=>
3
,
:order
=>
'posts.id'
)
)
.
all
assert_equal
3
,
posts
.
size
assert_equal
[
0
,
1
,
1
],
posts
.
map
(
&
:author_id
).
sort
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录