提交 0bee4100 编写于 作者: S Sean Griffin

Merge pull request #20677 from jmondo/decimal-default-string

Display decimal defaults as strings to keep precision
......@@ -8,7 +8,7 @@ def type
end
def type_cast_for_schema(value)
value.to_s
value.to_s.inspect
end
private
......
......@@ -56,7 +56,7 @@ def test_money_type_cast
def test_schema_dumping
output = dump_table_schema("postgresql_moneys")
assert_match %r{t\.money\s+"wealth",\s+scale: 2$}, output
assert_match %r{t\.money\s+"depth",\s+scale: 2,\s+default: 150\.55$}, output
assert_match %r{t\.money\s+"depth",\s+scale: 2,\s+default: "150\.55"$}, output
end
def test_create_and_update_money
......
......@@ -480,6 +480,7 @@ class DefaultsUsingMultipleSchemasAndDomainTest < ActiveRecord::PostgreSQLTestCa
@connection.create_table "defaults" do |t|
t.text "text_col", default: "some value"
t.string "string_col", default: "some value"
t.decimal "decimal_col", default: "3.14159265358979323846"
end
Default.reset_column_information
end
......@@ -498,6 +499,10 @@ def test_string_defaults_in_new_schema_when_overriding_domain
assert_equal "some value", Default.new.string_col, "Default of string column was not correctly parsed"
end
def test_decimal_defaults_in_new_schema_when_overriding_domain
assert_equal BigDecimal.new("3.14159265358979323846"), Default.new.decimal_col, "Default of decimal column was not correctly parsed"
end
def test_bpchar_defaults_in_new_schema_when_overriding_domain
@connection.execute "ALTER TABLE defaults ADD bpchar_col bpchar DEFAULT 'some value'"
Default.reset_column_information
......
......@@ -239,7 +239,7 @@ def test_schema_dumps_index_type
def test_schema_dump_includes_decimal_options
output = dump_all_table_schema([/^[^n]/])
assert_match %r{precision: 3,[[:space:]]+scale: 2,[[:space:]]+default: 2\.78}, output
assert_match %r{precision: 3,[[:space:]]+scale: 2,[[:space:]]+default: "2\.78"}, output
end
if current_adapter?(:PostgreSQLAdapter)
......@@ -255,7 +255,7 @@ def test_schema_dump_includes_limit_on_array_type
def test_schema_dump_allows_array_of_decimal_defaults
output = standard_dump
assert_match %r{t\.decimal\s+"decimal_array_default",\s+default: \[1.23, 3.45\],\s+array: true}, output
assert_match %r{t\.decimal\s+"decimal_array_default",\s+default: \["1.23", "3.45"\],\s+array: true}, output
end
if ActiveRecord::Base.connection.supports_extensions?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册