Commit d6da8546 authored by Kim Meiser's avatar Kim Meiser

Ein Storno wird in der Berechnung der all_redeemed_points berücksichtigt

parent ba178558
......@@ -16,19 +16,20 @@ class Hacker < ActiveRecord::Base
# Summe aller jemals eingelösten Punkte
def all_redeemed_points
return Redemption.sum('points')
return redemptions.where("id not in (select subject_id from cancels where subject_type = 'Redemption')").sum('points')
end
# Summe aller in den letzten 90 Tagen verdienten Punkte
def recent_earned_points
return Reward.where('created_at >= ?', Date.today - 90).sum('points')
return earnings.where("id not in (select subject_id from cancels where subject_type = 'Earning')").
where('created_at >= ?', Date.today - 90).sum('points')
end
# Summe aller jemals verdienten Punkte,
# unabhängig davon, ob diese bereits
# eingelöst wurden oder nicht
def all_earned_points
return Reward.sum('points')
return earnings.sum('points')
end
# Verbleibendes Guthaben, d.h. alle jemals verdienten Punkte
......
FactoryGirl.define do
factory :cancel do
association :hacker, :factory => :hacker
association :user, :factory => :hacker
end
end
......@@ -2,4 +2,50 @@ require 'spec_helper'
describe Hacker do
pending "add some examples to (or delete) #{__FILE__}"
let(:hacker) do
FactoryGirl.create(:hacker)
end
let(:redemptions) do
[FactoryGirl.create(:redemption, {
:hacker => hacker, :points => 10
}),
FactoryGirl.create(:redemption, {
:hacker => hacker, :points => 10
})]
end
let (:cancel) do
FactoryGirl.create(:cancel, {
:hacker => hacker, :subject => redemptions[0]
})
end
describe '#all_redeemed_points' do
before do
redemptions
end
it 'should sum all redemptions' do
hacker.all_redeemed_points.should be(20)
end
context '#with cancel' do
before do
cancel
end
it 'should sum all redemptions without cancels' do
hacker.all_redeemed_points.should be (10)
end
end
end
describe '#recent_earned_points'
describe '#all_earned_points'
# remaining_points
#it all_redeemed_points
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment