Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
949c8c0d
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 搜索 >>
提交
949c8c0d
编写于
12月 28, 2009
作者:
J
Jeremy Kemper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't publicize with_scope for tests since it may shadow public misuse
上级
1b91f534
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
112 addition
and
117 deletion
+112
-117
activerecord/test/cases/associations/eager_test.rb
activerecord/test/cases/associations/eager_test.rb
+4
-4
activerecord/test/cases/base_test.rb
activerecord/test/cases/base_test.rb
+9
-9
activerecord/test/cases/calculations_test.rb
activerecord/test/cases/calculations_test.rb
+1
-1
activerecord/test/cases/finder_test.rb
activerecord/test/cases/finder_test.rb
+2
-2
activerecord/test/cases/helper.rb
activerecord/test/cases/helper.rb
+0
-5
activerecord/test/cases/locking_test.rb
activerecord/test/cases/locking_test.rb
+1
-1
activerecord/test/cases/method_scoping_test.rb
activerecord/test/cases/method_scoping_test.rb
+87
-87
activerecord/test/cases/readonly_test.rb
activerecord/test/cases/readonly_test.rb
+4
-4
activerecord/test/cases/validations/uniqueness_validation_test.rb
...cord/test/cases/validations/uniqueness_validation_test.rb
+1
-1
activerecord/test/cases/validations_test.rb
activerecord/test/cases/validations_test.rb
+3
-3
未找到文件。
activerecord/test/cases/associations/eager_test.rb
浏览文件 @
949c8c0d
...
...
@@ -462,7 +462,7 @@ def test_eager_with_has_many_and_limit_and_conditions_on_the_eagers
def
test_eager_with_has_many_and_limit_and_scoped_conditions_on_the_eagers
posts
=
nil
Post
.
with_scope
(
:find
=>
{
Post
.
send
(
:with_scope
,
:find
=>
{
:include
=>
:comments
,
:conditions
=>
"comments.body like 'Normal%' OR comments.
#{
QUOTED_TYPE
}
= 'SpecialComment'"
})
do
...
...
@@ -470,7 +470,7 @@ def test_eager_with_has_many_and_limit_and_scoped_conditions_on_the_eagers
assert_equal
2
,
posts
.
size
end
Post
.
with_scope
(
:find
=>
{
Post
.
send
(
:with_scope
,
:find
=>
{
:include
=>
[
:comments
,
:author
],
:conditions
=>
"authors.name = 'David' AND (comments.body like 'Normal%' OR comments.
#{
QUOTED_TYPE
}
= 'SpecialComment')"
})
do
...
...
@@ -480,7 +480,7 @@ def test_eager_with_has_many_and_limit_and_scoped_conditions_on_the_eagers
end
def
test_eager_with_has_many_and_limit_and_scoped_and_explicit_conditions_on_the_eagers
Post
.
with_scope
(
:find
=>
{
:conditions
=>
"1=1"
})
do
Post
.
send
(
:with_scope
,
:find
=>
{
:conditions
=>
"1=1"
})
do
posts
=
authors
(
:david
).
posts
.
find
(
:all
,
:include
=>
:comments
,
:conditions
=>
"comments.body like 'Normal%' OR comments.
#{
QUOTED_TYPE
}
= 'SpecialComment'"
,
...
...
@@ -499,7 +499,7 @@ def test_eager_with_has_many_and_limit_and_scoped_and_explicit_conditions_on_the
def
test_eager_with_scoped_order_using_association_limiting_without_explicit_scope
posts_with_explicit_order
=
Post
.
find
(
:all
,
:conditions
=>
'comments.id is not null'
,
:include
=>
:comments
,
:order
=>
'posts.id DESC'
,
:limit
=>
2
)
posts_with_scoped_order
=
Post
.
with_scope
(
:find
=>
{
:order
=>
'posts.id DESC'
})
do
posts_with_scoped_order
=
Post
.
send
(
:with_scope
,
:find
=>
{
:order
=>
'posts.id DESC'
})
do
Post
.
find
(
:all
,
:conditions
=>
'comments.id is not null'
,
:include
=>
:comments
,
:limit
=>
2
)
end
assert_equal
posts_with_explicit_order
,
posts_with_scoped_order
...
...
activerecord/test/cases/base_test.rb
浏览文件 @
949c8c0d
...
...
@@ -1825,7 +1825,7 @@ def test_interpolate_sql
end
def
test_scoped_find_conditions
scoped_developers
=
Developer
.
with_scope
(
:find
=>
{
:conditions
=>
'salary > 90000'
})
do
scoped_developers
=
Developer
.
send
(
:with_scope
,
:find
=>
{
:conditions
=>
'salary > 90000'
})
do
Developer
.
find
(
:all
,
:conditions
=>
'id < 5'
)
end
assert
!
scoped_developers
.
include?
(
developers
(
:david
))
# David's salary is less than 90,000
...
...
@@ -1833,7 +1833,7 @@ def test_scoped_find_conditions
end
def
test_scoped_find_limit_offset
scoped_developers
=
Developer
.
with_scope
(
:find
=>
{
:limit
=>
3
,
:offset
=>
2
})
do
scoped_developers
=
Developer
.
send
(
:with_scope
,
:find
=>
{
:limit
=>
3
,
:offset
=>
2
})
do
Developer
.
find
(
:all
,
:order
=>
'id'
)
end
assert
!
scoped_developers
.
include?
(
developers
(
:david
))
...
...
@@ -1847,17 +1847,17 @@ def test_scoped_find_limit_offset
def
test_scoped_find_order
# Test order in scope
scoped_developers
=
Developer
.
with_scope
(
:find
=>
{
:limit
=>
1
,
:order
=>
'salary DESC'
})
do
scoped_developers
=
Developer
.
send
(
:with_scope
,
:find
=>
{
:limit
=>
1
,
:order
=>
'salary DESC'
})
do
Developer
.
find
(
:all
)
end
assert_equal
'Jamis'
,
scoped_developers
.
first
.
name
assert
scoped_developers
.
include?
(
developers
(
:jamis
))
# Test scope without order and order in find
scoped_developers
=
Developer
.
with_scope
(
:find
=>
{
:limit
=>
1
})
do
scoped_developers
=
Developer
.
send
(
:with_scope
,
:find
=>
{
:limit
=>
1
})
do
Developer
.
find
(
:all
,
:order
=>
'salary DESC'
)
end
# Test scope order + find order, find has priority
scoped_developers
=
Developer
.
with_scope
(
:find
=>
{
:limit
=>
3
,
:order
=>
'id DESC'
})
do
scoped_developers
=
Developer
.
send
(
:with_scope
,
:find
=>
{
:limit
=>
3
,
:order
=>
'id DESC'
})
do
Developer
.
find
(
:all
,
:order
=>
'salary ASC'
)
end
assert
scoped_developers
.
include?
(
developers
(
:poor_jamis
))
...
...
@@ -1869,7 +1869,7 @@ def test_scoped_find_order
end
def
test_scoped_find_limit_offset_including_has_many_association
topics
=
Topic
.
with_scope
(
:find
=>
{
:limit
=>
1
,
:offset
=>
1
,
:include
=>
:replies
})
do
topics
=
Topic
.
send
(
:with_scope
,
:find
=>
{
:limit
=>
1
,
:offset
=>
1
,
:include
=>
:replies
})
do
Topic
.
find
(
:all
,
:order
=>
"topics.id"
)
end
assert_equal
1
,
topics
.
size
...
...
@@ -1877,7 +1877,7 @@ def test_scoped_find_limit_offset_including_has_many_association
end
def
test_scoped_find_order_including_has_many_association
developers
=
Developer
.
with_scope
(
:find
=>
{
:order
=>
'developers.salary DESC'
,
:include
=>
:projects
})
do
developers
=
Developer
.
send
(
:with_scope
,
:find
=>
{
:order
=>
'developers.salary DESC'
,
:include
=>
:projects
})
do
Developer
.
find
(
:all
)
end
assert
developers
.
size
>=
2
...
...
@@ -1887,7 +1887,7 @@ def test_scoped_find_order_including_has_many_association
end
def
test_scoped_find_with_group_and_having
developers
=
Developer
.
with_scope
(
:find
=>
{
:group
=>
'developers.salary'
,
:having
=>
"SUM(salary) > 10000"
,
:select
=>
"SUM(salary) as salary"
})
do
developers
=
Developer
.
send
(
:with_scope
,
:find
=>
{
:group
=>
'developers.salary'
,
:having
=>
"SUM(salary) > 10000"
,
:select
=>
"SUM(salary) as salary"
})
do
Developer
.
find
(
:all
)
end
assert_equal
3
,
developers
.
size
...
...
@@ -1933,7 +1933,7 @@ def test_find_symbol_ordered_last
end
def
test_find_scoped_ordered_last
last_developer
=
Developer
.
with_scope
(
:find
=>
{
:order
=>
'developers.salary ASC'
})
do
last_developer
=
Developer
.
send
(
:with_scope
,
:find
=>
{
:order
=>
'developers.salary ASC'
})
do
Developer
.
find
(
:last
)
end
assert_equal
last_developer
,
Developer
.
find
(
:all
,
:order
=>
'developers.salary ASC'
).
last
...
...
activerecord/test/cases/calculations_test.rb
浏览文件 @
949c8c0d
...
...
@@ -42,7 +42,7 @@ def test_should_get_maximum_of_field_with_include
end
def
test_should_get_maximum_of_field_with_scoped_include
Account
.
with_scope
:find
=>
{
:include
=>
:firm
,
:conditions
=>
"companies.name != 'Summit'"
}
do
Account
.
send
:with_scope
,
:find
=>
{
:include
=>
:firm
,
:conditions
=>
"companies.name != 'Summit'"
}
do
assert_equal
50
,
Account
.
maximum
(
:credit_limit
)
end
end
...
...
activerecord/test/cases/finder_test.rb
浏览文件 @
949c8c0d
...
...
@@ -120,7 +120,7 @@ def test_exists_with_aggregate_having_three_mappings_with_one_difference
end
def
test_exists_with_scoped_include
Developer
.
with_scope
(
:find
=>
{
:include
=>
:projects
,
:order
=>
"projects.name"
})
do
Developer
.
send
(
:with_scope
,
:find
=>
{
:include
=>
:projects
,
:order
=>
"projects.name"
})
do
assert
Developer
.
exists?
end
end
...
...
@@ -1022,7 +1022,7 @@ def test_with_limiting_with_custom_select
def
test_finder_with_scoped_from
all_topics
=
Topic
.
find
(
:all
)
Topic
.
with_scope
(
:find
=>
{
:from
=>
'fake_topics'
})
do
Topic
.
send
(
:with_scope
,
:find
=>
{
:from
=>
'fake_topics'
})
do
assert_equal
all_topics
,
Topic
.
from
(
'topics'
).
to_a
end
end
...
...
activerecord/test/cases/helper.rb
浏览文件 @
949c8c0d
...
...
@@ -47,11 +47,6 @@ def execute_with_query_record(sql, name = nil, &block)
alias_method_chain
:execute
,
:query_record
end
# Make with_scope public for tests
class
<<
ActiveRecord
::
Base
public
:with_scope
,
:with_exclusive_scope
end
unless
ENV
[
'FIXTURE_DEBUG'
]
module
ActiveRecord::TestFixtures::ClassMethods
def
try_to_load_dependency_with_silence
(
*
args
)
...
...
activerecord/test/cases/locking_test.rb
浏览文件 @
949c8c0d
...
...
@@ -225,7 +225,7 @@ def test_sane_find_with_lock
def
test_sane_find_with_scoped_lock
assert_nothing_raised
do
Person
.
transaction
do
Person
.
with_scope
(
:find
=>
{
:lock
=>
true
})
do
Person
.
send
(
:with_scope
,
:find
=>
{
:lock
=>
true
})
do
Person
.
find
1
end
end
...
...
activerecord/test/cases/method_scoping_test.rb
浏览文件 @
949c8c0d
此差异已折叠。
点击以展开。
activerecord/test/cases/readonly_test.rb
浏览文件 @
949c8c0d
...
...
@@ -72,13 +72,13 @@ def test_has_many_with_through_is_not_implicitly_marked_readonly
end
def
test_readonly_scoping
Post
.
with_scope
(
:find
=>
{
:conditions
=>
'1=1'
})
do
Post
.
send
(
:with_scope
,
:find
=>
{
:conditions
=>
'1=1'
})
do
assert
!
Post
.
find
(
1
).
readonly?
assert
Post
.
readonly
(
true
).
find
(
1
).
readonly?
assert
!
Post
.
readonly
(
false
).
find
(
1
).
readonly?
end
Post
.
with_scope
(
:find
=>
{
:joins
=>
' '
})
do
Post
.
send
(
:with_scope
,
:find
=>
{
:joins
=>
' '
})
do
assert
!
Post
.
find
(
1
).
readonly?
assert
Post
.
readonly
.
find
(
1
).
readonly?
assert
!
Post
.
readonly
(
false
).
find
(
1
).
readonly?
...
...
@@ -87,14 +87,14 @@ def test_readonly_scoping
# Oracle barfs on this because the join includes unqualified and
# conflicting column names
unless
current_adapter?
(
:OracleAdapter
)
Post
.
with_scope
(
:find
=>
{
:joins
=>
', developers'
})
do
Post
.
send
(
:with_scope
,
:find
=>
{
:joins
=>
', developers'
})
do
assert
Post
.
find
(
1
).
readonly?
assert
Post
.
readonly
.
find
(
1
).
readonly?
assert
!
Post
.
readonly
(
false
).
find
(
1
).
readonly?
end
end
Post
.
with_scope
(
:find
=>
{
:readonly
=>
true
})
do
Post
.
send
(
:with_scope
,
:find
=>
{
:readonly
=>
true
})
do
assert
Post
.
find
(
1
).
readonly?
assert
Post
.
readonly
.
find
(
1
).
readonly?
assert
!
Post
.
readonly
(
false
).
find
(
1
).
readonly?
...
...
activerecord/test/cases/validations/uniqueness_validation_test.rb
浏览文件 @
949c8c0d
...
...
@@ -213,7 +213,7 @@ def test_validate_uniqueness_with_non_standard_table_names
def
test_validates_uniqueness_inside_with_scope
Topic
.
validates_uniqueness_of
(
:title
)
Topic
.
with_scope
(
:find
=>
{
:conditions
=>
{
:author_name
=>
"David"
}
})
do
Topic
.
send
(
:with_scope
,
:find
=>
{
:conditions
=>
{
:author_name
=>
"David"
}
})
do
t1
=
Topic
.
new
(
"title"
=>
"I'm unique!"
,
"author_name"
=>
"Mary"
)
assert
t1
.
save
t2
=
Topic
.
new
(
"title"
=>
"I'm unique!"
,
"author_name"
=>
"David"
)
...
...
activerecord/test/cases/validations_test.rb
浏览文件 @
949c8c0d
...
...
@@ -98,14 +98,14 @@ def test_exception_on_create_bang_many_with_block
end
def
test_scoped_create_without_attributes
Reply
.
with_scope
(
:create
=>
{})
do
Reply
.
send
(
:with_scope
,
:create
=>
{})
do
assert_raise
(
ActiveRecord
::
RecordInvalid
)
{
Reply
.
create!
}
end
end
def
test_create_with_exceptions_using_scope_for_protected_attributes
assert_nothing_raised
do
ProtectedPerson
.
with_scope
(
:create
=>
{
:first_name
=>
"Mary"
}
)
do
ProtectedPerson
.
send
(
:with_scope
,
:create
=>
{
:first_name
=>
"Mary"
}
)
do
person
=
ProtectedPerson
.
create!
:addon
=>
"Addon"
assert_equal
person
.
first_name
,
"Mary"
,
"scope should ignore attr_protected"
end
...
...
@@ -114,7 +114,7 @@ def test_create_with_exceptions_using_scope_for_protected_attributes
def
test_create_with_exceptions_using_scope_and_empty_attributes
assert_nothing_raised
do
ProtectedPerson
.
with_scope
(
:create
=>
{
:first_name
=>
"Mary"
}
)
do
ProtectedPerson
.
send
(
:with_scope
,
:create
=>
{
:first_name
=>
"Mary"
}
)
do
person
=
ProtectedPerson
.
create!
assert_equal
person
.
first_name
,
"Mary"
,
"should be ok when no attributes are passed to create!"
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录