From 0d3cf3333a77ae567f54ac98daca60e2a6ff6a9c Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Tue, 26 Jul 2022 02:13:38 +0200 Subject: [PATCH] DEV: Add secondary sort to `Group.visible_groups` (#17659) Fix a flaky group controller spec and makes the API responses more stable. --- app/models/group.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/group.rb b/app/models/group.rb index c6364dbbfe..f33250410e 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -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")