Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0ddfd75b
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,发现更多精彩内容 >>
提交
0ddfd75b
编写于
4月 14, 2013
作者:
M
Matt Aimonetti
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added a test suite for the postgres binary type
this shows a problem with nil values
上级
130d3a06
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
87 addition
and
0 deletion
+87
-0
activerecord/test/cases/adapters/postgresql/bytea_test.rb
activerecord/test/cases/adapters/postgresql/bytea_test.rb
+87
-0
未找到文件。
activerecord/test/cases/adapters/postgresql/bytea_test.rb
0 → 100644
浏览文件 @
0ddfd75b
# encoding: utf-8
require
"cases/helper"
require
'active_record/base'
require
'active_record/connection_adapters/postgresql_adapter'
class
PostgresqlByteaTest
<
ActiveRecord
::
TestCase
class
ByteaDataType
<
ActiveRecord
::
Base
self
.
table_name
=
'bytea_data_type'
end
def
setup
@connection
=
ActiveRecord
::
Base
.
connection
begin
@connection
.
transaction
do
@connection
.
create_table
(
'bytea_data_type'
)
do
|
t
|
t
.
binary
'payload'
end
end
end
@column
=
ByteaDataType
.
columns
.
find
{
|
c
|
c
.
name
==
'payload'
}
assert
(
@column
.
is_a?
(
ActiveRecord
::
ConnectionAdapters
::
PostgreSQLColumn
))
end
def
teardown
@connection
.
execute
'drop table if exists bytea_data_type'
end
def
test_column
assert_equal
:binary
,
@column
.
type
end
def
test_type_cast_binary_converts_the_encoding
assert
@column
data
=
"
\u
001F
\x8B
"
assert_equal
(
'UTF-8'
,
data
.
encoding
.
name
)
assert_equal
(
'ASCII-8BIT'
,
@column
.
type_cast
(
data
).
encoding
.
name
)
end
def
test_type_cast_binary_value
data
=
"
\u
001F
\x8B
"
.
force_encoding
(
"BINARY"
)
assert_equal
(
data
,
@column
.
type_cast
(
data
))
end
def
test_type_case_nil
assert_equal
(
nil
,
@column
.
type_cast
(
nil
))
end
def
test_read_value
data
=
"
\u
001F"
@connection
.
execute
"insert into bytea_data_type (payload) VALUES ('
#{
data
}
')"
record
=
ByteaDataType
.
first
assert_equal
(
data
,
record
.
payload
)
record
.
delete
end
def
test_read_nil_value
@connection
.
execute
"insert into bytea_data_type (payload) VALUES (null)"
record
=
ByteaDataType
.
first
assert_equal
(
nil
,
record
.
payload
)
record
.
delete
end
def
test_write_value
data
=
"
\u
001F"
record
=
ByteaDataType
.
create
(
payload:
data
)
refute
record
.
new_record?
assert_equal
(
data
,
record
.
payload
)
end
def
test_write_file
data
=
File
.
read
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
,
'..'
,
'..'
,
'assets'
,
'example.log'
))
assert
(
data
.
size
>
1
)
record
=
ByteaDataType
.
create
(
payload:
data
)
refute
record
.
new_record?
assert_equal
(
data
,
record
.
payload
)
assert_equal
(
data
,
ByteaDataType
.
where
(
id:
record
.
id
).
first
.
payload
)
end
def
test_write_nil
record
=
ByteaDataType
.
create
(
payload:
nil
)
refute
record
.
new_record?
assert_equal
(
nil
,
record
.
payload
)
assert_equal
(
nil
,
ByteaDataType
.
where
(
id:
record
.
id
).
first
.
payload
)
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录