Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
3e2f0800
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,发现更多精彩内容 >>
提交
3e2f0800
编写于
5月 18, 2009
作者:
J
Jeremy Kemper
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of git@github.com:rails/rails
上级
87adecfe
cef76c8a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
45 addition
and
4 deletion
+45
-4
actionpack/lib/action_view/helpers/text_helper.rb
actionpack/lib/action_view/helpers/text_helper.rb
+6
-1
actionpack/test/template/text_helper_test.rb
actionpack/test/template/text_helper_test.rb
+3
-0
activerecord/lib/active_record/associations/has_many_through_association.rb
...ctive_record/associations/has_many_through_association.rb
+7
-0
activerecord/lib/active_record/base.rb
activerecord/lib/active_record/base.rb
+1
-1
activerecord/test/cases/associations/has_many_through_associations_test.rb
.../cases/associations/has_many_through_associations_test.rb
+8
-2
activerecord/test/cases/method_scoping_test.rb
activerecord/test/cases/method_scoping_test.rb
+10
-0
activerecord/test/models/developer.rb
activerecord/test/models/developer.rb
+10
-0
未找到文件。
actionpack/lib/action_view/helpers/text_helper.rb
浏览文件 @
3e2f0800
...
...
@@ -34,12 +34,16 @@ def concat(string, unused_binding = nil)
# Truncates a given +text+ after a given <tt>:length</tt> if +text+ is longer than <tt>:length</tt>
# (defaults to 30). The last characters will be replaced with the <tt>:omission</tt> (defaults to "...").
# Pass a <tt>:separator</tt> to truncate +text+ at a natural break.
#
# ==== Examples
#
# truncate("Once upon a time in a world far far away")
# # => Once upon a time in a world f...
#
# truncate("Once upon a time in a world far far away", :separator => ' ')
# # => Once upon a time in a world...
#
# truncate("Once upon a time in a world far far away", :length => 14)
# # => Once upon a...
#
...
...
@@ -71,7 +75,8 @@ def truncate(text, *args)
if
text
l
=
options
[
:length
]
-
options
[
:omission
].
mb_chars
.
length
chars
=
text
.
mb_chars
(
chars
.
length
>
options
[
:length
]
?
chars
[
0
...
l
]
+
options
[
:omission
]
:
text
).
to_s
stop
=
options
[
:separator
]
?
(
chars
.
rindex
(
options
[
:separator
].
mb_chars
,
l
)
||
l
)
:
l
(
chars
.
length
>
options
[
:length
]
?
chars
[
0
...
stop
]
+
options
[
:omission
]
:
text
).
to_s
end
end
...
...
actionpack/test/template/text_helper_test.rb
浏览文件 @
3e2f0800
...
...
@@ -49,6 +49,9 @@ def test_truncate_with_options_hash
assert_equal
"This is a string that wil[...]"
,
truncate
(
"This is a string that will go longer then the default truncate length of 30"
,
:omission
=>
"[...]"
)
assert_equal
"Hello W..."
,
truncate
(
"Hello World!"
,
:length
=>
10
)
assert_equal
"Hello[...]"
,
truncate
(
"Hello World!"
,
:omission
=>
"[...]"
,
:length
=>
10
)
assert_equal
"Hello[...]"
,
truncate
(
"Hello Big World!"
,
:omission
=>
"[...]"
,
:length
=>
13
,
:separator
=>
' '
)
assert_equal
"Hello Big[...]"
,
truncate
(
"Hello Big World!"
,
:omission
=>
"[...]"
,
:length
=>
14
,
:separator
=>
' '
)
assert_equal
"Hello Big[...]"
,
truncate
(
"Hello Big World!"
,
:omission
=>
"[...]"
,
:length
=>
15
,
:separator
=>
' '
)
end
if
RUBY_VERSION
<
'1.9.0'
...
...
activerecord/lib/active_record/associations/has_many_through_association.rb
浏览文件 @
3e2f0800
...
...
@@ -17,6 +17,13 @@ def create(attrs = nil)
end
end
def
destroy
(
*
records
)
transaction
do
delete_records
(
flatten_deeper
(
records
))
super
end
end
# Returns the size of the collection by executing a SELECT COUNT(*) query if the collection hasn't been loaded and
# calling collection.size if it has. If it's more likely than not that the collection does have a size larger than zero,
# and you need to fetch that collection afterwards, it'll take one fewer SELECT query if you use #length.
...
...
activerecord/lib/active_record/base.rb
浏览文件 @
3e2f0800
...
...
@@ -2177,7 +2177,7 @@ def subclasses #:nodoc:
# default_scope :order => 'last_name, first_name'
# end
def
default_scope
(
options
=
{})
self
.
default_scoping
<<
{
:find
=>
options
,
:create
=>
(
options
.
is_a?
(
Hash
)
&&
options
.
has_key?
(
:conditions
)
)
?
options
[
:conditions
]
:
{}
}
self
.
default_scoping
<<
{
:find
=>
options
,
:create
=>
options
[
:conditions
].
is_a?
(
Hash
)
?
options
[
:conditions
]
:
{}
}
end
# Test whether the given method and optional key are scoped.
...
...
activerecord/test/cases/associations/has_many_through_associations_test.rb
浏览文件 @
3e2f0800
...
...
@@ -93,7 +93,7 @@ def test_delete_association
end
def
test_destroy_association
assert_difference
"Person.count"
,
-
1
do
assert_difference
[
"Person.count"
,
"Reader.count"
]
,
-
1
do
posts
(
:welcome
).
people
.
destroy
(
people
(
:michael
))
end
...
...
@@ -102,7 +102,7 @@ def test_destroy_association
end
def
test_destroy_all
assert_difference
"Person.count"
,
-
1
do
assert_difference
[
"Person.count"
,
"Reader.count"
]
,
-
1
do
posts
(
:welcome
).
people
.
destroy_all
end
...
...
@@ -110,6 +110,12 @@ def test_destroy_all
assert
posts
(
:welcome
).
people
(
true
).
empty?
end
def
test_should_raise_exception_for_destroying_mismatching_records
assert_no_difference
[
"Person.count"
,
"Reader.count"
]
do
assert_raise
(
ActiveRecord
::
AssociationTypeMismatch
)
{
posts
(
:welcome
).
people
.
destroy
(
posts
(
:thinking
))
}
end
end
def
test_replace_association
assert_queries
(
4
){
posts
(
:welcome
);
people
(
:david
);
people
(
:michael
);
posts
(
:welcome
).
people
(
true
)}
...
...
activerecord/test/cases/method_scoping_test.rb
浏览文件 @
3e2f0800
...
...
@@ -591,6 +591,16 @@ def test_default_scope
assert_equal
expected
,
received
end
def
test_default_scope_with_conditions_string
assert_equal
Developer
.
find_all_by_name
(
'David'
).
map
(
&
:id
).
sort
,
DeveloperCalledDavid
.
all
.
map
(
&
:id
).
sort
assert_equal
nil
,
DeveloperCalledDavid
.
create!
.
name
end
def
test_default_scope_with_conditions_hash
assert_equal
Developer
.
find_all_by_name
(
'Jamis'
).
map
(
&
:id
).
sort
,
DeveloperCalledJamis
.
all
.
map
(
&
:id
).
sort
assert_equal
'Jamis'
,
DeveloperCalledJamis
.
create!
.
name
end
def
test_default_scoping_with_threads
scope
=
[{
:create
=>
{},
:find
=>
{
:order
=>
'salary DESC'
}
}]
...
...
activerecord/test/models/developer.rb
浏览文件 @
3e2f0800
...
...
@@ -89,3 +89,13 @@ def self.all_ordered_by_name
end
end
end
class
DeveloperCalledDavid
<
ActiveRecord
::
Base
self
.
table_name
=
'developers'
default_scope
:conditions
=>
"name = 'David'"
end
class
DeveloperCalledJamis
<
ActiveRecord
::
Base
self
.
table_name
=
'developers'
default_scope
:conditions
=>
{
:name
=>
'Jamis'
}
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录