Commit 2e0d5c22 authored by Riyad Preukschas's avatar Riyad Preukschas

Add downvotes

parent a2a00600
...@@ -3,4 +3,9 @@ module Votes ...@@ -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
require 'spec_helper' require 'spec_helper'
describe Issue, "Upvote" do describe Issue do
let(:issue) { create(:issue) } let(:issue) { create(:issue) }
it "with no notes has a 0/0 score" do describe "#upvotes" do
issue.upvotes.should == 0 it "with no notes has a 0/0 score" do
end issue.upvotes.should == 0
end
it "should recognize non-+1 notes" do it "should recognize non-+1 notes" do
issue.notes << create(:note, note: "No +1 here") issue.notes << create(:note, note: "No +1 here")
issue.should have(1).note issue.should have(1).note
issue.notes.first.upvote?.should be_false issue.notes.first.upvote?.should be_false
issue.upvotes.should == 0 issue.upvotes.should == 0
end end
it "should recognize a single +1 note" do
issue.notes << create(:note, note: "+1 This is awesome")
issue.upvotes.should == 1
end
it "should recognize a single +1 note" do it "should recognize multiple +1 notes" do
issue.notes << create(:note, note: "+1 This is awesome") issue.notes << create(:note, note: "+1 This is awesome")
issue.upvotes.should == 1 issue.notes << create(:note, note: "+1 I want this")
issue.upvotes.should == 2
end
end end
it "should recognize multiple +1 notes" do describe "#downvotes" do
issue.notes << create(:note, note: "+1 This is awesome") it "with no notes has a 0/0 score" do
issue.notes << create(:note, note: "+1 I want this") issue.downvotes.should == 0
issue.upvotes.should == 2 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
end 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