Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0be13cae
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,发现更多精彩内容 >>
未验证
提交
0be13cae
编写于
1月 03, 2020
作者:
R
Rafael França
提交者:
GitHub
1月 03, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #38151 from seejohnrun/fix-test-dbs
Pass env_name as a string in test databases
上级
7b29bc21
1f938f52
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
1 deletion
+40
-1
activerecord/lib/active_record/test_databases.rb
activerecord/lib/active_record/test_databases.rb
+6
-1
activerecord/test/cases/test_databases_test.rb
activerecord/test/cases/test_databases_test.rb
+34
-0
未找到文件。
activerecord/lib/active_record/test_databases.rb
浏览文件 @
0be13cae
...
...
@@ -5,7 +5,7 @@
module
ActiveRecord
module
TestDatabases
# :nodoc:
ActiveSupport
::
Testing
::
Parallelization
.
after_fork_hook
do
|
i
|
create_and_load_schema
(
i
,
env_name:
ActiveRecord
::
ConnectionHandling
::
DEFAULT_ENV
.
call
.
to_sym
)
create_and_load_schema
(
i
,
env_name:
ActiveRecord
::
ConnectionHandling
::
DEFAULT_ENV
.
call
)
end
def
self
.
create_and_load_schema
(
i
,
env_name
:)
...
...
@@ -20,7 +20,12 @@ def self.create_and_load_schema(i, env_name:)
db_config
.
configuration_hash
.
merge
(
database:
database
)
)
# Reconstruct with the new configuration
ActiveRecord
::
Tasks
::
DatabaseTasks
.
reconstruct_from_schema
(
db_config_copy
,
ActiveRecord
::
Base
.
schema_format
,
nil
)
# Replace the original configuration with our replacement
ActiveRecord
::
Base
.
configurations
.
configurations
.
delete
(
db_config
)
ActiveRecord
::
Base
.
configurations
.
configurations
.
push
(
db_config_copy
)
end
ensure
ActiveRecord
::
Base
.
establish_connection
(
ActiveRecord
::
ConnectionHandling
::
DEFAULT_ENV
.
call
.
to_sym
)
...
...
activerecord/test/cases/test_databases_test.rb
浏览文件 @
0be13cae
# frozen_string_literal: true
require
"cases/helper"
require
"active_record/test_databases"
class
TestDatabasesTest
<
ActiveRecord
::
TestCase
unless
in_memory_db?
def
test_databases_are_created
previous_env
,
ENV
[
"RAILS_ENV"
]
=
ENV
[
"RAILS_ENV"
],
"arunit"
prev_configs
,
ActiveRecord
::
Base
.
configurations
=
ActiveRecord
::
Base
.
configurations
,
{
"arunit"
=>
{
"primary"
=>
{
"adapter"
=>
"sqlite3"
,
"database"
=>
"db/primary.sqlite3"
}
}
}
base_db_config
=
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
"arunit"
,
spec_name:
"primary"
)
expected_database
=
"
#{
base_db_config
.
database
}
-2"
...
...
@@ -16,6 +22,34 @@ def test_databases_are_created
ActiveRecord
::
TestDatabases
.
create_and_load_schema
(
2
,
env_name:
"arunit"
)
end
ensure
ActiveRecord
::
Base
.
configurations
=
prev_configs
ActiveRecord
::
Base
.
establish_connection
(
:arunit
)
ENV
[
"RAILS_ENV"
]
=
previous_env
end
def
test_create_databases_after_fork
previous_env
,
ENV
[
"RAILS_ENV"
]
=
ENV
[
"RAILS_ENV"
],
"arunit"
prev_configs
,
ActiveRecord
::
Base
.
configurations
=
ActiveRecord
::
Base
.
configurations
,
{
"arunit"
=>
{
"primary"
=>
{
"adapter"
=>
"sqlite3"
,
"database"
=>
"db/primary.sqlite3"
}
}
}
idx
=
42
base_db_config
=
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
"arunit"
,
spec_name:
"primary"
)
expected_database
=
"
#{
base_db_config
.
database
}
-
#{
idx
}
"
ActiveRecord
::
Tasks
::
DatabaseTasks
.
stub
(
:reconstruct_from_schema
,
->
(
db_config
,
_
,
_
)
{
assert_equal
expected_database
,
db_config
.
database
})
do
ActiveSupport
::
Testing
::
Parallelization
.
after_fork_hooks
.
each
{
|
cb
|
cb
.
call
(
idx
)
}
end
# Updates the databse configuration
assert_equal
expected_database
,
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
"arunit"
,
spec_name:
"primary"
).
database
ensure
ActiveRecord
::
Base
.
configurations
=
prev_configs
ActiveRecord
::
Base
.
establish_connection
(
:arunit
)
ENV
[
"RAILS_ENV"
]
=
previous_env
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录