DEV: Add secondary sort to `Group.visible_groups` (#17659)

Fix a flaky group controller spec and makes the API responses more stable.
This commit is contained in:
Jarek Radosz 2022-07-26 02:13:38 +02:00 committed by GitHub
parent 23a267c75d
commit 0d3cf3333a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -150,7 +150,9 @@ class Group < ActiveRecord::Base
scope :with_smtp_configured, -> { where(smtp_enabled: true) }
scope :visible_groups, Proc.new { |user, order, opts|
groups = self.order(order || "groups.name ASC")
groups = self
groups = groups.order(order) if order
groups = groups.order("groups.name ASC") unless order&.include?("name")
if !opts || !opts[:include_everyone]
groups = groups.where("groups.id > 0")