提交 a0d17760 编写于 作者: R Ryuta Kamizono

Fix UUID column with `null: true` and `default: nil`

`quote_default_expression` can be passed nil value when `null: true` and
`default: nil`. This addressed in that case.

Fixes #29222.
上级 0a9522a8
......@@ -62,7 +62,7 @@ def quoted_binary(value) # :nodoc:
def quote_default_expression(value, column) # :nodoc:
if value.is_a?(Proc)
value.call
elsif column.type == :uuid && value.include?("()")
elsif column.type == :uuid && /\(\)/.match?(value)
value # Does not quote function default values for UUID columns
elsif column.respond_to?(:array?)
value = type_cast_from_column(column, value)
......
......@@ -63,6 +63,16 @@ def test_change_column_default
UUIDType.reset_column_information
end
def test_add_column_with_null_true_and_default_nil
assert_nothing_raised do
connection.add_column :uuid_data_type, :thingy, :uuid, null: true, default: nil
end
UUIDType.reset_column_information
column = UUIDType.columns_hash["thingy"]
assert column.null
assert_nil column.default
end
def test_data_type_of_uuid_types
column = UUIDType.columns_hash["guid"]
assert_equal :uuid, column.type
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册