Add downvotes

This commit is contained in:
Riyad Preukschas 2012-09-08 02:30:47 +02:00
parent a2a0060034
commit 2e0d5c2250
2 changed files with 48 additions and 17 deletions

View file

@ -3,4 +3,9 @@ module Votes
def upvotes def upvotes
notes.select(&:upvote?).size notes.select(&:upvote?).size
end end
# Return the number of -1 comments (downvotes)
def downvotes
notes.select(&:downvote?).size
end
end end

View file

@ -1,8 +1,9 @@
require 'spec_helper' require 'spec_helper'
describe Issue, "Upvote" do describe Issue do
let(:issue) { create(:issue) } let(:issue) { create(:issue) }
describe "#upvotes" do
it "with no notes has a 0/0 score" do it "with no notes has a 0/0 score" do
issue.upvotes.should == 0 issue.upvotes.should == 0
end end
@ -25,3 +26,28 @@ describe Issue, "Upvote" do
issue.upvotes.should == 2 issue.upvotes.should == 2
end end
end end
describe "#downvotes" do
it "with no notes has a 0/0 score" do
issue.downvotes.should == 0
end
it "should recognize non--1 notes" do
issue.notes << create(:note, note: "Almost got a -1")
issue.should have(1).note
issue.notes.first.downvote?.should be_false
issue.downvotes.should == 0
end
it "should recognize a single -1 note" do
issue.notes << create(:note, note: "-1 This is bad")
issue.downvotes.should == 1
end
it "should recognize multiple -1 notes" do
issue.notes << create(:note, note: "-1 This is bad")
issue.notes << create(:note, note: "-1 Away with this")
issue.downvotes.should == 2
end
end
end