Skip to content

Commit

Permalink
Fix UUID column with null: true and default: nil
Browse files Browse the repository at this point in the history
`quote_default_expression` can be passed nil value when `null: true` and
`default: nil`. This addressed in that case.

Fixes #29222.
  • Loading branch information
kamipo committed May 29, 2017
1 parent 0a9522a commit a0d1776
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Expand Up @@ -62,7 +62,7 @@ def quoted_binary(value) # :nodoc:
def quote_default_expression(value, column) # :nodoc: def quote_default_expression(value, column) # :nodoc:
if value.is_a?(Proc) if value.is_a?(Proc)
value.call value.call
elsif column.type == :uuid && value.include?("()") elsif column.type == :uuid && /\(\)/.match?(value)
value # Does not quote function default values for UUID columns value # Does not quote function default values for UUID columns
elsif column.respond_to?(:array?) elsif column.respond_to?(:array?)
value = type_cast_from_column(column, value) value = type_cast_from_column(column, value)
Expand Down
10 changes: 10 additions & 0 deletions activerecord/test/cases/adapters/postgresql/uuid_test.rb
Expand Up @@ -63,6 +63,16 @@ def test_change_column_default
UUIDType.reset_column_information UUIDType.reset_column_information
end 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 def test_data_type_of_uuid_types
column = UUIDType.columns_hash["guid"] column = UUIDType.columns_hash["guid"]
assert_equal :uuid, column.type assert_equal :uuid, column.type
Expand Down

0 comments on commit a0d1776

Please sign in to comment.