Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
17b1b5d7
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,发现更多精彩内容 >>
提交
17b1b5d7
编写于
1月 25, 2015
作者:
S
Sean Griffin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove all references to `where_values` in tests
上级
d6110799
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
62 addition
and
62 deletion
+62
-62
activerecord/test/cases/associations/association_scope_test.rb
...erecord/test/cases/associations/association_scope_test.rb
+3
-3
activerecord/test/cases/associations/has_many_associations_test.rb
...ord/test/cases/associations/has_many_associations_test.rb
+4
-4
activerecord/test/cases/associations/has_one_associations_test.rb
...cord/test/cases/associations/has_one_associations_test.rb
+4
-4
activerecord/test/cases/associations_test.rb
activerecord/test/cases/associations_test.rb
+1
-1
activerecord/test/cases/relation/mutation_test.rb
activerecord/test/cases/relation/mutation_test.rb
+3
-3
activerecord/test/cases/relation/where_chain_test.rb
activerecord/test/cases/relation/where_chain_test.rb
+36
-36
activerecord/test/cases/relation_test.rb
activerecord/test/cases/relation_test.rb
+4
-4
activerecord/test/cases/scoping/default_scoping_test.rb
activerecord/test/cases/scoping/default_scoping_test.rb
+5
-5
activerecord/test/cases/scoping/named_scoping_test.rb
activerecord/test/cases/scoping/named_scoping_test.rb
+1
-1
activerecord/test/cases/scoping/relation_scoping_test.rb
activerecord/test/cases/scoping/relation_scoping_test.rb
+1
-1
未找到文件。
activerecord/test/cases/associations/association_scope_test.rb
浏览文件 @
17b1b5d7
...
...
@@ -8,9 +8,9 @@ class AssociationScopeTest < ActiveRecord::TestCase
test
'does not duplicate conditions'
do
scope
=
AssociationScope
.
scope
(
Author
.
new
.
association
(
:welcome_posts
),
Author
.
connection
)
wheres
=
scope
.
where_
valu
es
.
map
(
&
:right
)
binds
=
scope
.
bind_value
s
.
map
(
&
:last
)
wheres
=
scope
.
where_values
.
map
(
&
:right
).
reject
{
|
node
|
wheres
=
scope
.
where_
clause
.
predicat
es
.
map
(
&
:right
)
binds
=
scope
.
where_clause
.
bind
s
.
map
(
&
:last
)
wheres
.
reject!
{
|
node
|
Arel
::
Nodes
::
BindParam
===
node
}
assert_equal
wheres
.
uniq
,
wheres
...
...
activerecord/test/cases/associations/has_many_associations_test.rb
浏览文件 @
17b1b5d7
...
...
@@ -316,16 +316,16 @@ def test_association_protect_foreign_key
# would be convenient), because this would cause that scope to be applied to any callbacks etc.
def
test_build_and_create_should_not_happen_within_scope
car
=
cars
(
:honda
)
scoped_count
=
car
.
foo_bulbs
.
where_
valu
es
.
count
scoped_count
=
car
.
foo_bulbs
.
where_
clause
.
predicat
es
.
count
bulb
=
car
.
foo_bulbs
.
build
assert_not_equal
scoped_count
,
bulb
.
scope_after_initialize
.
where_
valu
es
.
count
assert_not_equal
scoped_count
,
bulb
.
scope_after_initialize
.
where_
clause
.
predicat
es
.
count
bulb
=
car
.
foo_bulbs
.
create
assert_not_equal
scoped_count
,
bulb
.
scope_after_initialize
.
where_
valu
es
.
count
assert_not_equal
scoped_count
,
bulb
.
scope_after_initialize
.
where_
clause
.
predicat
es
.
count
bulb
=
car
.
foo_bulbs
.
create!
assert_not_equal
scoped_count
,
bulb
.
scope_after_initialize
.
where_
valu
es
.
count
assert_not_equal
scoped_count
,
bulb
.
scope_after_initialize
.
where_
clause
.
predicat
es
.
count
end
def
test_no_sql_should_be_fired_if_association_already_loaded
...
...
activerecord/test/cases/associations/has_one_associations_test.rb
浏览文件 @
17b1b5d7
...
...
@@ -237,16 +237,16 @@ def test_building_the_associated_object_with_an_unrelated_type
def
test_build_and_create_should_not_happen_within_scope
pirate
=
pirates
(
:blackbeard
)
scoped_count
=
pirate
.
association
(
:foo_bulb
).
scope
.
where_
valu
es
.
count
scoped_count
=
pirate
.
association
(
:foo_bulb
).
scope
.
where_
clause
.
predicat
es
.
count
bulb
=
pirate
.
build_foo_bulb
assert_not_equal
scoped_count
,
bulb
.
scope_after_initialize
.
where_
valu
es
.
count
assert_not_equal
scoped_count
,
bulb
.
scope_after_initialize
.
where_
clause
.
predicat
es
.
count
bulb
=
pirate
.
create_foo_bulb
assert_not_equal
scoped_count
,
bulb
.
scope_after_initialize
.
where_
valu
es
.
count
assert_not_equal
scoped_count
,
bulb
.
scope_after_initialize
.
where_
clause
.
predicat
es
.
count
bulb
=
pirate
.
create_foo_bulb!
assert_not_equal
scoped_count
,
bulb
.
scope_after_initialize
.
where_
valu
es
.
count
assert_not_equal
scoped_count
,
bulb
.
scope_after_initialize
.
where_
clause
.
predicat
es
.
count
end
def
test_create_association
...
...
activerecord/test/cases/associations_test.rb
浏览文件 @
17b1b5d7
...
...
@@ -238,7 +238,7 @@ def test_proxy_association_accessor
end
def
test_scoped_allows_conditions
assert
developers
(
:david
).
projects
.
merge!
(
where:
'foo'
).
where_
valu
es
.
include?
(
'foo'
)
assert
developers
(
:david
).
projects
.
merge!
(
where:
'foo'
).
where_
clause
.
predicat
es
.
include?
(
'foo'
)
end
test
"getting a scope from an association"
do
...
...
activerecord/test/cases/relation/mutation_test.rb
浏览文件 @
17b1b5d7
...
...
@@ -136,12 +136,12 @@ def relation
end
test
'test_merge!'
do
assert
relation
.
merge!
(
where
: :foo
).
equal?
(
relation
)
assert_equal
[
:foo
],
relation
.
where
_values
assert
relation
.
merge!
(
select
: :foo
).
equal?
(
relation
)
assert_equal
[
:foo
],
relation
.
select
_values
end
test
'merge with a proc'
do
assert_equal
[
:foo
],
relation
.
merge
(
->
{
where
(
:foo
)
}).
where
_values
assert_equal
[
:foo
],
relation
.
merge
(
->
{
select
(
:foo
)
}).
select
_values
end
test
'none!'
do
...
...
activerecord/test/cases/relation/where_chain_test.rb
浏览文件 @
17b1b5d7
...
...
@@ -14,10 +14,10 @@ def setup
def
test_not_eq
relation
=
Post
.
where
.
not
(
title:
'hello'
)
assert_equal
1
,
relation
.
where_
valu
es
.
length
assert_equal
1
,
relation
.
where_
clause
.
predicat
es
.
length
value
=
relation
.
where_
valu
es
.
first
bind
=
relation
.
bind_value
s
.
first
value
=
relation
.
where_
clause
.
predicat
es
.
first
bind
=
relation
.
where_clause
.
bind
s
.
first
assert_bound_ast
value
,
Post
.
arel_table
[
@name
],
Arel
::
Nodes
::
NotEqual
assert_equal
'hello'
,
bind
.
last
...
...
@@ -26,7 +26,7 @@ def test_not_eq
def
test_not_null
expected
=
Post
.
arel_table
[
@name
].
not_eq
(
nil
)
relation
=
Post
.
where
.
not
(
title:
nil
)
assert_equal
([
expected
],
relation
.
where_
valu
es
)
assert_equal
([
expected
],
relation
.
where_
clause
.
predicat
es
)
end
def
test_not_with_nil
...
...
@@ -38,25 +38,25 @@ def test_not_with_nil
def
test_not_in
expected
=
Post
.
arel_table
[
@name
].
not_in
(
%w[hello goodbye]
)
relation
=
Post
.
where
.
not
(
title:
%w[hello goodbye]
)
assert_equal
([
expected
],
relation
.
where_
valu
es
)
assert_equal
([
expected
],
relation
.
where_
clause
.
predicat
es
)
end
def
test_association_not_eq
expected
=
Comment
.
arel_table
[
@name
].
not_eq
(
Arel
::
Nodes
::
BindParam
.
new
)
relation
=
Post
.
joins
(
:comments
).
where
.
not
(
comments:
{
title:
'hello'
})
assert_equal
(
expected
.
to_sql
,
relation
.
where_
valu
es
.
first
.
to_sql
)
assert_equal
(
expected
.
to_sql
,
relation
.
where_
clause
.
predicat
es
.
first
.
to_sql
)
end
def
test_not_eq_with_preceding_where
relation
=
Post
.
where
(
title:
'hello'
).
where
.
not
(
title:
'world'
)
value
=
relation
.
where_
valu
es
.
first
bind
=
relation
.
bind_value
s
.
first
value
=
relation
.
where_
clause
.
predicat
es
.
first
bind
=
relation
.
where_clause
.
bind
s
.
first
assert_bound_ast
value
,
Post
.
arel_table
[
@name
],
Arel
::
Nodes
::
Equality
assert_equal
'hello'
,
bind
.
last
value
=
relation
.
where_
valu
es
.
last
bind
=
relation
.
bind_value
s
.
last
value
=
relation
.
where_
clause
.
predicat
es
.
last
bind
=
relation
.
where_clause
.
bind
s
.
last
assert_bound_ast
value
,
Post
.
arel_table
[
@name
],
Arel
::
Nodes
::
NotEqual
assert_equal
'world'
,
bind
.
last
end
...
...
@@ -64,13 +64,13 @@ def test_not_eq_with_preceding_where
def
test_not_eq_with_succeeding_where
relation
=
Post
.
where
.
not
(
title:
'hello'
).
where
(
title:
'world'
)
value
=
relation
.
where_
valu
es
.
first
bind
=
relation
.
bind_value
s
.
first
value
=
relation
.
where_
clause
.
predicat
es
.
first
bind
=
relation
.
where_clause
.
bind
s
.
first
assert_bound_ast
value
,
Post
.
arel_table
[
@name
],
Arel
::
Nodes
::
NotEqual
assert_equal
'hello'
,
bind
.
last
value
=
relation
.
where_
valu
es
.
last
bind
=
relation
.
bind_value
s
.
last
value
=
relation
.
where_
clause
.
predicat
es
.
last
bind
=
relation
.
where_clause
.
bind
s
.
last
assert_bound_ast
value
,
Post
.
arel_table
[
@name
],
Arel
::
Nodes
::
Equality
assert_equal
'world'
,
bind
.
last
end
...
...
@@ -78,23 +78,23 @@ def test_not_eq_with_succeeding_where
def
test_not_eq_with_string_parameter
expected
=
Arel
::
Nodes
::
Not
.
new
(
"title = 'hello'"
)
relation
=
Post
.
where
.
not
(
"title = 'hello'"
)
assert_equal
([
expected
],
relation
.
where_
valu
es
)
assert_equal
([
expected
],
relation
.
where_
clause
.
predicat
es
)
end
def
test_not_eq_with_array_parameter
expected
=
Arel
::
Nodes
::
Not
.
new
(
"title = 'hello'"
)
relation
=
Post
.
where
.
not
([
'title = ?'
,
'hello'
])
assert_equal
([
expected
],
relation
.
where_
valu
es
)
assert_equal
([
expected
],
relation
.
where_
clause
.
predicat
es
)
end
def
test_chaining_multiple
relation
=
Post
.
where
.
not
(
author_id:
[
1
,
2
]).
where
.
not
(
title:
'ruby on rails'
)
expected
=
Post
.
arel_table
[
'author_id'
].
not_in
([
1
,
2
])
assert_equal
(
expected
,
relation
.
where_
valu
es
[
0
])
assert_equal
(
expected
,
relation
.
where_
clause
.
predicat
es
[
0
])
value
=
relation
.
where_
valu
es
[
1
]
bind
=
relation
.
bind_value
s
.
first
value
=
relation
.
where_
clause
.
predicat
es
[
1
]
bind
=
relation
.
where_clause
.
bind
s
.
first
assert_bound_ast
value
,
Post
.
arel_table
[
@name
],
Arel
::
Nodes
::
NotEqual
assert_equal
'ruby on rails'
,
bind
.
last
...
...
@@ -103,9 +103,9 @@ def test_chaining_multiple
def
test_rewhere_with_one_condition
relation
=
Post
.
where
(
title:
'hello'
).
where
(
title:
'world'
).
rewhere
(
title:
'alone'
)
assert_equal
1
,
relation
.
where_
valu
es
.
size
value
=
relation
.
where_
valu
es
.
first
bind
=
relation
.
bind_value
s
.
first
assert_equal
1
,
relation
.
where_
clause
.
predicat
es
.
size
value
=
relation
.
where_
clause
.
predicat
es
.
first
bind
=
relation
.
where_clause
.
bind
s
.
first
assert_bound_ast
value
,
Post
.
arel_table
[
@name
],
Arel
::
Nodes
::
Equality
assert_equal
'alone'
,
bind
.
last
end
...
...
@@ -113,15 +113,15 @@ def test_rewhere_with_one_condition
def
test_rewhere_with_multiple_overwriting_conditions
relation
=
Post
.
where
(
title:
'hello'
).
where
(
body:
'world'
).
rewhere
(
title:
'alone'
,
body:
'again'
)
assert_equal
2
,
relation
.
where_
valu
es
.
size
assert_equal
2
,
relation
.
where_
clause
.
predicat
es
.
size
value
=
relation
.
where_
valu
es
.
first
bind
=
relation
.
bind_value
s
.
first
value
=
relation
.
where_
clause
.
predicat
es
.
first
bind
=
relation
.
where_clause
.
bind
s
.
first
assert_bound_ast
value
,
Post
.
arel_table
[
'title'
],
Arel
::
Nodes
::
Equality
assert_equal
'alone'
,
bind
.
last
value
=
relation
.
where_
valu
es
[
1
]
bind
=
relation
.
bind_value
s
[
1
]
value
=
relation
.
where_
clause
.
predicat
es
[
1
]
bind
=
relation
.
where_clause
.
bind
s
[
1
]
assert_bound_ast
value
,
Post
.
arel_table
[
'body'
],
Arel
::
Nodes
::
Equality
assert_equal
'again'
,
bind
.
last
end
...
...
@@ -135,16 +135,16 @@ def assert_bound_ast value, table, type
def
test_rewhere_with_one_overwriting_condition_and_one_unrelated
relation
=
Post
.
where
(
title:
'hello'
).
where
(
body:
'world'
).
rewhere
(
title:
'alone'
)
assert_equal
2
,
relation
.
where_
valu
es
.
size
assert_equal
2
,
relation
.
where_
clause
.
predicat
es
.
size
value
=
relation
.
where_
valu
es
.
first
bind
=
relation
.
bind_value
s
.
first
value
=
relation
.
where_
clause
.
predicat
es
.
first
bind
=
relation
.
where_clause
.
bind
s
.
first
assert_bound_ast
value
,
Post
.
arel_table
[
'body'
],
Arel
::
Nodes
::
Equality
assert_equal
'world'
,
bind
.
last
value
=
relation
.
where_
valu
es
.
second
bind
=
relation
.
bind_value
s
.
second
value
=
relation
.
where_
clause
.
predicat
es
.
second
bind
=
relation
.
where_clause
.
bind
s
.
second
assert_bound_ast
value
,
Post
.
arel_table
[
'title'
],
Arel
::
Nodes
::
Equality
assert_equal
'alone'
,
bind
.
last
...
...
@@ -153,28 +153,28 @@ def test_rewhere_with_one_overwriting_condition_and_one_unrelated
def
test_rewhere_with_range
relation
=
Post
.
where
(
comments_count:
1
..
3
).
rewhere
(
comments_count:
3
..
5
)
assert_equal
1
,
relation
.
where_
valu
es
.
size
assert_equal
1
,
relation
.
where_
clause
.
predicat
es
.
size
assert_equal
Post
.
where
(
comments_count:
3
..
5
),
relation
end
def
test_rewhere_with_infinite_upper_bound_range
relation
=
Post
.
where
(
comments_count:
1
..
Float
::
INFINITY
).
rewhere
(
comments_count:
3
..
5
)
assert_equal
1
,
relation
.
where_
valu
es
.
size
assert_equal
1
,
relation
.
where_
clause
.
predicat
es
.
size
assert_equal
Post
.
where
(
comments_count:
3
..
5
),
relation
end
def
test_rewhere_with_infinite_lower_bound_range
relation
=
Post
.
where
(
comments_count:
-
Float
::
INFINITY
..
1
).
rewhere
(
comments_count:
3
..
5
)
assert_equal
1
,
relation
.
where_
valu
es
.
size
assert_equal
1
,
relation
.
where_
clause
.
predicat
es
.
size
assert_equal
Post
.
where
(
comments_count:
3
..
5
),
relation
end
def
test_rewhere_with_infinite_range
relation
=
Post
.
where
(
comments_count:
-
Float
::
INFINITY
..
Float
::
INFINITY
).
rewhere
(
comments_count:
3
..
5
)
assert_equal
1
,
relation
.
where_
valu
es
.
size
assert_equal
1
,
relation
.
where_
clause
.
predicat
es
.
size
assert_equal
Post
.
where
(
comments_count:
3
..
5
),
relation
end
end
...
...
activerecord/test/cases/relation_test.rb
浏览文件 @
17b1b5d7
...
...
@@ -156,12 +156,12 @@ def test_references_values_dont_duplicate
relation
=
Relation
.
new
(
FakeKlass
,
:b
,
nil
)
relation
=
relation
.
merge
where: :lol
,
readonly:
true
assert_equal
[
:lol
],
relation
.
where_
valu
es
assert_equal
[
:lol
],
relation
.
where_
clause
.
predicat
es
assert_equal
true
,
relation
.
readonly_value
end
test
'merging an empty hash into a relation'
do
assert_equal
[],
Relation
.
new
(
FakeKlass
,
:b
,
nil
).
merge
({}).
where_values
assert_equal
Relation
::
WhereClause
.
empty
,
Relation
.
new
(
FakeKlass
,
:b
,
nil
).
merge
({}).
where_clause
end
test
'merging a hash with unknown keys raises'
do
...
...
@@ -173,7 +173,7 @@ def test_references_values_dont_duplicate
values
=
relation
.
values
values
[
:where
]
=
nil
assert_not_nil
relation
.
where_
values
assert_not_nil
relation
.
where_
clause
end
test
'relations can be created with a values hash'
do
...
...
@@ -191,7 +191,7 @@ def self.sanitize_sql(args)
relation
=
Relation
.
new
(
klass
,
:b
,
nil
)
relation
.
merge!
(
where:
[
'foo = ?'
,
'bar'
])
assert_equal
[
'foo = bar'
],
relation
.
where_
valu
es
assert_equal
[
'foo = bar'
],
relation
.
where_
clause
.
predicat
es
end
def
test_merging_readonly_false
...
...
activerecord/test/cases/scoping/default_scoping_test.rb
浏览文件 @
17b1b5d7
...
...
@@ -284,8 +284,8 @@ def test_unscope_errors_with_non_symbol_or_hash_arguments
def
test_unscope_merging
merged
=
Developer
.
where
(
name:
"Jamis"
).
merge
(
Developer
.
unscope
(
:where
))
assert
merged
.
where_
values
.
empty?
assert
!
merged
.
where
(
name:
"Jon"
).
where_
values
.
empty?
assert
merged
.
where_
clause
.
empty?
assert
!
merged
.
where
(
name:
"Jon"
).
where_
clause
.
empty?
end
def
test_order_in_default_scope_should_not_prevail
...
...
@@ -426,19 +426,19 @@ def test_default_scope_is_threadsafe
test
"additional conditions are ANDed with the default scope"
do
scope
=
DeveloperCalledJamis
.
where
(
name:
"David"
)
assert_equal
2
,
scope
.
where_
valu
es
.
length
assert_equal
2
,
scope
.
where_
clause
.
predicat
es
.
length
assert_equal
[],
scope
.
to_a
end
test
"additional conditions in a scope are ANDed with the default scope"
do
scope
=
DeveloperCalledJamis
.
david
assert_equal
2
,
scope
.
where_
valu
es
.
length
assert_equal
2
,
scope
.
where_
clause
.
predicat
es
.
length
assert_equal
[],
scope
.
to_a
end
test
"a scope can remove the condition from the default scope"
do
scope
=
DeveloperCalledJamis
.
david2
assert_equal
1
,
scope
.
where_
valu
es
.
length
assert_equal
1
,
scope
.
where_
clause
.
predicat
es
.
length
assert_equal
Developer
.
where
(
name:
"David"
).
map
(
&
:id
),
scope
.
map
(
&
:id
)
end
end
activerecord/test/cases/scoping/named_scoping_test.rb
浏览文件 @
17b1b5d7
...
...
@@ -380,7 +380,7 @@ def test_size_should_use_length_when_results_are_loaded
end
def
test_should_not_duplicates_where_values
where_values
=
Topic
.
where
(
"1=1"
).
scope_with_lambda
.
where_
valu
es
where_values
=
Topic
.
where
(
"1=1"
).
scope_with_lambda
.
where_
clause
.
predicat
es
assert_equal
[
"1=1"
],
where_values
end
...
...
activerecord/test/cases/scoping/relation_scoping_test.rb
浏览文件 @
17b1b5d7
...
...
@@ -184,7 +184,7 @@ def test_ensure_that_method_scoping_is_correctly_restored
rescue
end
assert
!
Developer
.
all
.
where_
valu
es
.
include?
(
"name = 'Jamis'"
)
assert
!
Developer
.
all
.
where_
clause
.
predicat
es
.
include?
(
"name = 'Jamis'"
)
end
def
test_default_scope_filters_on_joins
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录