Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ec118073
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 搜索 >>
提交
ec118073
编写于
12月 24, 2013
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Deprecate use of string in establish_connection as connection lookup
上级
d2ed433b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
33 addition
and
15 deletion
+33
-15
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
activerecord/lib/active_record/connection_adapters/connection_specification.rb
...ve_record/connection_adapters/connection_specification.rb
+16
-9
activerecord/lib/active_record/connection_handling.rb
activerecord/lib/active_record/connection_handling.rb
+7
-0
activerecord/test/cases/adapter_test.rb
activerecord/test/cases/adapter_test.rb
+1
-1
activerecord/test/cases/multiple_db_test.rb
activerecord/test/cases/multiple_db_test.rb
+1
-1
activerecord/test/cases/transaction_isolation_test.rb
activerecord/test/cases/transaction_isolation_test.rb
+2
-2
activerecord/test/support/connection.rb
activerecord/test/support/connection.rb
+2
-2
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
ec118073
*
Deprecated use of string argument as a configuration lookup in
`ActiveRecord::Base.establish_connection`
. Instead, a symbol must be given.
*José Valim*
*
Fixed
`update_column`
,
`update_columns`
, and
`update_all`
to correctly serialize
values for
`array`
,
`hstore`
and
`json`
column types in PostgreSQL.
...
...
activerecord/lib/active_record/connection_adapters/connection_specification.rb
浏览文件 @
ec118073
...
...
@@ -26,7 +26,7 @@ def resolve(config)
if
config
resolve_connection
config
elsif
defined?
(
Rails
.
env
)
resolve_env_connection
Rails
.
env
resolve_env_connection
Rails
.
env
.
to_sym
else
raise
AdapterNotSpecified
end
...
...
@@ -55,7 +55,7 @@ def spec(config)
def
resolve_connection
(
spec
)
#:nodoc:
case
spec
when
Symbol
,
String
resolve_env_connection
spec
.
to_s
resolve_env_connection
spec
when
Hash
resolve_hash_connection
spec
end
...
...
@@ -63,14 +63,21 @@ def resolve_connection(spec) #:nodoc:
def
resolve_env_connection
(
spec
)
# :nodoc:
# Rails has historically accepted a string to mean either
# an environment key or a url spec. So we support both for
# now but it would be nice to limit the environment key only
# for symbols.
config
=
configurations
.
fetch
(
spec
.
to_s
)
do
resolve_string_connection
(
spec
)
if
spec
.
is_a?
(
String
)
# an environment key or a url spec, so we have deprecated
# this ambiguous behaviour and in the future this function
# can be removed in favor of resolve_string_connection and
# resolve_symbol_connection.
if
config
=
configurations
[
spec
.
to_s
]
if
spec
.
is_a?
(
String
)
ActiveSupport
::
Deprecation
.
warn
"Passing a string to ActiveRecord::Base.establish_connection "
\
"for a configuration lookup is deprecated, please pass a symbol (
#{
spec
.
to_sym
.
inspect
}
) instead"
end
resolve_connection
(
config
)
elsif
spec
.
is_a?
(
String
)
resolve_string_connection
(
spec
)
else
raise
(
AdapterNotSpecified
,
"
#{
spec
}
database is not configured"
)
end
raise
(
AdapterNotSpecified
,
"
#{
spec
}
database is not configured"
)
unless
config
resolve_connection
(
config
)
end
def
resolve_hash_connection
(
spec
)
# :nodoc:
...
...
activerecord/lib/active_record/connection_handling.rb
浏览文件 @
ec118073
...
...
@@ -32,6 +32,13 @@ module ConnectionHandling
# "postgres://myuser:mypass@localhost/somedatabase"
# )
#
# In case <tt>ActiveRecord::Base.configurations</tt> is set (Rails
# automatically loads the contents of config/database.yml into it),
# a symbol can also be given as argument, representing a key in the
# configuration hash:
#
# ActiveRecord::Base.establish_connection(:production)
#
# The exceptions AdapterNotSpecified, AdapterNotFound and ArgumentError
# may be returned on an error.
def
establish_connection
(
spec
=
ENV
[
"DATABASE_URL"
])
...
...
activerecord/test/cases/adapter_test.rb
浏览文件 @
ec118073
...
...
@@ -191,7 +191,7 @@ class Klass < ActiveRecord::Base
end
def
setup
Klass
.
establish_connection
'arunit'
Klass
.
establish_connection
:arunit
@connection
=
Klass
.
connection
end
...
...
activerecord/test/cases/multiple_db_test.rb
浏览文件 @
ec118073
...
...
@@ -101,7 +101,7 @@ def test_associations_should_work_when_model_has_no_connection
College
.
first
.
courses
.
first
end
ensure
ActiveRecord
::
Base
.
establish_connection
'arunit'
ActiveRecord
::
Base
.
establish_connection
:arunit
end
end
end
...
...
activerecord/test/cases/transaction_isolation_test.rb
浏览文件 @
ec118073
...
...
@@ -28,8 +28,8 @@ class Tag2 < ActiveRecord::Base
end
setup
do
Tag
.
establish_connection
'arunit'
Tag2
.
establish_connection
'arunit'
Tag
.
establish_connection
:arunit
Tag2
.
establish_connection
:arunit
Tag
.
destroy_all
end
...
...
activerecord/test/support/connection.rb
浏览文件 @
ec118073
...
...
@@ -15,7 +15,7 @@ def self.connect
puts
"Using
#{
connection_name
}
"
ActiveRecord
::
Base
.
logger
=
ActiveSupport
::
Logger
.
new
(
"debug.log"
,
0
,
100
*
1024
*
1024
)
ActiveRecord
::
Base
.
configurations
=
connection_config
ActiveRecord
::
Base
.
establish_connection
'arunit'
ARUnit2Model
.
establish_connection
'arunit2'
ActiveRecord
::
Base
.
establish_connection
:arunit
ARUnit2Model
.
establish_connection
:arunit2
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录