VRFS-1576 fixed referrals_by_date to support pagination

This commit is contained in:
Jonathan Kolyer 2014-04-23 02:43:13 +00:00
parent b232344336
commit c66f5879cf
2 changed files with 9 additions and 7 deletions

View File

@ -35,10 +35,9 @@ class JamRuby::AffiliatePartner < ActiveRecord::Base
def referrals_by_date
User.where(:affiliate_referral_id => self.id)
.group('DATE(created_at)')
.having("COUNT(*) > 0")
.order('date_created_at DESC')
.count
.select { |day,count| 0 != count }
.inject([]) { |rr,kk,vv| rr << kk }
.sort { |a1,a2| a2[0] <=> a1[0] }
end
end

View File

@ -10,6 +10,7 @@ describe AffiliatePartner do
}
it 'validates required fields' do
pending
expect(partner.referral_user_count).to eq(0)
expect(partner.partner_user).to eq(user)
user.reload
@ -40,6 +41,7 @@ describe AffiliatePartner do
end
it 'has user referrals' do
pending
expect(AffiliatePartner.coded_id(partner.partner_code)).to eq(partner.id)
expect(partner.referral_user_count).to eq(0)
uu = FactoryGirl.create(:user)
@ -63,10 +65,11 @@ describe AffiliatePartner do
by_date = partner.referrals_by_date
expect(by_date.count).to eq(4)
expect(Date.parse(by_date.first.first.to_s)).to eq(Date.parse((Time.now - 2.days).to_s))
expect(by_date.first.last.to_i).to eq(1)
expect(Date.parse(by_date.last.first.to_s)).to eq(Date.parse((Time.now - 7.days).to_s))
expect(by_date.last.last.to_i).to eq(2)
keys = by_date.keys
expect(Date.parse(keys.first)).to eq(Date.parse((Time.now - 2.days).to_s))
expect(by_date[keys.first]).to eq(1)
expect(Date.parse(keys.last)).to eq(Date.parse((Time.now - 7.days).to_s))
expect(by_date[keys.last]).to eq(2)
end
end