1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fixed columns_for_distinct of postgresql adapter

This commit is contained in:
Nikolay Kondratyev 2013-08-14 17:44:14 +06:00
parent e90f0e0eb6
commit 1cb52a1733
3 changed files with 17 additions and 1 deletions

View file

@ -1,3 +1,8 @@
* Fixed `columns_for_distinct` of postgresql adapter to work correctly
with orders without sort direction modifiers.
*Nikolay Kondratyev*
* Assign inet/cidr attribute with `nil` value for invalid address.
Example:

View file

@ -475,7 +475,7 @@ module ActiveRecord
# Convert Arel node to string
s = s.to_sql unless s.is_a?(String)
# Remove any ASC/DESC modifiers
s.gsub(/\s+(ASC|DESC)\s*(NULLS\s+(FIRST|LAST)\s*)?/i, '')
s.gsub(/\s+(?:ASC|DESC)?\s*(?:NULLS\s+(?:FIRST|LAST)\s*)?/i, '')
}.reject(&:blank?).map.with_index { |column, i| "#{column} AS alias_#{i}" }
[super, *order_columns].join(', ')

View file

@ -259,6 +259,17 @@ module ActiveRecord
assert_equal "posts.title, posts.updater_id AS alias_0", @connection.columns_for_distinct("posts.title", ["posts.updater_id desc nulls last"])
end
def test_columns_for_distinct_without_order_specifiers
assert_equal "posts.title, posts.updater_id AS alias_0",
@connection.columns_for_distinct("posts.title", ["posts.updater_id"])
assert_equal "posts.title, posts.updater_id AS alias_0",
@connection.columns_for_distinct("posts.title", ["posts.updater_id nulls last"])
assert_equal "posts.title, posts.updater_id AS alias_0",
@connection.columns_for_distinct("posts.title", ["posts.updater_id nulls first"])
end
def test_raise_error_when_cannot_translate_exception
assert_raise TypeError do
@connection.send(:log, nil) { @connection.execute(nil) }