Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
09fbee82
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,发现更多精彩内容 >>
未验证
提交
09fbee82
编写于
1月 07, 2020
作者:
E
Eileen M. Uchitelle
提交者:
GitHub
1月 07, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #38179 from eileencodes/fix-resolve-symbol-conn
Restore previous behavior of parallel test databases
上级
8c65783d
c0509885
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
38 addition
and
15 deletion
+38
-15
activerecord/lib/active_record/database_configurations/database_config.rb
.../active_record/database_configurations/database_config.rb
+4
-0
activerecord/lib/active_record/database_configurations/hash_config.rb
.../lib/active_record/database_configurations/hash_config.rb
+4
-0
activerecord/lib/active_record/test_databases.rb
activerecord/lib/active_record/test_databases.rb
+3
-14
activerecord/test/cases/test_databases_test.rb
activerecord/test/cases/test_databases_test.rb
+27
-1
未找到文件。
activerecord/lib/active_record/database_configurations/database_config.rb
浏览文件 @
09fbee82
...
...
@@ -30,6 +30,10 @@ def database
raise
NotImplementedError
end
def
_database
=
(
database
)
raise
NotImplementedError
end
def
adapter
raise
NotImplementedError
end
...
...
activerecord/lib/active_record/database_configurations/hash_config.rb
浏览文件 @
09fbee82
...
...
@@ -61,6 +61,10 @@ def database
configuration_hash
[
:database
]
end
def
_database
=
(
database
)
# :nodoc:
@config
=
configuration_hash
.
dup
.
merge
(
database:
database
).
freeze
end
def
pool
(
configuration_hash
[
:pool
]
||
5
).
to_i
end
...
...
activerecord/lib/active_record/test_databases.rb
浏览文件 @
09fbee82
...
...
@@ -12,23 +12,12 @@ def self.create_and_load_schema(i, env_name:)
old
,
ENV
[
"VERBOSE"
]
=
ENV
[
"VERBOSE"
],
"false"
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
env_name
).
each
do
|
db_config
|
database
=
"
#{
db_config
.
database
}
-
#{
i
}
"
d
b_config
.
_d
atabase
=
"
#{
db_config
.
database
}
-
#{
i
}
"
db_config_copy
=
ActiveRecord
::
DatabaseConfigurations
::
HashConfig
.
new
(
env_name
,
db_config
.
spec_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
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
reconstruct_from_schema
(
db_config
,
ActiveRecord
::
Base
.
schema_format
,
nil
)
end
ensure
ActiveRecord
::
Base
.
establish_connection
(
ActiveRecord
::
ConnectionHandling
::
DEFAULT_ENV
.
call
.
to_sym
)
ActiveRecord
::
Base
.
establish_connection
ENV
[
"VERBOSE"
]
=
old
end
end
...
...
activerecord/test/cases/test_databases_test.rb
浏览文件 @
09fbee82
...
...
@@ -25,6 +25,7 @@ def test_databases_are_created
ActiveRecord
::
Base
.
configurations
=
prev_configs
ActiveRecord
::
Base
.
establish_connection
(
:arunit
)
ENV
[
"RAILS_ENV"
]
=
previous_env
FileUtils
.
rm_rf
(
"db"
)
end
def
test_create_databases_after_fork
...
...
@@ -45,12 +46,37 @@ def test_create_databases_after_fork
ActiveSupport
::
Testing
::
Parallelization
.
after_fork_hooks
.
each
{
|
cb
|
cb
.
call
(
idx
)
}
end
# Updates the databse configuration
# Updates the datab
a
se 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
FileUtils
.
rm_rf
(
"db"
)
end
def
test_order_of_configurations_isnt_changed_by_test_databases
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"
},
"replica"
=>
{
"adapter"
=>
"sqlite3"
,
"database"
=>
"db/primary.sqlite3"
}
}
}
idx
=
42
base_configs_order
=
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
"arunit"
).
map
(
&
:spec_name
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
stub
(
:reconstruct_from_schema
,
->
(
db_config
,
_
,
_
)
{
assert_equal
base_configs_order
,
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
"arunit"
).
map
(
&
:spec_name
)
})
do
ActiveSupport
::
Testing
::
Parallelization
.
after_fork_hooks
.
each
{
|
cb
|
cb
.
call
(
idx
)
}
end
ensure
ActiveRecord
::
Base
.
configurations
=
prev_configs
ActiveRecord
::
Base
.
establish_connection
(
:arunit
)
ENV
[
"RAILS_ENV"
]
=
previous_env
FileUtils
.
rm_rf
(
"db"
)
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录