Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
23f80cee
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,发现更多精彩内容 >>
未验证
提交
23f80cee
编写于
7月 10, 2018
作者:
R
Ryuta Kamizono
提交者:
GitHub
7月 10, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #33326 from utilum/replace_shallow_mocks_with_ruby
Replace shallow mocks with Ruby classes
上级
d41ec818
f7bfb3db
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
47 addition
and
18 deletion
+47
-18
activerecord/test/cases/fixtures_test.rb
activerecord/test/cases/fixtures_test.rb
+17
-4
activerecord/test/cases/tasks/database_tasks_test.rb
activerecord/test/cases/tasks/database_tasks_test.rb
+11
-1
activerecord/test/cases/tasks/mysql_rake_test.rb
activerecord/test/cases/tasks/mysql_rake_test.rb
+6
-6
activerecord/test/cases/tasks/postgresql_rake_test.rb
activerecord/test/cases/tasks/postgresql_rake_test.rb
+8
-5
activerecord/test/cases/tasks/sqlite_rake_test.rb
activerecord/test/cases/tasks/sqlite_rake_test.rb
+5
-2
未找到文件。
activerecord/test/cases/fixtures_test.rb
浏览文件 @
23f80cee
...
@@ -833,29 +833,42 @@ class TransactionalFixturesOnConnectionNotification < ActiveRecord::TestCase
...
@@ -833,29 +833,42 @@ class TransactionalFixturesOnConnectionNotification < ActiveRecord::TestCase
self
.
use_instantiated_fixtures
=
false
self
.
use_instantiated_fixtures
=
false
def
test_transaction_created_on_connection_notification
def
test_transaction_created_on_connection_notification
connection
=
stub
(
transaction_open?:
false
)
connection
=
Class
.
new
do
attr_accessor
:pool
def
transaction_open?
;
end
def
begin_transaction
(
*
args
);
end
def
rollback_transaction
(
*
args
);
end
end
.
new
connection
.
pool
=
Class
.
new
do
def
lock_thread
=
(
lock_thread
);
false
;
end
end
.
new
connection
.
expects
(
:begin_transaction
).
with
(
joinable:
false
)
connection
.
expects
(
:begin_transaction
).
with
(
joinable:
false
)
pool
=
connection
.
stubs
(
:pool
).
returns
(
ActiveRecord
::
ConnectionAdapters
::
ConnectionPool
.
new
(
ActiveRecord
::
Base
.
connection_pool
.
spec
))
pool
.
stubs
(
:lock_thread
=
).
with
(
false
)
fire_connection_notification
(
connection
)
fire_connection_notification
(
connection
)
end
end
def
test_notification_established_transactions_are_rolled_back
def
test_notification_established_transactions_are_rolled_back
# Mocha is not thread-safe so define our own stub to test
connection
=
Class
.
new
do
connection
=
Class
.
new
do
attr_accessor
:rollback_transaction_called
attr_accessor
:rollback_transaction_called
attr_accessor
:pool
attr_accessor
:pool
def
transaction_open?
;
true
;
end
def
transaction_open?
;
true
;
end
def
begin_transaction
(
*
args
);
end
def
begin_transaction
(
*
args
);
end
def
rollback_transaction
(
*
args
)
def
rollback_transaction
(
*
args
)
@rollback_transaction_called
=
true
@rollback_transaction_called
=
true
end
end
end
.
new
end
.
new
connection
.
pool
=
Class
.
new
do
connection
.
pool
=
Class
.
new
do
def
lock_thread
=
(
lock_thread
);
false
;
end
def
lock_thread
=
(
lock_thread
);
false
;
end
end
.
new
end
.
new
fire_connection_notification
(
connection
)
fire_connection_notification
(
connection
)
teardown_fixtures
teardown_fixtures
assert
(
connection
.
rollback_transaction_called
,
"Expected <mock connection>#rollback_transaction to be called but was not"
)
assert
(
connection
.
rollback_transaction_called
,
"Expected <mock connection>#rollback_transaction to be called but was not"
)
end
end
...
...
activerecord/test/cases/tasks/database_tasks_test.rb
浏览文件 @
23f80cee
...
@@ -6,7 +6,17 @@
...
@@ -6,7 +6,17 @@
module
ActiveRecord
module
ActiveRecord
module
DatabaseTasksSetupper
module
DatabaseTasksSetupper
def
setup
def
setup
@mysql_tasks
,
@postgresql_tasks
,
@sqlite_tasks
=
stub
,
stub
,
stub
@mysql_tasks
,
@postgresql_tasks
,
@sqlite_tasks
=
Array
.
new
(
3
,
Class
.
new
do
def
create
;
end
def
drop
;
end
def
purge
;
end
def
charset
;
end
def
collation
;
end
def
structure_dump
(
*
);
end
end
.
new
)
ActiveRecord
::
Tasks
::
MySQLDatabaseTasks
.
stubs
(
:new
).
returns
@mysql_tasks
ActiveRecord
::
Tasks
::
MySQLDatabaseTasks
.
stubs
(
:new
).
returns
@mysql_tasks
ActiveRecord
::
Tasks
::
PostgreSQLDatabaseTasks
.
stubs
(
:new
).
returns
@postgresql_tasks
ActiveRecord
::
Tasks
::
PostgreSQLDatabaseTasks
.
stubs
(
:new
).
returns
@postgresql_tasks
ActiveRecord
::
Tasks
::
SQLiteDatabaseTasks
.
stubs
(
:new
).
returns
@sqlite_tasks
ActiveRecord
::
Tasks
::
SQLiteDatabaseTasks
.
stubs
(
:new
).
returns
@sqlite_tasks
...
...
activerecord/test/cases/tasks/mysql_rake_test.rb
浏览文件 @
23f80cee
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
module
ActiveRecord
module
ActiveRecord
class
MysqlDBCreateTest
<
ActiveRecord
::
TestCase
class
MysqlDBCreateTest
<
ActiveRecord
::
TestCase
def
setup
def
setup
@connection
=
stub
(
create_database:
true
)
@connection
=
Class
.
new
{
def
create_database
(
*
);
end
}.
new
@configuration
=
{
@configuration
=
{
"adapter"
=>
"mysql2"
,
"adapter"
=>
"mysql2"
,
"database"
=>
"my-app-db"
"database"
=>
"my-app-db"
...
@@ -96,7 +96,7 @@ def teardown
...
@@ -96,7 +96,7 @@ def teardown
end
end
def
test_raises_error
def
test_raises_error
assert_raises
(
Mysql2
::
Error
)
do
assert_raises
(
Mysql2
::
Error
,
"Invalid permissions"
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create
@configuration
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create
@configuration
end
end
end
end
...
@@ -104,7 +104,7 @@ def test_raises_error
...
@@ -104,7 +104,7 @@ def test_raises_error
class
MySQLDBDropTest
<
ActiveRecord
::
TestCase
class
MySQLDBDropTest
<
ActiveRecord
::
TestCase
def
setup
def
setup
@connection
=
stub
(
drop_database:
true
)
@connection
=
Class
.
new
{
def
drop_database
(
name
);
true
end
}.
new
@configuration
=
{
@configuration
=
{
"adapter"
=>
"mysql2"
,
"adapter"
=>
"mysql2"
,
"database"
=>
"my-app-db"
"database"
=>
"my-app-db"
...
@@ -142,7 +142,7 @@ def test_when_database_dropped_successfully_outputs_info_to_stdout
...
@@ -142,7 +142,7 @@ def test_when_database_dropped_successfully_outputs_info_to_stdout
class
MySQLPurgeTest
<
ActiveRecord
::
TestCase
class
MySQLPurgeTest
<
ActiveRecord
::
TestCase
def
setup
def
setup
@connection
=
stub
(
recreate_database:
true
)
@connection
=
Class
.
new
{
def
recreate_database
(
*
);
end
}.
new
@configuration
=
{
@configuration
=
{
"adapter"
=>
"mysql2"
,
"adapter"
=>
"mysql2"
,
"database"
=>
"test-db"
"database"
=>
"test-db"
...
@@ -176,7 +176,7 @@ def test_recreates_database_with_the_given_options
...
@@ -176,7 +176,7 @@ def test_recreates_database_with_the_given_options
class
MysqlDBCharsetTest
<
ActiveRecord
::
TestCase
class
MysqlDBCharsetTest
<
ActiveRecord
::
TestCase
def
setup
def
setup
@connection
=
stub
(
create_database:
true
)
@connection
=
Class
.
new
{
def
charset
;
end
}.
new
@configuration
=
{
@configuration
=
{
"adapter"
=>
"mysql2"
,
"adapter"
=>
"mysql2"
,
"database"
=>
"my-app-db"
"database"
=>
"my-app-db"
...
@@ -193,7 +193,7 @@ def test_db_retrieves_charset
...
@@ -193,7 +193,7 @@ def test_db_retrieves_charset
class
MysqlDBCollationTest
<
ActiveRecord
::
TestCase
class
MysqlDBCollationTest
<
ActiveRecord
::
TestCase
def
setup
def
setup
@connection
=
stub
(
create_database:
true
)
@connection
=
Class
.
new
{
def
collation
;
end
}.
new
@configuration
=
{
@configuration
=
{
"adapter"
=>
"mysql2"
,
"adapter"
=>
"mysql2"
,
"database"
=>
"my-app-db"
"database"
=>
"my-app-db"
...
...
activerecord/test/cases/tasks/postgresql_rake_test.rb
浏览文件 @
23f80cee
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
module
ActiveRecord
module
ActiveRecord
class
PostgreSQLDBCreateTest
<
ActiveRecord
::
TestCase
class
PostgreSQLDBCreateTest
<
ActiveRecord
::
TestCase
def
setup
def
setup
@connection
=
stub
(
create_database:
true
)
@connection
=
Class
.
new
{
def
create_database
(
*
);
end
}.
new
@configuration
=
{
@configuration
=
{
"adapter"
=>
"postgresql"
,
"adapter"
=>
"postgresql"
,
"database"
=>
"my-app-db"
"database"
=>
"my-app-db"
...
@@ -89,7 +89,7 @@ def test_create_when_database_exists_outputs_info_to_stderr
...
@@ -89,7 +89,7 @@ def test_create_when_database_exists_outputs_info_to_stderr
class
PostgreSQLDBDropTest
<
ActiveRecord
::
TestCase
class
PostgreSQLDBDropTest
<
ActiveRecord
::
TestCase
def
setup
def
setup
@connection
=
stub
(
drop_database:
true
)
@connection
=
Class
.
new
{
def
drop_database
(
*
);
end
}.
new
@configuration
=
{
@configuration
=
{
"adapter"
=>
"postgresql"
,
"adapter"
=>
"postgresql"
,
"database"
=>
"my-app-db"
"database"
=>
"my-app-db"
...
@@ -131,7 +131,10 @@ def test_when_database_dropped_successfully_outputs_info_to_stdout
...
@@ -131,7 +131,10 @@ def test_when_database_dropped_successfully_outputs_info_to_stdout
class
PostgreSQLPurgeTest
<
ActiveRecord
::
TestCase
class
PostgreSQLPurgeTest
<
ActiveRecord
::
TestCase
def
setup
def
setup
@connection
=
stub
(
create_database:
true
,
drop_database:
true
)
@connection
=
Class
.
new
do
def
create_database
(
*
);
end
def
drop_database
(
*
);
end
end
.
new
@configuration
=
{
@configuration
=
{
"adapter"
=>
"postgresql"
,
"adapter"
=>
"postgresql"
,
"database"
=>
"my-app-db"
"database"
=>
"my-app-db"
...
@@ -179,7 +182,7 @@ def test_establishes_connection
...
@@ -179,7 +182,7 @@ def test_establishes_connection
class
PostgreSQLDBCharsetTest
<
ActiveRecord
::
TestCase
class
PostgreSQLDBCharsetTest
<
ActiveRecord
::
TestCase
def
setup
def
setup
@connection
=
stub
(
create_database:
true
)
@connection
=
Class
.
new
{
def
create_database
(
*
);
end
}.
new
@configuration
=
{
@configuration
=
{
"adapter"
=>
"postgresql"
,
"adapter"
=>
"postgresql"
,
"database"
=>
"my-app-db"
"database"
=>
"my-app-db"
...
@@ -197,7 +200,7 @@ def test_db_retrieves_charset
...
@@ -197,7 +200,7 @@ def test_db_retrieves_charset
class
PostgreSQLDBCollationTest
<
ActiveRecord
::
TestCase
class
PostgreSQLDBCollationTest
<
ActiveRecord
::
TestCase
def
setup
def
setup
@connection
=
stub
(
create_database:
true
)
@connection
=
Class
.
new
{
def
create_database
(
*
);
end
}.
new
@configuration
=
{
@configuration
=
{
"adapter"
=>
"postgresql"
,
"adapter"
=>
"postgresql"
,
"database"
=>
"my-app-db"
"database"
=>
"my-app-db"
...
...
activerecord/test/cases/tasks/sqlite_rake_test.rb
浏览文件 @
23f80cee
...
@@ -69,11 +69,14 @@ def test_db_create_with_error_prints_message
...
@@ -69,11 +69,14 @@ def test_db_create_with_error_prints_message
class
SqliteDBDropTest
<
ActiveRecord
::
TestCase
class
SqliteDBDropTest
<
ActiveRecord
::
TestCase
def
setup
def
setup
@database
=
"db_create.sqlite3"
@database
=
"db_create.sqlite3"
@path
=
stub
(
to_s:
"/absolute/path"
,
absolute?:
true
)
@configuration
=
{
@configuration
=
{
"adapter"
=>
"sqlite3"
,
"adapter"
=>
"sqlite3"
,
"database"
=>
@database
"database"
=>
@database
}
}
@path
=
Class
.
new
do
def
to_s
;
"/absolute/path"
end
def
absolute?
;
true
end
end
.
new
Pathname
.
stubs
(
:new
).
returns
(
@path
)
Pathname
.
stubs
(
:new
).
returns
(
@path
)
File
.
stubs
(
:join
).
returns
(
"/former/relative/path"
)
File
.
stubs
(
:join
).
returns
(
"/former/relative/path"
)
...
@@ -126,7 +129,7 @@ def test_when_db_dropped_successfully_outputs_info_to_stdout
...
@@ -126,7 +129,7 @@ def test_when_db_dropped_successfully_outputs_info_to_stdout
class
SqliteDBCharsetTest
<
ActiveRecord
::
TestCase
class
SqliteDBCharsetTest
<
ActiveRecord
::
TestCase
def
setup
def
setup
@database
=
"db_create.sqlite3"
@database
=
"db_create.sqlite3"
@connection
=
stub
:connection
@connection
=
Class
.
new
{
def
encoding
;
end
}.
new
@configuration
=
{
@configuration
=
{
"adapter"
=>
"sqlite3"
,
"adapter"
=>
"sqlite3"
,
"database"
=>
@database
"database"
=>
@database
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录