Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a95c2eca
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,发现更多精彩内容 >>
未验证
提交
a95c2eca
编写于
11月 19, 2018
作者:
A
Aaron Patterson
提交者:
GitHub
11月 19, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #34453 from bogdanvlviv/exercise-connected_to-and-connects_to
Exercise `connected_to` and `connects_to` methods
上级
c4720a25
cf01da28
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
1 deletion
+36
-1
activerecord/lib/active_record/connection_handling.rb
activerecord/lib/active_record/connection_handling.rb
+1
-1
activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb
.../connection_adapters/connection_handlers_multi_db_test.rb
+35
-0
未找到文件。
activerecord/lib/active_record/connection_handling.rb
浏览文件 @
a95c2eca
...
...
@@ -107,7 +107,7 @@ def connects_to(database: {})
# end
def
connected_to
(
database:
nil
,
role:
nil
,
&
blk
)
if
database
&&
role
raise
ArgumentError
,
"connected_to can only accept a
database or role
argument, but not both arguments."
raise
ArgumentError
,
"connected_to can only accept a
`database` or a `role`
argument, but not both arguments."
elsif
database
if
database
.
is_a?
(
Hash
)
role
,
database
=
database
.
first
...
...
activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb
浏览文件 @
a95c2eca
...
...
@@ -153,6 +153,20 @@ def test_switching_connections_with_database_config_hash
ENV
[
"RAILS_ENV"
]
=
previous_env
end
def
test_switching_connections_with_database_and_role_raises
error
=
assert_raises
(
ArgumentError
)
do
ActiveRecord
::
Base
.
connected_to
(
database: :readonly
,
role: :writing
)
{
}
end
assert_equal
"connected_to can only accept a `database` or a `role` argument, but not both arguments."
,
error
.
message
end
def
test_switching_connections_without_database_and_role_raises
error
=
assert_raises
(
ArgumentError
)
do
ActiveRecord
::
Base
.
connected_to
{
}
end
assert_equal
"must provide a `database` or a `role`."
,
error
.
message
end
def
test_switching_connections_with_database_symbol
previous_env
,
ENV
[
"RAILS_ENV"
]
=
ENV
[
"RAILS_ENV"
],
"default_env"
...
...
@@ -207,6 +221,27 @@ def test_connects_to_using_top_level_key_in_two_level_config
ActiveRecord
::
Base
.
configurations
=
@prev_configs
ActiveRecord
::
Base
.
establish_connection
(
:arunit
)
end
def
test_connects_to_returns_array_of_established_connections
config
=
{
"development"
=>
{
"adapter"
=>
"sqlite3"
,
"database"
=>
"db/primary.sqlite3"
},
"development_readonly"
=>
{
"adapter"
=>
"sqlite3"
,
"database"
=>
"db/readonly.sqlite3"
}
}
@prev_configs
,
ActiveRecord
::
Base
.
configurations
=
ActiveRecord
::
Base
.
configurations
,
config
result
=
ActiveRecord
::
Base
.
connects_to
database:
{
writing: :development
,
reading: :development_readonly
}
assert_equal
(
[
ActiveRecord
::
Base
.
connection_handlers
[
:writing
].
retrieve_connection_pool
(
"primary"
),
ActiveRecord
::
Base
.
connection_handlers
[
:reading
].
retrieve_connection_pool
(
"primary"
)
],
result
)
ensure
ActiveRecord
::
Base
.
configurations
=
@prev_configs
ActiveRecord
::
Base
.
establish_connection
(
:arunit
)
end
end
def
test_connection_pools
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录