Skip to content

Commit da90328

Browse files
committed
Test group by and aggregate functions in order clause
Order clauses should allow aggregate functions on queries with group and limit clauses.
1 parent ad5c3dc commit da90328

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/db/mssql/limit_offset_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,24 @@ def test_limit_with_group_by
182182
assert_equal ['three', 'four'], ships.map(&:name)
183183
end if ar_version('3.0')
184184

185+
def test_limit_with_group_by_and_aggregate_in_order_clause
186+
%w( one two three four five six seven eight ).each_with_index do |name, i|
187+
LongShip.create!(:name => name, :width => (i+1)*10)
188+
end
189+
190+
ships = LongShip.select(:name).group(:name).limit(2).order('width').all
191+
assert_equal ['one', 'two'], ships.map(&:name)
192+
193+
ships = LongShip.select(:name).group(:name).limit(2).order('width DESC').all
194+
assert_equal ['eight', 'seven'], ships.map(&:name)
195+
196+
ships = LongShip.select(:name).group(:name).limit(2).order('MAX(width)').all
197+
assert_equal ['one', 'two'], ships.map(&:name)
198+
199+
ships = LongShip.select(:name).group(:name).limit(2).order('MAX(width) DESC').all
200+
assert_equal ['eight', 'seven'], ships.map(&:name)
201+
end if ar_version('3.0')
202+
185203
def test_select_distinct_with_limit
186204
%w(c a b a b a c d c d).each do |name|
187205
LongShip.create!(:name => name)

0 commit comments

Comments
 (0)