add user id to user sort clause
so we still have a deterministic sort for pagination when multiple users have the same sortable name fixes CNVS-36604 Change-Id: I75b5eaae782553a80a185660ddb4346dbe79f853 Reviewed-on: https://gerrit.instructure.com/110288 Tested-by: Jenkins Reviewed-by: James Williams <jamesw@instructure.com> QA-Review: Deepeeca Soundarrajan <dsoundarrajan@instructure.com> Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
parent
f30fef4ccf
commit
0b597e75c7
|
@ -240,6 +240,7 @@ class User < ActiveRecord::Base
|
|||
def self.order_by_sortable_name(options = {})
|
||||
order_clause = clause = sortable_name_order_by_clause
|
||||
order_clause = "#{clause} DESC" if options[:direction] == :descending
|
||||
order_clause += ",users.id"
|
||||
scope = self.order(order_clause)
|
||||
if scope.select_values.empty?
|
||||
scope = scope.select(self.arel_table[Arel.star])
|
||||
|
|
|
@ -2123,6 +2123,11 @@ describe User do
|
|||
expect(User.sortable_name_order_by_clause).not_to match(/'es'/)
|
||||
expect(User.sortable_name_order_by_clause).to match(/'root'/)
|
||||
end
|
||||
|
||||
it "breaks ties with user id" do
|
||||
ids = 5.times.map { User.create!(:name => "Abcde").id }.sort
|
||||
expect(User.order_by_sortable_name.where(id: ids).map(&:id)).to eq(ids)
|
||||
end
|
||||
end
|
||||
|
||||
describe "quota" do
|
||||
|
|
Loading…
Reference in New Issue