From e8e764c0645476d921eb56d922dd93de128883c2 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Fri, 17 Apr 2020 09:04:10 +1000 Subject: [PATCH] FIX: flaky groups_controller_spec (#9439) Sometimes spec which is testing order groups by user count is failing. My theory is that cause is the randomness of Postgres when the order value is the same for 2 rows. In spec, we got three groups `moderator_group` - 0 users `group` - 1 user `other_group` - 1 user And we are expecting that controller will return them in ascending order [moderator, group, other_group] Because `group` and `other_group` contain the same amount of users, we are dealing with luck Therefore, I believe that adding one more user to other_group should make that query reliable. It was not crashing on my local machine, so I am not 100% sure. --- spec/requests/groups_controller_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/requests/groups_controller_spec.rb b/spec/requests/groups_controller_spec.rb index 381e247e422..0f1027edf3d 100644 --- a/spec/requests/groups_controller_spec.rb +++ b/spec/requests/groups_controller_spec.rb @@ -4,6 +4,7 @@ require 'rails_helper' describe GroupsController do fab!(:user) { Fabricate(:user) } + let(:other_user) { Fabricate(:user) } let(:group) { Fabricate(:group, users: [user]) } let(:moderator_group_id) { Group::AUTO_GROUPS[:moderators] } fab!(:admin) { Fabricate(:admin) } @@ -91,7 +92,7 @@ describe GroupsController do sign_in(user) end - let!(:other_group) { Fabricate(:group, name: "other_group", users: [user]) } + let!(:other_group) { Fabricate(:group, name: "other_group", users: [user, other_user]) } context "with default (descending) order" do it "sorts by name" do @@ -116,7 +117,7 @@ describe GroupsController do body = JSON.parse(response.body) expect(body["groups"].map { |g| g["id"] }).to eq([ - group.id, other_group.id, moderator_group_id + other_group.id, group.id, moderator_group_id ]) expect(body["load_more_groups"]).to eq("/groups?order=user_count&page=1")