2012-08-29 01:52:19 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2013-04-10 16:28:42 -04:00
|
|
|
describe Issue, 'Votes' do
|
|
|
|
let(:issue) { create(:issue) }
|
2012-10-29 22:27:36 -04:00
|
|
|
|
2012-09-07 20:30:47 -04:00
|
|
|
describe "#upvotes" do
|
|
|
|
it "with no notes has a 0/0 score" do
|
2013-04-10 16:28:42 -04:00
|
|
|
issue.upvotes.should == 0
|
2012-09-07 20:30:47 -04:00
|
|
|
end
|
2012-08-29 01:52:19 -04:00
|
|
|
|
2012-09-07 20:30:47 -04:00
|
|
|
it "should recognize non-+1 notes" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "No +1 here"
|
|
|
|
issue.should have(1).note
|
|
|
|
issue.notes.first.upvote?.should be_false
|
|
|
|
issue.upvotes.should == 0
|
2012-09-07 20:30:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should recognize a single +1 note" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "+1 This is awesome"
|
|
|
|
issue.upvotes.should == 1
|
2012-09-07 20:30:47 -04:00
|
|
|
end
|
2012-08-29 01:52:19 -04:00
|
|
|
|
2012-09-07 20:30:47 -04:00
|
|
|
it "should recognize multiple +1 notes" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "+1 This is awesome"
|
|
|
|
add_note "+1 I want this"
|
|
|
|
issue.upvotes.should == 2
|
2012-09-07 20:30:47 -04:00
|
|
|
end
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
|
2012-09-07 20:30:47 -04:00
|
|
|
describe "#downvotes" do
|
|
|
|
it "with no notes has a 0/0 score" do
|
2013-04-10 16:28:42 -04:00
|
|
|
issue.downvotes.should == 0
|
2012-09-07 20:30:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should recognize non--1 notes" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "Almost got a -1"
|
|
|
|
issue.should have(1).note
|
|
|
|
issue.notes.first.downvote?.should be_false
|
|
|
|
issue.downvotes.should == 0
|
2012-09-07 20:30:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should recognize a single -1 note" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "-1 This is bad"
|
|
|
|
issue.downvotes.should == 1
|
2012-09-07 20:30:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should recognize multiple -1 notes" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "-1 This is bad"
|
|
|
|
add_note "-1 Away with this"
|
|
|
|
issue.downvotes.should == 2
|
2012-09-07 20:30:47 -04:00
|
|
|
end
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
2012-09-07 20:37:29 -04:00
|
|
|
|
|
|
|
describe "#votes_count" do
|
|
|
|
it "with no notes has a 0/0 score" do
|
2013-04-10 16:28:42 -04:00
|
|
|
issue.votes_count.should == 0
|
2012-09-07 20:37:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should recognize non notes" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "No +1 here"
|
|
|
|
issue.should have(1).note
|
|
|
|
issue.votes_count.should == 0
|
2012-09-07 20:37:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should recognize a single +1 note" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "+1 This is awesome"
|
|
|
|
issue.votes_count.should == 1
|
2012-09-07 20:37:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should recognize a single -1 note" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "-1 This is bad"
|
|
|
|
issue.votes_count.should == 1
|
2012-09-07 20:37:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should recognize multiple notes" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "+1 This is awesome"
|
|
|
|
add_note "-1 This is bad"
|
|
|
|
add_note "+1 I want this"
|
|
|
|
issue.votes_count.should == 3
|
2012-09-07 20:37:29 -04:00
|
|
|
end
|
|
|
|
end
|
2012-09-11 10:47:59 -04:00
|
|
|
|
|
|
|
describe "#upvotes_in_percent" do
|
|
|
|
it "with no notes has a 0% score" do
|
2013-04-10 16:28:42 -04:00
|
|
|
issue.upvotes_in_percent.should == 0
|
2012-09-11 10:47:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should count a single 1 note as 100%" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "+1 This is awesome"
|
|
|
|
issue.upvotes_in_percent.should == 100
|
2012-09-11 10:47:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should count multiple +1 notes as 100%" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "+1 This is awesome"
|
|
|
|
add_note "+1 I want this"
|
|
|
|
issue.upvotes_in_percent.should == 100
|
2012-09-11 10:47:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should count fractions for multiple +1 and -1 notes correctly" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "+1 This is awesome"
|
|
|
|
add_note "+1 I want this"
|
|
|
|
add_note "-1 This is bad"
|
|
|
|
add_note "+1 me too"
|
|
|
|
issue.upvotes_in_percent.should == 75
|
2012-09-11 10:47:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#downvotes_in_percent" do
|
|
|
|
it "with no notes has a 0% score" do
|
2013-04-10 16:28:42 -04:00
|
|
|
issue.downvotes_in_percent.should == 0
|
2012-09-11 10:47:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should count a single -1 note as 100%" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "-1 This is bad"
|
|
|
|
issue.downvotes_in_percent.should == 100
|
2012-09-11 10:47:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should count multiple -1 notes as 100%" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "-1 This is bad"
|
|
|
|
add_note "-1 Away with this"
|
|
|
|
issue.downvotes_in_percent.should == 100
|
2012-09-11 10:47:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should count fractions for multiple +1 and -1 notes correctly" do
|
2013-04-10 16:28:42 -04:00
|
|
|
add_note "+1 This is awesome"
|
|
|
|
add_note "+1 I want this"
|
|
|
|
add_note "-1 This is bad"
|
|
|
|
add_note "+1 me too"
|
|
|
|
issue.downvotes_in_percent.should == 25
|
2012-09-11 10:47:59 -04:00
|
|
|
end
|
|
|
|
end
|
2013-04-10 16:28:42 -04:00
|
|
|
|
|
|
|
def add_note(text)
|
|
|
|
issue.notes << create(:note, note: text, project: issue.project)
|
|
|
|
end
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|