Merge pull request #1409 from riyad/update-votes
Update votes for issues and merge requests
This commit is contained in:
commit
40eec08c99
17 changed files with 256 additions and 66 deletions
|
@ -12,7 +12,7 @@ describe Issue do
|
|||
|
||||
describe 'modules' do
|
||||
it { should include_module(IssueCommonality) }
|
||||
it { should include_module(Upvote) }
|
||||
it { should include_module(Votes) }
|
||||
end
|
||||
|
||||
subject { Factory.create(:issue) }
|
||||
|
|
|
@ -8,6 +8,6 @@ describe MergeRequest do
|
|||
|
||||
describe 'modules' do
|
||||
it { should include_module(IssueCommonality) }
|
||||
it { should include_module(Upvote) }
|
||||
it { should include_module(Votes) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,6 +24,13 @@ describe Note do
|
|||
it "recognizes a neutral note" do
|
||||
note = Factory(:note, note: "This is not a +1 note")
|
||||
note.should_not be_upvote
|
||||
note.should_not be_downvote
|
||||
end
|
||||
|
||||
it "recognizes a neutral emoji note" do
|
||||
note = build(:note, note: "I would :+1: this, but I don't want to")
|
||||
note.should_not be_upvote
|
||||
note.should_not be_downvote
|
||||
end
|
||||
|
||||
it "recognizes a +1 note" do
|
||||
|
@ -31,19 +38,19 @@ describe Note do
|
|||
note.should be_upvote
|
||||
end
|
||||
|
||||
it "recognizes a -1 note as no vote" do
|
||||
note = Factory(:note, note: "-1 for this")
|
||||
note.should_not be_upvote
|
||||
end
|
||||
|
||||
it "recognizes a +1 emoji as a vote" do
|
||||
note = build(:note, note: ":+1: for this")
|
||||
note.should be_upvote
|
||||
end
|
||||
|
||||
it "recognizes a neutral emoji note" do
|
||||
note = build(:note, note: "I would :+1: this, but I don't want to")
|
||||
note.should_not be_upvote
|
||||
it "recognizes a -1 note" do
|
||||
note = Factory(:note, note: "-1 for this")
|
||||
note.should be_downvote
|
||||
end
|
||||
|
||||
it "recognizes a -1 emoji as a vote" do
|
||||
note = build(:note, note: ":-1: for this")
|
||||
note.should be_downvote
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Issue, "Upvote" do
|
||||
let(:issue) { create(:issue) }
|
||||
|
||||
it "with no notes has a 0/0 score" do
|
||||
issue.upvotes.should == 0
|
||||
end
|
||||
|
||||
it "should recognize non-+1 notes" do
|
||||
issue.notes << create(:note, note: "No +1 here")
|
||||
issue.should have(1).note
|
||||
issue.notes.first.upvote?.should be_false
|
||||
issue.upvotes.should == 0
|
||||
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 multiple +1 notes" do
|
||||
issue.notes << create(:note, note: "+1 This is awesome")
|
||||
issue.notes << create(:note, note: "+1 I want this")
|
||||
issue.upvotes.should == 2
|
||||
end
|
||||
end
|
132
spec/roles/votes_spec.rb
Normal file
132
spec/roles/votes_spec.rb
Normal file
|
@ -0,0 +1,132 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Issue do
|
||||
let(:issue) { create(:issue) }
|
||||
|
||||
describe "#upvotes" do
|
||||
it "with no notes has a 0/0 score" do
|
||||
issue.upvotes.should == 0
|
||||
end
|
||||
|
||||
it "should recognize non-+1 notes" do
|
||||
issue.notes << create(:note, note: "No +1 here")
|
||||
issue.should have(1).note
|
||||
issue.notes.first.upvote?.should be_false
|
||||
issue.upvotes.should == 0
|
||||
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 multiple +1 notes" do
|
||||
issue.notes << create(:note, note: "+1 This is awesome")
|
||||
issue.notes << create(:note, note: "+1 I want this")
|
||||
issue.upvotes.should == 2
|
||||
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
|
||||
|
||||
describe "#votes_count" do
|
||||
it "with no notes has a 0/0 score" do
|
||||
issue.votes_count.should == 0
|
||||
end
|
||||
|
||||
it "should recognize non notes" do
|
||||
issue.notes << create(:note, note: "No +1 here")
|
||||
issue.should have(1).note
|
||||
issue.votes_count.should == 0
|
||||
end
|
||||
|
||||
it "should recognize a single +1 note" do
|
||||
issue.notes << create(:note, note: "+1 This is awesome")
|
||||
issue.votes_count.should == 1
|
||||
end
|
||||
|
||||
it "should recognize a single -1 note" do
|
||||
issue.notes << create(:note, note: "-1 This is bad")
|
||||
issue.votes_count.should == 1
|
||||
end
|
||||
|
||||
it "should recognize multiple notes" do
|
||||
issue.notes << create(:note, note: "+1 This is awesome")
|
||||
issue.notes << create(:note, note: "-1 This is bad")
|
||||
issue.notes << create(:note, note: "+1 I want this")
|
||||
issue.votes_count.should == 3
|
||||
end
|
||||
end
|
||||
|
||||
describe "#upvotes_in_percent" do
|
||||
it "with no notes has a 0% score" do
|
||||
issue.upvotes_in_percent.should == 0
|
||||
end
|
||||
|
||||
it "should count a single 1 note as 100%" do
|
||||
issue.notes << create(:note, note: "+1 This is awesome")
|
||||
issue.upvotes_in_percent.should == 100
|
||||
end
|
||||
|
||||
it "should count multiple +1 notes as 100%" do
|
||||
issue.notes << create(:note, note: "+1 This is awesome")
|
||||
issue.notes << create(:note, note: "+1 I want this")
|
||||
issue.upvotes_in_percent.should == 100
|
||||
end
|
||||
|
||||
it "should count fractions for multiple +1 and -1 notes correctly" do
|
||||
issue.notes << create(:note, note: "+1 This is awesome")
|
||||
issue.notes << create(:note, note: "+1 I want this")
|
||||
issue.notes << create(:note, note: "-1 This is bad")
|
||||
issue.notes << create(:note, note: "+1 me too")
|
||||
issue.upvotes_in_percent.should == 75
|
||||
end
|
||||
end
|
||||
|
||||
describe "#downvotes_in_percent" do
|
||||
it "with no notes has a 0% score" do
|
||||
issue.downvotes_in_percent.should == 0
|
||||
end
|
||||
|
||||
it "should count a single -1 note as 100%" do
|
||||
issue.notes << create(:note, note: "-1 This is bad")
|
||||
issue.downvotes_in_percent.should == 100
|
||||
end
|
||||
|
||||
it "should count multiple -1 notes as 100%" do
|
||||
issue.notes << create(:note, note: "-1 This is bad")
|
||||
issue.notes << create(:note, note: "-1 Away with this")
|
||||
issue.downvotes_in_percent.should == 100
|
||||
end
|
||||
|
||||
it "should count fractions for multiple +1 and -1 notes correctly" do
|
||||
issue.notes << create(:note, note: "+1 This is awesome")
|
||||
issue.notes << create(:note, note: "+1 I want this")
|
||||
issue.notes << create(:note, note: "-1 This is bad")
|
||||
issue.notes << create(:note, note: "+1 me too")
|
||||
issue.downvotes_in_percent.should == 25
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue