Skip to content
Browse files

subtract remainder of score at end

  • Loading branch information...
1 parent 63197e3 commit dd2ef31d5a4265a01572993979beafcbfc7cba65 @ryanb committed
Showing with 11 additions and 6 deletions.
  1. +4 −5 app/models/score_tracker.rb
  2. +6 −0 spec/models/score_tracker_spec.rb
  3. +1 −1 spec/models/stamp_spec.rb
View
9 app/models/score_tracker.rb
@@ -32,12 +32,11 @@ def miss
@position = 0
end
@position += 1
- @score -= @negative_points
- if @score < 0
+ if @score < @negative_points
@position = 0
- @score = 0
- else
- -@negative_points
+ @negative_points = @score
end
+ @score -= @negative_points
+ -@negative_points
end
end
View
6 spec/models/score_tracker_spec.rb
@@ -51,4 +51,10 @@
tracker = ScoreTracker.new(:score => 123)
tracker.score.should == 123
end
+
+ it "should remove remaining points from score (don't go past zero)" do
+ tracker = ScoreTracker.new(:score => 1, :negative_points => 3)
+ tracker.miss.should == -1
+ tracker.score.should == 0
+ end
end
View
2 spec/models/stamp_spec.rb
@@ -20,7 +20,7 @@
["2009-04-01", "2009-04-02", "2009-04-03", "2009-04-04", "2009-04-07"].each do |date|
@stamp.marks.create!(:marked_on => date)
end
- @stamp.month_points(Date.new(2009, 4, 3)).should == [1, 2, 2, 3, -1, -2, 2, -1, -2, -2] + [0]*20
+ @stamp.month_points(Date.new(2009, 4, 3)).should == [1, 2, 2, 3, -1, -2, 2, -1, -2, -2, -2] + [0]*19
end
it "should apply score to previous month" do

0 comments on commit dd2ef31

Please sign in to comment.
Something went wrong with that request. Please try again.