Commit 2e0d5c2250ad34273a0ad6e207f2717b9a98bd86

Authored by Riyad Preukschas
1 parent a2a00600

Add downvotes

Showing 2 changed files with 48 additions and 17 deletions   Show diff stats
app/roles/votes.rb
@@ -3,4 +3,9 @@ module Votes @@ -3,4 +3,9 @@ module Votes
3 def upvotes 3 def upvotes
4 notes.select(&:upvote?).size 4 notes.select(&:upvote?).size
5 end 5 end
  6 +
  7 + # Return the number of -1 comments (downvotes)
  8 + def downvotes
  9 + notes.select(&:downvote?).size
  10 + end
6 end 11 end
spec/roles/votes_spec.rb
1 require 'spec_helper' 1 require 'spec_helper'
2 2
3 -describe Issue, "Upvote" do 3 +describe Issue do
4 let(:issue) { create(:issue) } 4 let(:issue) { create(:issue) }
5 5
6 - it "with no notes has a 0/0 score" do  
7 - issue.upvotes.should == 0  
8 - end 6 + describe "#upvotes" do
  7 + it "with no notes has a 0/0 score" do
  8 + issue.upvotes.should == 0
  9 + end
9 10
10 - it "should recognize non-+1 notes" do  
11 - issue.notes << create(:note, note: "No +1 here")  
12 - issue.should have(1).note  
13 - issue.notes.first.upvote?.should be_false  
14 - issue.upvotes.should == 0  
15 - end 11 + it "should recognize non-+1 notes" do
  12 + issue.notes << create(:note, note: "No +1 here")
  13 + issue.should have(1).note
  14 + issue.notes.first.upvote?.should be_false
  15 + issue.upvotes.should == 0
  16 + end
  17 +
  18 + it "should recognize a single +1 note" do
  19 + issue.notes << create(:note, note: "+1 This is awesome")
  20 + issue.upvotes.should == 1
  21 + end
16 22
17 - it "should recognize a single +1 note" do  
18 - issue.notes << create(:note, note: "+1 This is awesome")  
19 - issue.upvotes.should == 1 23 + it "should recognize multiple +1 notes" do
  24 + issue.notes << create(:note, note: "+1 This is awesome")
  25 + issue.notes << create(:note, note: "+1 I want this")
  26 + issue.upvotes.should == 2
  27 + end
20 end 28 end
21 29
22 - it "should recognize multiple +1 notes" do  
23 - issue.notes << create(:note, note: "+1 This is awesome")  
24 - issue.notes << create(:note, note: "+1 I want this")  
25 - issue.upvotes.should == 2 30 + describe "#downvotes" do
  31 + it "with no notes has a 0/0 score" do
  32 + issue.downvotes.should == 0
  33 + end
  34 +
  35 + it "should recognize non--1 notes" do
  36 + issue.notes << create(:note, note: "Almost got a -1")
  37 + issue.should have(1).note
  38 + issue.notes.first.downvote?.should be_false
  39 + issue.downvotes.should == 0
  40 + end
  41 +
  42 + it "should recognize a single -1 note" do
  43 + issue.notes << create(:note, note: "-1 This is bad")
  44 + issue.downvotes.should == 1
  45 + end
  46 +
  47 + it "should recognize multiple -1 notes" do
  48 + issue.notes << create(:note, note: "-1 This is bad")
  49 + issue.notes << create(:note, note: "-1 Away with this")
  50 + issue.downvotes.should == 2
  51 + end
26 end 52 end
27 end 53 end