From 4be8f17e66d95e786edd91cdade334ff5da8ee04 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Tue, 14 Nov 2017 11:38:54 +0100 Subject: [PATCH] FIX: counting invites didn't work PostgreSQL reported the following error: "for SELECT DISTINCT, ORDER BY expressions must appear in select list" --- app/models/invite.rb | 4 ++-- spec/models/invite_spec.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/invite.rb b/app/models/invite.rb index 8f9cf8ebd99..984e3cb1808 100644 --- a/app/models/invite.rb +++ b/app/models/invite.rb @@ -183,11 +183,11 @@ class Invite < ActiveRecord::Base end def self.find_pending_invites_count(inviter) - find_all_invites_from(inviter, 0, nil).where('invites.user_id IS NULL').count + find_all_invites_from(inviter, 0, nil).where('invites.user_id IS NULL').reorder(nil).count end def self.find_redeemed_invites_count(inviter) - find_all_invites_from(inviter, 0, nil).where('invites.user_id IS NOT NULL').count + find_all_invites_from(inviter, 0, nil).where('invites.user_id IS NOT NULL').reorder(nil).count end def self.filter_by(email_or_username) diff --git a/spec/models/invite_spec.rb b/spec/models/invite_spec.rb index b36afc144d7..552a953194f 100644 --- a/spec/models/invite_spec.rb +++ b/spec/models/invite_spec.rb @@ -402,6 +402,8 @@ describe Invite do expect(invites.length).to eq(1) expect(invites.first).to eq pending_invite + + expect(Invite.find_pending_invites_count(inviter)).to eq(1) end end @@ -426,6 +428,8 @@ describe Invite do expect(invites.length).to eq(1) expect(invites.first).to eq redeemed_invite + + expect(Invite.find_redeemed_invites_count(inviter)).to eq(1) end end