Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
915f108d
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,发现更多精彩内容 >>
提交
915f108d
编写于
6月 26, 2009
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
git://github.com/rails/rails
上级
aee63a12
b5dfdc71
变更
24
隐藏空白更改
内联
并排
Showing
24 changed file
with
218 addition
and
82 deletion
+218
-82
actionpack/lib/action_controller/base/streaming.rb
actionpack/lib/action_controller/base/streaming.rb
+1
-1
actionpack/lib/action_controller/testing/performance_test.rb
actionpack/lib/action_controller/testing/performance_test.rb
+0
-0
actionpack/lib/action_view/helpers/asset_tag_helper.rb
actionpack/lib/action_view/helpers/asset_tag_helper.rb
+28
-4
actionpack/lib/action_view/render/partials.rb
actionpack/lib/action_view/render/partials.rb
+0
-26
actionpack/lib/action_view/template/handlers/builder.rb
actionpack/lib/action_view/template/handlers/builder.rb
+1
-2
actionpack/lib/action_view/template/handlers/erb.rb
actionpack/lib/action_view/template/handlers/erb.rb
+2
-1
actionpack/test/controller/render_test.rb
actionpack/test/controller/render_test.rb
+0
-7
actionpack/test/controller/send_file_test.rb
actionpack/test/controller/send_file_test.rb
+1
-1
actionpack/test/fixtures/public/.gitignore
actionpack/test/fixtures/public/.gitignore
+1
-0
actionpack/test/fixtures/public/elsewhere/cools.js
actionpack/test/fixtures/public/elsewhere/cools.js
+1
-0
actionpack/test/fixtures/public/elsewhere/file.css
actionpack/test/fixtures/public/elsewhere/file.css
+1
-0
actionpack/test/fixtures/public/javascripts/common.javascript
...onpack/test/fixtures/public/javascripts/common.javascript
+1
-0
actionpack/test/fixtures/public/stylesheets/random.styles
actionpack/test/fixtures/public/stylesheets/random.styles
+1
-0
actionpack/test/template/asset_tag_helper_test.rb
actionpack/test/template/asset_tag_helper_test.rb
+88
-30
activerecord/lib/active_record/base.rb
activerecord/lib/active_record/base.rb
+19
-0
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
...lib/active_record/connection_adapters/abstract_adapter.rb
+6
-1
activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
...rd/lib/active_record/connection_adapters/mysql_adapter.rb
+13
-0
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+11
-0
activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
...d/lib/active_record/connection_adapters/sqlite_adapter.rb
+10
-0
activerecord/test/cases/adapter_test.rb
activerecord/test/cases/adapter_test.rb
+15
-0
activesupport/lib/active_support/cache.rb
activesupport/lib/active_support/cache.rb
+6
-1
railties/lib/initializer.rb
railties/lib/initializer.rb
+11
-6
railties/lib/performance_test_help.rb
railties/lib/performance_test_help.rb
+1
-1
railties/lib/rails/configuration.rb
railties/lib/rails/configuration.rb
+0
-1
未找到文件。
actionpack/lib/action_controller/base/streaming.rb
浏览文件 @
915f108d
...
@@ -168,7 +168,7 @@ def send_file_headers!(options)
...
@@ -168,7 +168,7 @@ def send_file_headers!(options)
end
end
headers
.
merge!
(
headers
.
merge!
(
'Content-Length'
=>
options
[
:length
],
'Content-Length'
=>
options
[
:length
]
.
to_s
,
'Content-Disposition'
=>
disposition
,
'Content-Disposition'
=>
disposition
,
'Content-Transfer-Encoding'
=>
'binary'
'Content-Transfer-Encoding'
=>
'binary'
)
)
...
...
actionpack/lib/action_controller/testing/performance.rb
→
actionpack/lib/action_controller/testing/performance
_test
.rb
浏览文件 @
915f108d
文件已移动
actionpack/lib/action_view/helpers/asset_tag_helper.rb
浏览文件 @
915f108d
require
'cgi'
require
'cgi'
require
'action_view/helpers/url_helper'
require
'action_view/helpers/url_helper'
require
'action_view/helpers/tag_helper'
require
'action_view/helpers/tag_helper'
require
'active_support/core_ext/file'
module
ActionView
module
ActionView
module
Helpers
#:nodoc:
module
Helpers
#:nodoc:
...
@@ -285,7 +286,7 @@ def javascript_include_tag(*sources)
...
@@ -285,7 +286,7 @@ def javascript_include_tag(*sources)
end
end
javascript_src_tag
(
joined_javascript_name
,
options
)
javascript_src_tag
(
joined_javascript_name
,
options
)
else
else
e
xpand_javascript_sources
(
sources
,
recursive
).
collect
{
|
source
|
javascript_src_tag
(
source
,
options
)
}.
join
(
"
\n
"
)
e
nsure_javascript_sources!
(
expand_javascript_sources
(
sources
,
recursive
)
).
collect
{
|
source
|
javascript_src_tag
(
source
,
options
)
}.
join
(
"
\n
"
)
end
end
end
end
...
@@ -434,7 +435,7 @@ def stylesheet_link_tag(*sources)
...
@@ -434,7 +435,7 @@ def stylesheet_link_tag(*sources)
end
end
stylesheet_tag
(
joined_stylesheet_name
,
options
)
stylesheet_tag
(
joined_stylesheet_name
,
options
)
else
else
e
xpand_stylesheet_sources
(
sources
,
recursive
).
collect
{
|
source
|
stylesheet_tag
(
source
,
options
)
}.
join
(
"
\n
"
)
e
nsure_stylesheet_sources!
(
expand_stylesheet_sources
(
sources
,
recursive
)
).
collect
{
|
source
|
stylesheet_tag
(
source
,
options
)
}.
join
(
"
\n
"
)
end
end
end
end
...
@@ -664,13 +665,28 @@ def determine_source(source, collection)
...
@@ -664,13 +665,28 @@ def determine_source(source, collection)
end
end
end
end
def
ensure_stylesheet_sources!
(
sources
)
sources
.
each
do
|
source
|
asset_file_path!
(
path_to_stylesheet
(
source
))
end
return
sources
end
def
ensure_javascript_sources!
(
sources
)
sources
.
each
do
|
source
|
asset_file_path!
(
path_to_javascript
(
source
))
end
return
sources
end
def
join_asset_file_contents
(
paths
)
def
join_asset_file_contents
(
paths
)
paths
.
collect
{
|
path
|
File
.
read
(
asset_file_path
(
path
))
}.
join
(
"
\n\n
"
)
paths
.
collect
{
|
path
|
File
.
read
(
asset_file_path
!
(
path
))
}.
join
(
"
\n\n
"
)
end
end
def
write_asset_file_contents
(
joined_asset_path
,
asset_paths
)
def
write_asset_file_contents
(
joined_asset_path
,
asset_paths
)
FileUtils
.
mkdir_p
(
File
.
dirname
(
joined_asset_path
))
FileUtils
.
mkdir_p
(
File
.
dirname
(
joined_asset_path
))
File
.
open
(
joined_asset_path
,
"w+"
)
{
|
cache
|
cache
.
write
(
join_asset_file_contents
(
asset_paths
))
}
File
.
atomic_write
(
joined_asset_path
)
{
|
cache
|
cache
.
write
(
join_asset_file_contents
(
asset_paths
))
}
# Set mtime to the latest of the combined files to allow for
# Set mtime to the latest of the combined files to allow for
# consistent ETag without a shared filesystem.
# consistent ETag without a shared filesystem.
...
@@ -682,6 +698,14 @@ def asset_file_path(path)
...
@@ -682,6 +698,14 @@ def asset_file_path(path)
File
.
join
(
ASSETS_DIR
,
path
.
split
(
'?'
).
first
)
File
.
join
(
ASSETS_DIR
,
path
.
split
(
'?'
).
first
)
end
end
def
asset_file_path!
(
path
)
unless
path
=~
%r{^[-a-z]+://}
absolute_path
=
asset_file_path
(
path
)
raise
(
Errno
::
ENOENT
,
"Asset file not found at '
#{
absolute_path
}
'"
)
unless
File
.
exist?
(
absolute_path
)
return
absolute_path
end
end
def
collect_asset_files
(
*
path
)
def
collect_asset_files
(
*
path
)
dir
=
path
.
first
dir
=
path
.
first
...
...
actionpack/lib/action_view/render/partials.rb
浏览文件 @
915f108d
...
@@ -232,18 +232,6 @@ def _render_partial_with_block(layout, block, options)
...
@@ -232,18 +232,6 @@ def _render_partial_with_block(layout, block, options)
ensure
ensure
@_proc_for_layout
=
nil
@_proc_for_layout
=
nil
end
end
def
_deprecated_ivar_assign
(
template
)
if
respond_to?
(
:controller
)
ivar
=
:"@
#{
template
.
variable_name
}
"
object
=
if
controller
.
instance_variable_defined?
(
ivar
)
ActiveSupport
::
Deprecation
::
DeprecatedObjectProxy
.
new
(
controller
.
instance_variable_get
(
ivar
),
"
#{
ivar
}
will no longer be implicitly assigned to
#{
template
.
variable_name
}
"
)
end
end
end
def
_render_partial_with_layout
(
layout
,
options
)
def
_render_partial_with_layout
(
layout
,
options
)
if
layout
if
layout
...
@@ -253,18 +241,6 @@ def _render_partial_with_layout(layout, options)
...
@@ -253,18 +241,6 @@ def _render_partial_with_layout(layout, options)
content
=
_render_partial
(
options
)
content
=
_render_partial
(
options
)
return
_render_content_with_layout
(
content
,
layout
,
options
[
:locals
])
return
_render_content_with_layout
(
content
,
layout
,
options
[
:locals
])
end
end
def
_deprecated_ivar_assign
(
template
)
if
respond_to?
(
:controller
)
ivar
=
:"@
#{
template
.
variable_name
}
"
object
=
if
controller
.
instance_variable_defined?
(
ivar
)
ActiveSupport
::
Deprecation
::
DeprecatedObjectProxy
.
new
(
controller
.
instance_variable_get
(
ivar
),
"
#{
ivar
}
will no longer be implicitly assigned to
#{
template
.
variable_name
}
"
)
end
end
end
def
_array_like_objects
def
_array_like_objects
array_like
=
[
Array
]
array_like
=
[
Array
]
...
@@ -290,8 +266,6 @@ def _render_partial_object(template, options, object = nil)
...
@@ -290,8 +266,6 @@ def _render_partial_object(template, options, object = nil)
end
end
def
_set_locals
(
object
,
locals
,
template
,
options
)
def
_set_locals
(
object
,
locals
,
template
,
options
)
object
||=
_deprecated_ivar_assign
(
template
)
locals
[
:object
]
=
locals
[
template
.
variable_name
]
=
object
locals
[
:object
]
=
locals
[
template
.
variable_name
]
=
object
locals
[
options
[
:as
]]
=
object
if
options
[
:as
]
locals
[
options
[
:as
]]
=
object
if
options
[
:as
]
end
end
...
...
actionpack/lib/action_view/template/handlers/builder.rb
浏览文件 @
915f108d
require
'builder'
module
ActionView
module
ActionView
module
TemplateHandlers
module
TemplateHandlers
class
Builder
<
TemplateHandler
class
Builder
<
TemplateHandler
...
@@ -8,6 +6,7 @@ class Builder < TemplateHandler
...
@@ -8,6 +6,7 @@ class Builder < TemplateHandler
self
.
default_format
=
Mime
::
XML
self
.
default_format
=
Mime
::
XML
def
compile
(
template
)
def
compile
(
template
)
require
'builder'
"xml = ::Builder::XmlMarkup.new(:indent => 2);"
+
"xml = ::Builder::XmlMarkup.new(:indent => 2);"
+
"self.output_buffer = xml.target!;"
+
"self.output_buffer = xml.target!;"
+
template
.
source
+
template
.
source
+
...
...
actionpack/lib/action_view/template/handlers/erb.rb
浏览文件 @
915f108d
require
'erb'
require
'active_support/core_ext/class/attribute_accessors'
require
'active_support/core_ext/class/attribute_accessors'
module
ActionView
module
ActionView
...
@@ -16,6 +15,8 @@ class ERB < TemplateHandler
...
@@ -16,6 +15,8 @@ class ERB < TemplateHandler
self
.
default_format
=
Mime
::
HTML
self
.
default_format
=
Mime
::
HTML
def
compile
(
template
)
def
compile
(
template
)
require
'erb'
magic
=
$1
if
template
.
source
=~
/\A(<%#.*coding:\s*(\S+)\s*-?%>)/
magic
=
$1
if
template
.
source
=~
/\A(<%#.*coding:\s*(\S+)\s*-?%>)/
erb
=
"
#{
magic
}
<% __in_erb_template=true %>
#{
template
.
source
}
"
erb
=
"
#{
magic
}
<% __in_erb_template=true %>
#{
template
.
source
}
"
::
ERB
.
new
(
erb
,
nil
,
erb_trim_mode
,
'@output_buffer'
).
src
::
ERB
.
new
(
erb
,
nil
,
erb_trim_mode
,
'@output_buffer'
).
src
...
...
actionpack/test/controller/render_test.rb
浏览文件 @
915f108d
...
@@ -1268,13 +1268,6 @@ def test_partial_hash_collection_with_locals
...
@@ -1268,13 +1268,6 @@ def test_partial_hash_collection_with_locals
assert_equal
"Hola: PratikHola: Amy"
,
@response
.
body
assert_equal
"Hola: PratikHola: Amy"
,
@response
.
body
end
end
def
test_partial_with_implicit_local_assignment
assert_deprecated
do
get
:partial_with_implicit_local_assignment
assert_equal
"Hello: Marcel"
,
@response
.
body
end
end
def
test_render_missing_partial_template
def
test_render_missing_partial_template
assert_raise
(
ActionView
::
MissingTemplate
)
do
assert_raise
(
ActionView
::
MissingTemplate
)
do
get
:missing_partial
get
:missing_partial
...
...
actionpack/test/controller/send_file_test.rb
浏览文件 @
915f108d
...
@@ -115,7 +115,7 @@ def test_send_file_headers!
...
@@ -115,7 +115,7 @@ def test_send_file_headers!
@controller
.
send
(
:send_file_headers!
,
options
)
@controller
.
send
(
:send_file_headers!
,
options
)
h
=
@controller
.
headers
h
=
@controller
.
headers
assert_equal
1
,
h
[
'Content-Length'
]
assert_equal
'1'
,
h
[
'Content-Length'
]
assert_equal
'image/png'
,
@controller
.
content_type
assert_equal
'image/png'
,
@controller
.
content_type
assert_equal
'disposition; filename="filename"'
,
h
[
'Content-Disposition'
]
assert_equal
'disposition; filename="filename"'
,
h
[
'Content-Disposition'
]
assert_equal
'binary'
,
h
[
'Content-Transfer-Encoding'
]
assert_equal
'binary'
,
h
[
'Content-Transfer-Encoding'
]
...
...
actionpack/test/fixtures/public/.gitignore
0 → 100644
浏览文件 @
915f108d
absolute
\ No newline at end of file
actionpack/test/fixtures/public/elsewhere/cools.js
0 → 100644
浏览文件 @
915f108d
// cools.js
\ No newline at end of file
actionpack/test/fixtures/public/elsewhere/file.css
0 → 100644
浏览文件 @
915f108d
/*file.css*/
\ No newline at end of file
actionpack/test/fixtures/public/javascripts/common.javascript
0 → 100644
浏览文件 @
915f108d
// common.javascript
\ No newline at end of file
actionpack/test/fixtures/public/stylesheets/random.styles
0 → 100644
浏览文件 @
915f108d
/* random.styles */
\ No newline at end of file
actionpack/test/template/asset_tag_helper_test.rb
浏览文件 @
915f108d
...
@@ -75,22 +75,22 @@ def teardown
...
@@ -75,22 +75,22 @@ def teardown
}
}
JavascriptIncludeToTag
=
{
JavascriptIncludeToTag
=
{
%(javascript_include_tag("
xmlhr"))
=>
%(<script src="/javascripts/xmlhr
.js" type="text/javascript"></script>)
,
%(javascript_include_tag("
bank"))
=>
%(<script src="/javascripts/bank
.js" type="text/javascript"></script>)
,
%(javascript_include_tag("
xmlhr.js"))
=>
%(<script src="/javascripts/xmlhr
.js" type="text/javascript"></script>)
,
%(javascript_include_tag("
bank.js"))
=>
%(<script src="/javascripts/bank
.js" type="text/javascript"></script>)
,
%(javascript_include_tag("
xmlhr", :lang => "vbscript"))
=>
%(<script lang="vbscript" src="/javascripts/xmlhr
.js" type="text/javascript"></script>)
,
%(javascript_include_tag("
bank", :lang => "vbscript"))
=>
%(<script lang="vbscript" src="/javascripts/bank
.js" type="text/javascript"></script>)
,
%(javascript_include_tag("common.javascript", "/elsewhere/cools"))
=>
%(<script src="/javascripts/common.javascript" type="text/javascript"></script>\n<script src="/elsewhere/cools.js" type="text/javascript"></script>)
,
%(javascript_include_tag("common.javascript", "/elsewhere/cools"))
=>
%(<script src="/javascripts/common.javascript" type="text/javascript"></script>\n<script src="/elsewhere/cools.js" type="text/javascript"></script>)
,
%(javascript_include_tag(:defaults))
=>
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
,
%(javascript_include_tag(:defaults))
=>
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
,
%(javascript_include_tag(:all))
=>
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>)
,
%(javascript_include_tag(:all))
=>
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>)
,
%(javascript_include_tag(:all, :recursive => true))
=>
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/subdir/subdir.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>)
,
%(javascript_include_tag(:all, :recursive => true))
=>
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/subdir/subdir.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>)
,
%(javascript_include_tag(:defaults, "
test"))
=>
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/test
.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
,
%(javascript_include_tag(:defaults, "
bank"))
=>
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/bank
.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
,
%(javascript_include_tag("
test", :defaults))
=>
%(<script src="/javascripts/test
.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
%(javascript_include_tag("
bank", :defaults))
=>
%(<script src="/javascripts/bank
.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
}
}
StylePathToTag
=
{
StylePathToTag
=
{
%(stylesheet_path("
style"))
=>
%(/stylesheets/style
.css)
,
%(stylesheet_path("
bank"))
=>
%(/stylesheets/bank
.css)
,
%(stylesheet_path("
style.css"))
=>
%(/stylesheets/style
.css)
,
%(stylesheet_path("
bank.css"))
=>
%(/stylesheets/bank
.css)
,
%(stylesheet_path('
dir/file'))
=>
%(/stylesheets/dir/file
.css)
,
%(stylesheet_path('
subdir/subdir'))
=>
%(/stylesheets/subdir/subdir
.css)
,
%(stylesheet_path('/
dir/file.rcss'))
=>
%(/dir/file.r
css)
%(stylesheet_path('/
subdir/subdir.css'))
=>
%(/subdir/subdir.
css)
}
}
PathToStyleToTag
=
{
PathToStyleToTag
=
{
...
@@ -101,15 +101,16 @@ def teardown
...
@@ -101,15 +101,16 @@ def teardown
}
}
StyleLinkToTag
=
{
StyleLinkToTag
=
{
%(stylesheet_link_tag("
style"))
=>
%(<link href="/stylesheets/style
.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag("
bank"))
=>
%(<link href="/stylesheets/bank
.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag("
style.css"))
=>
%(<link href="/stylesheets/style
.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag("
bank.css"))
=>
%(<link href="/stylesheets/bank
.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag("/
dir/file"))
=>
%(<link href="/dir
/file.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag("/
elsewhere/file"))
=>
%(<link href="/elsewhere
/file.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag("
dir/file"))
=>
%(<link href="/stylesheets/dir/file
.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag("
subdir/subdir"))
=>
%(<link href="/stylesheets/subdir/subdir
.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag("
style", :media => "all"))
=>
%(<link href="/stylesheets/style
.css" media="all" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag("
bank", :media => "all"))
=>
%(<link href="/stylesheets/bank
.css" media="all" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag(:all))
=>
%(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag(:all))
=>
%(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag(:all, :recursive => true))
=>
%(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/subdir/subdir.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag(:all, :recursive => true))
=>
%(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/subdir/subdir.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag(:all, :media => "all"))
=>
%(<link href="/stylesheets/bank.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="all" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag(:all, :media => "all"))
=>
%(<link href="/stylesheets/bank.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="all" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag("random.styles", "/css/stylish"))
=>
%(<link href="/stylesheets/random.styles" media="screen" rel="stylesheet" type="text/css" />\n<link href="/css/stylish.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag("random.styles", "/elsewhere/file"))
=>
%(<link href="/stylesheets/random.styles" media="screen" rel="stylesheet" type="text/css" />\n<link href="/elsewhere/file.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(stylesheet_link_tag("http://www.example.com/styles/style"))
=>
%(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" type="text/css" />)
%(stylesheet_link_tag("http://www.example.com/styles/style"))
=>
%(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" type="text/css" />)
}
}
...
@@ -160,6 +161,20 @@ def test_javascript_include_tag_with_blank_asset_id
...
@@ -160,6 +161,20 @@ def test_javascript_include_tag_with_blank_asset_id
JavascriptIncludeToTag
.
each
{
|
method
,
tag
|
assert_dom_equal
(
tag
,
eval
(
method
))
}
JavascriptIncludeToTag
.
each
{
|
method
,
tag
|
assert_dom_equal
(
tag
,
eval
(
method
))
}
end
end
def
test_javascript_include_tag_with_missing_source
assert_raise
(
Errno
::
ENOENT
)
{
javascript_include_tag
(
'missing_security_guard'
)
}
assert_raise
(
Errno
::
ENOENT
)
{
javascript_include_tag
(
:defaults
,
'missing_security_guard'
)
}
assert_nothing_raised
{
javascript_include_tag
(
'http://example.com/css/missing_security_guard'
)
}
end
def
test_javascript_include_tag_with_given_asset_id
def
test_javascript_include_tag_with_given_asset_id
ENV
[
"RAILS_ASSET_ID"
]
=
"1"
ENV
[
"RAILS_ASSET_ID"
]
=
"1"
assert_dom_equal
(
%(<script src="/javascripts/prototype.js?1" type="text/javascript"></script>\n<script src="/javascripts/effects.js?1" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js?1" type="text/javascript"></script>\n<script src="/javascripts/controls.js?1" type="text/javascript"></script>\n<script src="/javascripts/application.js?1" type="text/javascript"></script>)
,
javascript_include_tag
(
:defaults
))
assert_dom_equal
(
%(<script src="/javascripts/prototype.js?1" type="text/javascript"></script>\n<script src="/javascripts/effects.js?1" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js?1" type="text/javascript"></script>\n<script src="/javascripts/controls.js?1" type="text/javascript"></script>\n<script src="/javascripts/application.js?1" type="text/javascript"></script>)
,
javascript_include_tag
(
:defaults
))
...
@@ -167,26 +182,27 @@ def test_javascript_include_tag_with_given_asset_id
...
@@ -167,26 +182,27 @@ def test_javascript_include_tag_with_given_asset_id
def
test_register_javascript_include_default
def
test_register_javascript_include_default
ENV
[
"RAILS_ASSET_ID"
]
=
""
ENV
[
"RAILS_ASSET_ID"
]
=
""
ActionView
::
Helpers
::
AssetTagHelper
::
register_javascript_include_default
'
slider
'
ActionView
::
Helpers
::
AssetTagHelper
::
register_javascript_include_default
'
bank
'
assert_dom_equal
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/
slider
.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
,
javascript_include_tag
(
:defaults
)
assert_dom_equal
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/
bank
.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
,
javascript_include_tag
(
:defaults
)
end
end
def
test_register_javascript_include_default_mixed_defaults
def
test_register_javascript_include_default_mixed_defaults
ENV
[
"RAILS_ASSET_ID"
]
=
""
ENV
[
"RAILS_ASSET_ID"
]
=
""
ActionView
::
Helpers
::
AssetTagHelper
::
register_javascript_include_default
'
slider
'
ActionView
::
Helpers
::
AssetTagHelper
::
register_javascript_include_default
'
bank
'
ActionView
::
Helpers
::
AssetTagHelper
::
register_javascript_include_default
'
lib1'
,
'/elsewhere/blub/lib2
'
ActionView
::
Helpers
::
AssetTagHelper
::
register_javascript_include_default
'
robber'
,
'/elsewhere/cools.js
'
assert_dom_equal
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/
slider.js" type="text/javascript"></script>\n<script src="/javascripts/lib1.js" type="text/javascript"></script>\n<script src="/elsewhere/blub/lib2
.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
,
javascript_include_tag
(
:defaults
)
assert_dom_equal
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/
bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/elsewhere/cools
.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
,
javascript_include_tag
(
:defaults
)
end
end
def
test_custom_javascript_expansions
def
test_custom_javascript_expansions
ActionView
::
Helpers
::
AssetTagHelper
::
register_javascript_expansion
:monkey
=>
[
"head"
,
"body"
,
"tail"
]
ENV
[
"RAILS_ASSET_ID"
]
=
""
assert_dom_equal
%(<script src="/javascripts/first.js" type="text/javascript"></script>\n<script src="/javascripts/head.js" type="text/javascript"></script>\n<script src="/javascripts/body.js" type="text/javascript"></script>\n<script src="/javascripts/tail.js" type="text/javascript"></script>\n<script src="/javascripts/last.js" type="text/javascript"></script>)
,
javascript_include_tag
(
'first'
,
:monkey
,
'last'
)
ActionView
::
Helpers
::
AssetTagHelper
::
register_javascript_expansion
:robbery
=>
[
"bank"
,
"robber"
]
assert_dom_equal
%(<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>)
,
javascript_include_tag
(
'controls'
,
:robbery
,
'effects'
)
end
end
def
test_custom_javascript_expansions_and_defaults_puts_application_js_at_the_end
def
test_custom_javascript_expansions_and_defaults_puts_application_js_at_the_end
ENV
[
"RAILS_ASSET_ID"
]
=
""
ENV
[
"RAILS_ASSET_ID"
]
=
""
ActionView
::
Helpers
::
AssetTagHelper
::
register_javascript_expansion
:
monkey
=>
[
"head"
,
"body"
,
"tail
"
]
ActionView
::
Helpers
::
AssetTagHelper
::
register_javascript_expansion
:
robbery
=>
[
"bank"
,
"robber
"
]
assert_dom_equal
%(<script src="/javascripts/
first.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/head.js" type="text/javascript"></script>\n<script src="/javascripts/body.js" type="text/javascript"></script>\n<script src="/javascripts/tail.js" type="text/javascript"></script>\n<script src="/javascripts/last.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
,
javascript_include_tag
(
'first'
,
:defaults
,
:monkey
,
'last
'
)
assert_dom_equal
%(<script src="/javascripts/
controls.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
,
javascript_include_tag
(
'controls'
,
:defaults
,
:robbery
,
'effects
'
)
end
end
def
test_custom_javascript_expansions_with_undefined_symbol
def
test_custom_javascript_expansions_with_undefined_symbol
...
@@ -195,6 +211,7 @@ def test_custom_javascript_expansions_with_undefined_symbol
...
@@ -195,6 +211,7 @@ def test_custom_javascript_expansions_with_undefined_symbol
end
end
def
test_stylesheet_path
def
test_stylesheet_path
ENV
[
"RAILS_ASSET_ID"
]
=
""
StylePathToTag
.
each
{
|
method
,
tag
|
assert_dom_equal
(
tag
,
eval
(
method
))
}
StylePathToTag
.
each
{
|
method
,
tag
|
assert_dom_equal
(
tag
,
eval
(
method
))
}
end
end
...
@@ -207,9 +224,20 @@ def test_stylesheet_link_tag
...
@@ -207,9 +224,20 @@ def test_stylesheet_link_tag
StyleLinkToTag
.
each
{
|
method
,
tag
|
assert_dom_equal
(
tag
,
eval
(
method
))
}
StyleLinkToTag
.
each
{
|
method
,
tag
|
assert_dom_equal
(
tag
,
eval
(
method
))
}
end
end
def
test_stylesheet_link_tag_with_missing_source
assert_raise
(
Errno
::
ENOENT
)
{
stylesheet_link_tag
(
'missing_security_guard'
)
}
assert_nothing_raised
{
stylesheet_link_tag
(
'http://example.com/css/missing_security_guard'
)
}
end
def
test_custom_stylesheet_expansions
def
test_custom_stylesheet_expansions
ActionView
::
Helpers
::
AssetTagHelper
::
register_stylesheet_expansion
:monkey
=>
[
"head"
,
"body"
,
"tail"
]
ENV
[
"RAILS_ASSET_ID"
]
=
''
assert_dom_equal
%(<link href="/stylesheets/first.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/head.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/body.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/tail.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/last.css" media="screen" rel="stylesheet" type="text/css" />)
,
stylesheet_link_tag
(
'first'
,
:monkey
,
'last'
)
ActionView
::
Helpers
::
AssetTagHelper
::
register_stylesheet_expansion
:robbery
=>
[
"bank"
,
"robber"
]
assert_dom_equal
%(<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/subdir/subdir.css" media="screen" rel="stylesheet" type="text/css" />)
,
stylesheet_link_tag
(
'version.1.0'
,
:robbery
,
'subdir/subdir'
)
end
end
def
test_custom_stylesheet_expansions_with_undefined_symbol
def
test_custom_stylesheet_expansions_with_undefined_symbol
...
@@ -546,8 +574,14 @@ def test_caching_stylesheet_link_tag_when_caching_on
...
@@ -546,8 +574,14 @@ def test_caching_stylesheet_link_tag_when_caching_on
stylesheet_link_tag
(
:all
,
:cache
=>
true
)
stylesheet_link_tag
(
:all
,
:cache
=>
true
)
)
)
expected
=
Dir
[
"
#{
ActionView
::
Helpers
::
AssetTagHelper
::
STYLESHEETS_DIR
}
/*.css"
].
map
{
|
p
|
File
.
mtime
(
p
)
}.
max
files_to_be_joined
=
Dir
[
"
#{
ActionView
::
Helpers
::
AssetTagHelper
::
STYLESHEETS_DIR
}
/[^all]*.css"
]
assert_equal
expected
,
File
.
mtime
(
File
.
join
(
ActionView
::
Helpers
::
AssetTagHelper
::
STYLESHEETS_DIR
,
'all.css'
))
expected_mtime
=
files_to_be_joined
.
map
{
|
p
|
File
.
mtime
(
p
)
}.
max
assert_equal
expected_mtime
,
File
.
mtime
(
File
.
join
(
ActionView
::
Helpers
::
AssetTagHelper
::
STYLESHEETS_DIR
,
'all.css'
))
bytes_added_by_join
=
"
\n\n
"
.
size
*
files_to_be_joined
.
size
-
"
\n\n
"
.
size
expected_size
=
files_to_be_joined
.
sum
{
|
p
|
File
.
size
(
p
)
}
+
bytes_added_by_join
assert_equal
expected_size
,
File
.
size
(
File
.
join
(
ActionView
::
Helpers
::
AssetTagHelper
::
STYLESHEETS_DIR
,
'all.css'
))
assert_dom_equal
(
assert_dom_equal
(
%(<link href="http://a0.example.com/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(<link href="http://a0.example.com/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />)
,
...
@@ -598,6 +632,28 @@ def test_concat_stylesheet_link_tag_when_caching_off
...
@@ -598,6 +632,28 @@ def test_concat_stylesheet_link_tag_when_caching_off
FileUtils
.
rm_f
(
File
.
join
(
ActionView
::
Helpers
::
AssetTagHelper
::
ASSETS_DIR
,
'absolute'
))
FileUtils
.
rm_f
(
File
.
join
(
ActionView
::
Helpers
::
AssetTagHelper
::
ASSETS_DIR
,
'absolute'
))
end
end
def
test_caching_stylesheet_link_tag_when_caching_on_and_missing_css_file
ENV
[
"RAILS_ASSET_ID"
]
=
""
ActionController
::
Base
.
asset_host
=
'http://a0.example.com'
ActionController
::
Base
.
perform_caching
=
true
assert_raise
(
Errno
::
ENOENT
)
{
stylesheet_link_tag
(
'bank'
,
'robber'
,
'missing_security_guard'
,
:cache
=>
true
)
}
assert
!
File
.
exist?
(
File
.
join
(
ActionView
::
Helpers
::
AssetTagHelper
::
STYLESHEETS_DIR
,
'all.css'
))
assert_raise
(
Errno
::
ENOENT
)
{
stylesheet_link_tag
(
'bank'
,
'robber'
,
'missing_security_guard'
,
:cache
=>
"money"
)
}
assert
!
File
.
exist?
(
File
.
join
(
ActionView
::
Helpers
::
AssetTagHelper
::
STYLESHEETS_DIR
,
'money.css'
))
ensure
FileUtils
.
rm_f
(
File
.
join
(
ActionView
::
Helpers
::
AssetTagHelper
::
STYLESHEETS_DIR
,
'all.css'
))
FileUtils
.
rm_f
(
File
.
join
(
ActionView
::
Helpers
::
AssetTagHelper
::
STYLESHEETS_DIR
,
'money.css'
))
end
def
test_caching_stylesheet_link_tag_when_caching_on_with_proc_asset_host
def
test_caching_stylesheet_link_tag_when_caching_on_with_proc_asset_host
ENV
[
"RAILS_ASSET_ID"
]
=
""
ENV
[
"RAILS_ASSET_ID"
]
=
""
ActionController
::
Base
.
asset_host
=
Proc
.
new
{
|
source
|
"http://a
#{
source
.
length
}
.example.com"
}
ActionController
::
Base
.
asset_host
=
Proc
.
new
{
|
source
|
"http://a
#{
source
.
length
}
.example.com"
}
...
@@ -625,8 +681,10 @@ def test_caching_stylesheet_link_tag_with_relative_url_root
...
@@ -625,8 +681,10 @@ def test_caching_stylesheet_link_tag_with_relative_url_root
stylesheet_link_tag
(
:all
,
:cache
=>
true
)
stylesheet_link_tag
(
:all
,
:cache
=>
true
)
)
)
expected
=
Dir
[
"
#{
ActionView
::
Helpers
::
AssetTagHelper
::
STYLESHEETS_DIR
}
/*.css"
].
map
{
|
p
|
File
.
mtime
(
p
)
}.
max
files_to_be_joined
=
Dir
[
"
#{
ActionView
::
Helpers
::
AssetTagHelper
::
STYLESHEETS_DIR
}
/[^all]*.css"
]
assert_equal
expected
,
File
.
mtime
(
File
.
join
(
ActionView
::
Helpers
::
AssetTagHelper
::
STYLESHEETS_DIR
,
'all.css'
))
expected_mtime
=
files_to_be_joined
.
map
{
|
p
|
File
.
mtime
(
p
)
}.
max
assert_equal
expected_mtime
,
File
.
mtime
(
File
.
join
(
ActionView
::
Helpers
::
AssetTagHelper
::
STYLESHEETS_DIR
,
'all.css'
))
assert_dom_equal
(
assert_dom_equal
(
%(<link href="/collaboration/hieraki/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />)
,
%(<link href="/collaboration/hieraki/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />)
,
...
...
activerecord/lib/active_record/base.rb
浏览文件 @
915f108d
...
@@ -67,6 +67,25 @@ class RecordNotSaved < ActiveRecordError
...
@@ -67,6 +67,25 @@ class RecordNotSaved < ActiveRecordError
class
StatementInvalid
<
ActiveRecordError
class
StatementInvalid
<
ActiveRecordError
end
end
# Parent class for all specific exceptions which wrap database driver exceptions
# provides access to the original exception also.
class
WrappedDatabaseException
<
StatementInvalid
attr_reader
:original_exception
def
initialize
(
message
,
original_exception
)
super
(
message
)
@original_exception
,
=
original_exception
end
end
# Raised when a record cannot be inserted because it would violate a uniqueness constraint.
class
RecordNotUnique
<
WrappedDatabaseException
end
# Raised when a record cannot be inserted or updated because it references a non-existent record.
class
InvalidForeignKey
<
WrappedDatabaseException
end
# Raised when number of bind variables in statement given to <tt>:condition</tt> key (for example, when using +find+ method)
# Raised when number of bind variables in statement given to <tt>:condition</tt> key (for example, when using +find+ method)
# does not match number of expected variables.
# does not match number of expected variables.
#
#
...
...
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
浏览文件 @
915f108d
...
@@ -211,9 +211,14 @@ def log(sql, name)
...
@@ -211,9 +211,14 @@ def log(sql, name)
@last_verification
=
0
@last_verification
=
0
message
=
"
#{
e
.
class
.
name
}
:
#{
e
.
message
}
:
#{
sql
}
"
message
=
"
#{
e
.
class
.
name
}
:
#{
e
.
message
}
:
#{
sql
}
"
log_info
(
message
,
name
,
0
)
log_info
(
message
,
name
,
0
)
raise
ActiveRecord
::
StatementInvalid
,
message
raise
translate_exception
(
e
,
message
)
end
end
def
translate_exception
(
e
,
message
)
# override in derived class
ActiveRecord
::
StatementInvalid
.
new
(
message
)
end
def
format_log_entry
(
message
,
dump
=
nil
)
def
format_log_entry
(
message
,
dump
=
nil
)
if
ActiveRecord
::
Base
.
colorize_logging
if
ActiveRecord
::
Base
.
colorize_logging
if
@@row_even
if
@@row_even
...
...
activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
浏览文件 @
915f108d
...
@@ -563,6 +563,19 @@ def limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key)
...
@@ -563,6 +563,19 @@ def limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key)
where_sql
where_sql
end
end
protected
def
translate_exception
(
exception
,
message
)
case
exception
.
errno
when
1062
RecordNotUnique
.
new
(
message
,
exception
)
when
1452
InvalidForeignKey
.
new
(
message
,
exception
)
else
super
end
end
private
private
def
connect
def
connect
encoding
=
@config
[
:encoding
]
encoding
=
@config
[
:encoding
]
...
...
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
915f108d
...
@@ -941,6 +941,17 @@ def postgresql_version
...
@@ -941,6 +941,17 @@ def postgresql_version
end
end
end
end
def
translate_exception
(
exception
,
message
)
case
exception
.
message
when
/duplicate key value violates unique constraint/
RecordNotUnique
.
new
(
message
,
exception
)
when
/violates foreign key constraint/
InvalidForeignKey
.
new
(
message
,
exception
)
else
super
end
end
private
private
# The internal PostgreSQL identifier of the money data type.
# The internal PostgreSQL identifier of the money data type.
MONEY_COLUMN_TYPE_OID
=
790
#:nodoc:
MONEY_COLUMN_TYPE_OID
=
790
#:nodoc:
...
...
activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
浏览文件 @
915f108d
...
@@ -431,6 +431,16 @@ def default_primary_key_type
...
@@ -431,6 +431,16 @@ def default_primary_key_type
'INTEGER PRIMARY KEY NOT NULL'
.
freeze
'INTEGER PRIMARY KEY NOT NULL'
.
freeze
end
end
end
end
def
translate_exception
(
exception
,
message
)
case
exception
.
message
when
/column(s)? .* (is|are) not unique/
RecordNotUnique
.
new
(
message
,
exception
)
else
super
end
end
end
end
class
SQLite2Adapter
<
SQLiteAdapter
# :nodoc:
class
SQLite2Adapter
<
SQLiteAdapter
# :nodoc:
...
...
activerecord/test/cases/adapter_test.rb
浏览文件 @
915f108d
...
@@ -130,4 +130,19 @@ def test_add_limit_offset_should_sanitize_sql_injection_for_limit_with_comas
...
@@ -130,4 +130,19 @@ def test_add_limit_offset_should_sanitize_sql_injection_for_limit_with_comas
assert_equal
" LIMIT 1,7 OFFSET 7"
,
@connection
.
add_limit_offset!
(
""
,
:limit
=>
sql_inject
,
:offset
=>
7
)
assert_equal
" LIMIT 1,7 OFFSET 7"
,
@connection
.
add_limit_offset!
(
""
,
:limit
=>
sql_inject
,
:offset
=>
7
)
end
end
end
end
def
test_uniqueness_violations_are_translated_to_specific_exception
@connection
.
execute
"INSERT INTO subscribers(nick) VALUES('me')"
assert_raises
(
ActiveRecord
::
RecordNotUnique
)
do
@connection
.
execute
"INSERT INTO subscribers(nick) VALUES('me')"
end
end
def
test_foreign_key_violations_are_translated_to_specific_exception
unless
@connection
.
adapter_name
==
'SQLite'
assert_raises
(
ActiveRecord
::
InvalidForeignKey
)
do
@connection
.
execute
"INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
end
end
end
end
end
activesupport/lib/active_support/cache.rb
浏览文件 @
915f108d
...
@@ -2,7 +2,12 @@
...
@@ -2,7 +2,12 @@
require
'active_support/core_ext/benchmark'
require
'active_support/core_ext/benchmark'
require
'active_support/core_ext/exception'
require
'active_support/core_ext/exception'
require
'active_support/core_ext/class/attribute_accessors'
require
'active_support/core_ext/class/attribute_accessors'
require
'active_support/core_ext'
# FIXME: pulling in all to_param extensions
%w(hash nil string time date date_time array big_decimal range object boolean)
.
each
do
|
library
|
require
"active_support/core_ext/
#{
library
}
/conversions"
end
# require 'active_support/core_ext' # FIXME: pulling in all to_param extensions
module
ActiveSupport
module
ActiveSupport
# See ActiveSupport::Cache::Store for documentation.
# See ActiveSupport::Cache::Store for documentation.
...
...
railties/lib/initializer.rb
浏览文件 @
915f108d
...
@@ -101,6 +101,7 @@ def self.default
...
@@ -101,6 +101,7 @@ def self.default
def
self
.
run
(
initializer
=
nil
,
config
=
nil
)
def
self
.
run
(
initializer
=
nil
,
config
=
nil
)
default
.
config
=
config
if
config
default
.
config
=
config
if
config
default
.
config
||=
Configuration
.
new
default
.
config
||=
Configuration
.
new
yield
default
.
config
if
block_given?
default
.
run
(
initializer
)
default
.
run
(
initializer
)
end
end
end
end
...
@@ -176,7 +177,8 @@ def self.run(initializer = nil, config = nil)
...
@@ -176,7 +177,8 @@ def self.run(initializer = nil, config = nil)
# Action Pack, Action Mailer, and Active Resource) are loaded.
# Action Pack, Action Mailer, and Active Resource) are loaded.
Initializer
.
default
.
add
:require_frameworks
do
Initializer
.
default
.
add
:require_frameworks
do
begin
begin
require
'active_support/all'
require
'active_support'
require
'active_support/core_ext/kernel/reporting'
configuration
.
frameworks
.
each
{
|
framework
|
require
(
framework
.
to_s
)
}
configuration
.
frameworks
.
each
{
|
framework
|
require
(
framework
.
to_s
)
}
rescue
LoadError
=>
e
rescue
LoadError
=>
e
# Re-raise as RuntimeError because Mongrel would swallow LoadError.
# Re-raise as RuntimeError because Mongrel would swallow LoadError.
...
@@ -396,12 +398,15 @@ def self.run(initializer = nil, config = nil)
...
@@ -396,12 +398,15 @@ def self.run(initializer = nil, config = nil)
end
end
Initializer
.
default
.
add
:initialize_metal
do
Initializer
.
default
.
add
:initialize_metal
do
Rails
::
Rack
::
Metal
.
requested_metals
=
configuration
.
metals
# TODO: Make Rails and metal work without ActionController
Rails
::
Rack
::
Metal
.
metal_paths
+=
plugin_loader
.
engine_metal_paths
if
defined?
(
ActionController
)
Rails
::
Rack
::
Metal
.
requested_metals
=
configuration
.
metals
Rails
::
Rack
::
Metal
.
metal_paths
+=
plugin_loader
.
engine_metal_paths
configuration
.
middleware
.
insert_before
(
configuration
.
middleware
.
insert_before
(
:"ActionDispatch::ParamsParser"
,
:"ActionDispatch::ParamsParser"
,
Rails
::
Rack
::
Metal
,
:if
=>
Rails
::
Rack
::
Metal
.
metals
.
any?
)
Rails
::
Rack
::
Metal
,
:if
=>
Rails
::
Rack
::
Metal
.
metals
.
any?
)
end
end
end
# Add the load paths used by support functions such as the info controller
# Add the load paths used by support functions such as the info controller
...
...
railties/lib/performance_test_help.rb
浏览文件 @
915f108d
require
'action_controller/performance_test'
require
'action_controller/
testing/
performance_test'
ActionController
::
Base
.
perform_caching
=
true
ActionController
::
Base
.
perform_caching
=
true
ActiveSupport
::
Dependencies
.
mechanism
=
:require
ActiveSupport
::
Dependencies
.
mechanism
=
:require
...
...
railties/lib/rails/configuration.rb
浏览文件 @
915f108d
...
@@ -93,7 +93,6 @@ def framework_root_path
...
@@ -93,7 +93,6 @@ def framework_root_path
# TODO: Fix this when there is an application object
# TODO: Fix this when there is an application object
def
middleware
def
middleware
require
'action_controller'
ActionController
::
Dispatcher
.
middleware
ActionController
::
Dispatcher
.
middleware
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录