Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
be736265
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,发现更多精彩内容 >>
提交
be736265
编写于
4月 02, 2013
作者:
Y
Yves Senn
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
replace #merge with relation API calls in calculations_test.
上级
2a27485c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
13 addition
and
17 deletion
+13
-17
activerecord/test/cases/calculations_test.rb
activerecord/test/cases/calculations_test.rb
+13
-17
未找到文件。
activerecord/test/cases/calculations_test.rb
浏览文件 @
be736265
...
...
@@ -96,25 +96,24 @@ def test_should_group_by_summed_field
end
def
test_should_order_by_grouped_field
c
=
Account
.
all
.
merge!
(
:group
=>
:firm_id
,
:order
=>
"firm_id"
).
sum
(
:credit_limit
)
c
=
Account
.
group
(
:firm_id
).
order
(
"firm_id"
).
sum
(
:credit_limit
)
assert_equal
[
1
,
2
,
6
,
9
],
c
.
keys
.
compact
end
def
test_should_order_by_calculation
c
=
Account
.
all
.
merge!
(
:group
=>
:firm_id
,
:order
=>
"sum_credit_limit desc, firm_id"
).
sum
(
:credit_limit
)
c
=
Account
.
group
(
:firm_id
).
order
(
"sum_credit_limit desc, firm_id"
).
sum
(
:credit_limit
)
assert_equal
[
105
,
60
,
53
,
50
,
50
],
c
.
keys
.
collect
{
|
k
|
c
[
k
]
}
assert_equal
[
6
,
2
,
9
,
1
],
c
.
keys
.
compact
end
def
test_should_limit_calculation
c
=
Account
.
all
.
merge!
(
:where
=>
"firm_id IS NOT NULL"
,
:group
=>
:firm_id
,
:order
=>
"firm_id"
,
:limit
=>
2
).
sum
(
:credit_limit
)
c
=
Account
.
where
(
"firm_id IS NOT NULL"
).
group
(
:firm_id
).
order
(
"firm_id"
).
limit
(
2
).
sum
(
:credit_limit
)
assert_equal
[
1
,
2
],
c
.
keys
.
compact
end
def
test_should_limit_calculation_with_offset
c
=
Account
.
all
.
merge!
(
:where
=>
"firm_id IS NOT NULL"
,
:group
=>
:firm_id
,
:order
=>
"firm_id"
,
:limit
=>
2
,
:offset
=>
1
).
sum
(
:credit_limit
)
c
=
Account
.
where
(
"firm_id IS NOT NULL"
).
group
(
:firm_id
).
order
(
"firm_id"
).
limit
(
2
).
offset
(
1
).
sum
(
:credit_limit
)
assert_equal
[
2
,
6
],
c
.
keys
.
compact
end
...
...
@@ -164,8 +163,7 @@ def test_no_limit_no_offset
end
def
test_should_group_by_summed_field_having_condition
c
=
Account
.
all
.
merge!
(
:group
=>
:firm_id
,
:having
=>
'sum(credit_limit) > 50'
).
sum
(
:credit_limit
)
c
=
Account
.
group
(
:firm_id
).
having
(
'sum(credit_limit) > 50'
).
sum
(
:credit_limit
)
assert_nil
c
[
1
]
assert_equal
105
,
c
[
6
]
assert_equal
60
,
c
[
2
]
...
...
@@ -200,17 +198,15 @@ def test_sum_should_return_valid_values_for_decimals
end
def
test_should_group_by_summed_field_with_conditions
c
=
Account
.
all
.
merge!
(
:where
=>
'firm_id > 1'
,
:group
=>
:firm_id
).
sum
(
:credit_limit
)
c
=
Account
.
where
(
'firm_id > 1'
).
group
(
:firm_id
).
sum
(
:credit_limit
)
assert_nil
c
[
1
]
assert_equal
105
,
c
[
6
]
assert_equal
60
,
c
[
2
]
end
def
test_should_group_by_summed_field_with_conditions_and_having
c
=
Account
.
all
.
merge!
(
:where
=>
'firm_id > 1'
,
:group
=>
:firm_id
,
:having
=>
'sum(credit_limit) > 60'
).
sum
(
:credit_limit
)
c
=
Account
.
where
(
'firm_id > 1'
).
group
(
:firm_id
).
having
(
'sum(credit_limit) > 60'
).
sum
(
:credit_limit
)
assert_nil
c
[
1
]
assert_equal
105
,
c
[
6
]
assert_nil
c
[
2
]
...
...
@@ -322,7 +318,7 @@ def test_should_perform_joined_include_when_referencing_included_tables
def
test_should_count_scoped_select
Account
.
update_all
(
"credit_limit = NULL"
)
assert_equal
0
,
Account
.
all
.
merge!
(
:select
=>
"credit_limit"
).
count
assert_equal
0
,
Account
.
select
(
"credit_limit"
).
count
end
def
test_should_count_scoped_select_with_options
...
...
@@ -330,11 +326,11 @@ def test_should_count_scoped_select_with_options
Account
.
last
.
update_columns
(
'credit_limit'
=>
49
)
Account
.
first
.
update_columns
(
'credit_limit'
=>
51
)
assert_equal
1
,
Account
.
all
.
merge!
(
:select
=>
"credit_limit"
).
where
(
'credit_limit >= 50'
).
count
assert_equal
1
,
Account
.
select
(
"credit_limit"
).
where
(
'credit_limit >= 50'
).
count
end
def
test_should_count_manual_select_with_include
assert_equal
6
,
Account
.
all
.
merge!
(
:select
=>
"DISTINCT accounts.id"
,
:includes
=>
:firm
).
count
assert_equal
6
,
Account
.
select
(
"DISTINCT accounts.id"
).
includes
(
:firm
).
count
end
def
test_count_with_column_parameter
...
...
@@ -366,7 +362,7 @@ def test_should_count_field_in_joined_table
end
def
test_should_count_field_in_joined_table_with_group_by
c
=
Account
.
all
.
merge!
(
:group
=>
'accounts.firm_id'
,
:joins
=>
:firm
).
count
(
'companies.id'
)
c
=
Account
.
group
(
'accounts.firm_id'
).
joins
(
:firm
).
count
(
'companies.id'
)
[
1
,
6
,
2
,
9
].
each
{
|
firm_id
|
assert
c
.
keys
.
include?
(
firm_id
)
}
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录