提交 563c16c7 编写于 作者: R Ryuta Kamizono

Add JSON attribute test cases for SQLite3 adapter

上级 214dc7d8
......@@ -478,6 +478,8 @@ def initialize_type_map(m = type_map)
m.alias_type %r(number)i, "decimal"
m.alias_type %r(double)i, "float"
m.register_type %r(^json)i, Type::Json.new
m.register_type(%r(decimal)i) do |sql_type|
scale = extract_scale(sql_type)
precision = extract_precision(sql_type)
......
......@@ -563,7 +563,6 @@ def initialize_type_map(m = type_map)
m.register_type %r(longblob)i, Type::Binary.new(limit: 2**32 - 1)
m.register_type %r(^float)i, Type::Float.new(limit: 24)
m.register_type %r(^double)i, Type::Float.new(limit: 53)
m.register_type %r(^json)i, Type::Json.new
register_integer_type m, %r(^bigint)i, limit: 8
register_integer_type m, %r(^int)i, limit: 4
......
# frozen_string_literal: true
require "cases/helper"
require "cases/json_shared_test_cases"
class SQLite3JSONTest < ActiveRecord::SQLite3TestCase
include JSONSharedTestCases
def setup
super
@connection.create_table("json_data_type") do |t|
t.column "payload", :json, default: {}
t.column "settings", :json
end
end
def test_default
@connection.add_column "json_data_type", "permissions", column_type, default: { "users": "read", "posts": ["read", "write"] }
klass.reset_column_information
assert_equal({ "users" => "read", "posts" => ["read", "write"] }, klass.column_defaults["permissions"])
assert_equal({ "users" => "read", "posts" => ["read", "write"] }, klass.new.permissions)
end
private
def column_type
:json
end
end
......@@ -30,6 +30,7 @@ def test_column
end
def test_change_table_supports_json
skip unless @connection.supports_json?
@connection.change_table("json_data_type") do |t|
t.public_send column_type, "users"
end
......@@ -40,6 +41,7 @@ def test_change_table_supports_json
end
def test_schema_dumping
skip unless @connection.supports_json?
output = dump_table_schema("json_data_type")
assert_match(/t\.#{column_type}\s+"settings"/, output)
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册