Skip to content

Commit

Permalink
Fix quote_default_expression for UUID with array default
Browse files Browse the repository at this point in the history
Fixes #30539.
  • Loading branch information
kamipo committed Sep 7, 2017
1 parent 0b31bed commit a4b73f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Expand Up @@ -64,7 +64,7 @@ def quoted_binary(value) # :nodoc:
def quote_default_expression(value, column) # :nodoc:
if value.is_a?(Proc)
value.call
elsif column.type == :uuid && /\(\)/.match?(value)
elsif column.type == :uuid && value.is_a?(String) && /\(\)/.match?(value)
value # Does not quote function default values for UUID columns
elsif column.respond_to?(:array?)
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 @@ -76,6 +76,16 @@ def test_add_column_with_null_true_and_default_nil
assert_nil column.default
end

def test_add_column_with_default_array
connection.add_column :uuid_data_type, :thingy, :uuid, array: true, default: []

UUIDType.reset_column_information
column = UUIDType.columns_hash["thingy"]

assert column.array?
assert [], column.default
end

def test_data_type_of_uuid_types
column = UUIDType.columns_hash["guid"]
assert_equal :uuid, column.type
Expand Down

2 comments on commit a4b73f8

@cdesch
Copy link

@cdesch cdesch commented on a4b73f8 Jan 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamipo Any chance this can be pulled into the Rails 5.1.x ? .....5.1.5

@rafaelfranca
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already in the 5-1-stable branch 90dd63a#diff-4b40a34b5dacebf9464c049adda25c4e

Please sign in to comment.