Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
395573b3
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,发现更多精彩内容 >>
提交
395573b3
编写于
9月 11, 2014
作者:
Y
Yves Senn
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reuse view test-cases for pg materialized view tests.
上级
e40bf04a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
67 deletion
+36
-67
activerecord/test/cases/adapters/postgresql/view_test.rb
activerecord/test/cases/adapters/postgresql/view_test.rb
+9
-58
activerecord/test/cases/view_test.rb
activerecord/test/cases/view_test.rb
+27
-9
未找到文件。
activerecord/test/cases/adapters/postgresql/view_test.rb
浏览文件 @
395573b3
require
"cases/helper"
require
"cases/view_test"
module
ViewTestConcern
extend
ActiveSupport
::
Concern
included
do
self
.
use_transactional_fixtures
=
false
mattr_accessor
:view_type
end
SCHEMA_NAME
=
'test_schema'
TABLE_NAME
=
'things'
COLUMNS
=
[
'id integer'
,
'name character varying(50)'
,
'email character varying(50)'
,
'moment timestamp without time zone'
]
class
ThingView
<
ActiveRecord
::
Base
end
def
setup
super
ThingView
.
table_name
=
"
#{
SCHEMA_NAME
}
.
#{
view_type
}
_things"
if
ActiveRecord
::
Base
.
connection
.
supports_materialized_views?
class
MaterializedViewTest
<
ActiveRecord
::
TestCase
include
ViewBehavior
@connection
=
ActiveRecord
::
Base
.
connection
@connection
.
execute
"CREATE SCHEMA
#{
SCHEMA_NAME
}
CREATE TABLE
#{
TABLE_NAME
}
(
#{
COLUMNS
.
join
(
','
)
}
)"
@connection
.
execute
"CREATE
#{
view_type
.
humanize
}
#{
ThingView
.
table_name
}
AS SELECT * FROM
#{
SCHEMA_NAME
}
.
#{
TABLE_NAME
}
"
private
def
create_view
(
name
,
query
)
@connection
.
execute
"CREATE
MATERIALIZED VIEW
#{
name
}
AS
#{
query
}
"
end
def
teardown
super
@connection
.
execute
"DROP SCHEMA
#{
SCHEMA_NAME
}
CASCADE"
end
def
drop_view
(
name
)
@connection
.
execute
"DROP MATERIALIZED VIEW
#{
name
}
"
if
@connection
.
table_exists?
name
def
test_table_exists
name
=
ThingView
.
table_name
assert
@connection
.
table_exists?
(
name
),
"'
#{
name
}
' table should exist"
end
def
test_column_definitions
assert_nothing_raised
do
assert_equal
COLUMNS
,
columns
(
ThingView
.
table_name
)
end
end
private
def
columns
(
table_name
)
@connection
.
send
(
:column_definitions
,
table_name
).
map
do
|
name
,
type
,
default
|
"
#{
name
}
#{
type
}
"
+
(
default
?
" default
#{
default
}
"
:
''
)
end
end
end
class
ViewTest
<
ActiveRecord
::
TestCase
include
ViewTestConcern
self
.
view_type
=
'view'
end
if
ActiveRecord
::
Base
.
connection
.
supports_materialized_views?
class
MaterializedViewTest
<
ActiveRecord
::
TestCase
include
ViewTestConcern
self
.
view_type
=
'materialized_view'
end
end
activerecord/test/cases/view_test.rb
浏览文件 @
395573b3
require
"cases/helper"
require
"models/book"
if
ActiveRecord
::
Base
.
connection
.
supports_views?
class
ViewWithPrimaryKeyTest
<
ActiveRecord
::
TestCase
fixtures
:books
module
ViewBehavior
extend
ActiveSupport
::
Concern
included
do
fixtures
:books
end
class
Ebook
<
ActiveRecord
::
Base
self
.
primary_key
=
"id"
end
setup
do
def
setup
super
@connection
=
ActiveRecord
::
Base
.
connection
@connection
.
execute
<<-
SQL
CREATE VIEW ebooks
AS SELECT id, name, status FROM books WHERE format = 'ebook'
create_view
"ebooks"
,
<<-
SQL
SELECT id, name, status FROM books WHERE format = 'ebook'
SQL
end
teardown
do
@connection
.
execute
"DROP VIEW ebooks"
if
@connection
.
table_exists?
"ebooks"
def
teardown
super
drop_view
"ebooks"
end
def
test_reading
...
...
@@ -51,6 +55,20 @@ def test_does_not_assume_id_column_as_primary_key
end
end
if
ActiveRecord
::
Base
.
connection
.
supports_views?
class
ViewWithPrimaryKeyTest
<
ActiveRecord
::
TestCase
include
ViewBehavior
private
def
create_view
(
name
,
query
)
@connection
.
execute
"CREATE VIEW
#{
name
}
AS
#{
query
}
"
end
def
drop_view
(
name
)
@connection
.
execute
"DROP VIEW
#{
name
}
"
if
@connection
.
table_exists?
name
end
end
class
ViewWithoutPrimaryKeyTest
<
ActiveRecord
::
TestCase
fixtures
:books
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录