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
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.upvotes).to eq(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"
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.notes.size).to eq(1)
|
|
|
|
expect(issue.notes.first.upvote?).to be_falsey
|
|
|
|
expect(issue.upvotes).to eq(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"
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.upvotes).to eq(1)
|
2012-09-07 20:30:47 -04:00
|
|
|
end
|
2012-08-29 01:52:19 -04:00
|
|
|
|
2014-11-05 15:45:18 -05:00
|
|
|
it 'should recognize multiple +1 notes' do
|
|
|
|
add_note '+1 This is awesome', create(:user)
|
|
|
|
add_note '+1 I want this', create(:user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.upvotes).to eq(2)
|
2012-09-07 20:30:47 -04:00
|
|
|
end
|
2014-11-05 15:45:18 -05:00
|
|
|
|
|
|
|
it 'should not count 2 +1 votes from the same user' do
|
|
|
|
add_note '+1 This is awesome'
|
|
|
|
add_note '+1 I want this'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.upvotes).to eq(1)
|
2014-11-05 15:45:18 -05: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
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.downvotes).to eq(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"
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.notes.size).to eq(1)
|
|
|
|
expect(issue.notes.first.downvote?).to be_falsey
|
|
|
|
expect(issue.downvotes).to eq(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"
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.downvotes).to eq(1)
|
2012-09-07 20:30:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should recognize multiple -1 notes" do
|
2014-11-05 15:45:18 -05:00
|
|
|
add_note('-1 This is bad', create(:user))
|
|
|
|
add_note('-1 Away with this', create(:user))
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.downvotes).to eq(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
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.votes_count).to eq(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"
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.notes.size).to eq(1)
|
|
|
|
expect(issue.votes_count).to eq(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"
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.votes_count).to eq(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"
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.votes_count).to eq(1)
|
2012-09-07 20:37:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should recognize multiple notes" do
|
2014-11-05 15:45:18 -05:00
|
|
|
add_note('+1 This is awesome', create(:user))
|
|
|
|
add_note('-1 This is bad', create(:user))
|
|
|
|
add_note('+1 I want this', create(:user))
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.votes_count).to eq(3)
|
2012-09-07 20:37:29 -04:00
|
|
|
end
|
2014-11-05 15:45:18 -05:00
|
|
|
|
|
|
|
it 'should not count 2 -1 votes from the same user' do
|
|
|
|
add_note '-1 This is suspicious'
|
|
|
|
add_note '-1 This is bad'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.votes_count).to eq(1)
|
2014-11-05 15:45:18 -05:00
|
|
|
end
|
2012-09-07 20:37:29 -04:00
|
|
|
end
|
2012-09-11 10:47:59 -04:00
|
|
|
|
|
|
|
describe "#upvotes_in_percent" do
|
|
|
|
it "with no notes has a 0% score" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.upvotes_in_percent).to eq(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"
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.upvotes_in_percent).to eq(100)
|
2012-09-11 10:47:59 -04:00
|
|
|
end
|
|
|
|
|
2014-11-05 15:45:18 -05:00
|
|
|
it 'should count multiple +1 notes as 100%' do
|
|
|
|
add_note('+1 This is awesome', create(:user))
|
|
|
|
add_note('+1 I want this', create(:user))
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.upvotes_in_percent).to eq(100)
|
2012-09-11 10:47:59 -04:00
|
|
|
end
|
|
|
|
|
2014-11-05 15:45:18 -05:00
|
|
|
it 'should count fractions for multiple +1 and -1 notes correctly' do
|
|
|
|
add_note('+1 This is awesome', create(:user))
|
|
|
|
add_note('+1 I want this', create(:user))
|
|
|
|
add_note('-1 This is bad', create(:user))
|
|
|
|
add_note('+1 me too', create(:user))
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.upvotes_in_percent).to eq(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
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.downvotes_in_percent).to eq(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"
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.downvotes_in_percent).to eq(100)
|
2012-09-11 10:47:59 -04:00
|
|
|
end
|
|
|
|
|
2014-11-05 15:45:18 -05:00
|
|
|
it 'should count multiple -1 notes as 100%' do
|
|
|
|
add_note('-1 This is bad', create(:user))
|
|
|
|
add_note('-1 Away with this', create(:user))
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.downvotes_in_percent).to eq(100)
|
2012-09-11 10:47:59 -04:00
|
|
|
end
|
|
|
|
|
2014-11-05 15:45:18 -05:00
|
|
|
it 'should count fractions for multiple +1 and -1 notes correctly' do
|
|
|
|
add_note('+1 This is awesome', create(:user))
|
|
|
|
add_note('+1 I want this', create(:user))
|
|
|
|
add_note('-1 This is bad', create(:user))
|
|
|
|
add_note('+1 me too', create(:user))
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.downvotes_in_percent).to eq(25)
|
2012-09-11 10:47:59 -04:00
|
|
|
end
|
|
|
|
end
|
2013-04-10 16:28:42 -04:00
|
|
|
|
2014-11-05 15:45:18 -05:00
|
|
|
describe '#filter_superceded_votes' do
|
|
|
|
|
|
|
|
it 'should count a users vote only once amongst multiple votes' do
|
|
|
|
add_note('-1 This needs work before I will accept it')
|
|
|
|
add_note('+1 I want this', create(:user))
|
|
|
|
add_note('+1 This is is awesome', create(:user))
|
|
|
|
add_note('+1 this looks good now')
|
|
|
|
add_note('+1 This is awesome', create(:user))
|
|
|
|
add_note('+1 me too', create(:user))
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.downvotes).to eq(0)
|
|
|
|
expect(issue.upvotes).to eq(5)
|
2014-11-05 15:45:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should count each users vote only once' do
|
|
|
|
add_note '-1 This needs work before it will be accepted'
|
|
|
|
add_note '+1 I like this'
|
|
|
|
add_note '+1 I still like this'
|
|
|
|
add_note '+1 I really like this'
|
|
|
|
add_note '+1 Give me this now!!!!'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.downvotes).to eq(0)
|
|
|
|
expect(issue.upvotes).to eq(1)
|
2014-11-05 15:45:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should count a users vote only once without caring about comments' do
|
|
|
|
add_note '-1 This needs work before it will be accepted'
|
|
|
|
add_note 'Comment 1'
|
|
|
|
add_note 'Another comment'
|
|
|
|
add_note '+1 vote'
|
|
|
|
add_note 'final comment'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.downvotes).to eq(0)
|
|
|
|
expect(issue.upvotes).to eq(1)
|
2014-11-05 15:45:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_note(text, author = issue.author)
|
2015-01-22 15:08:47 -05:00
|
|
|
created_at = Time.now - 1.hour + Note.count.seconds
|
2014-11-05 15:45:18 -05:00
|
|
|
issue.notes << create(:note, note: text, project: issue.project,
|
2015-01-22 15:08:47 -05:00
|
|
|
author_id: author.id, created_at: created_at)
|
2013-04-10 16:28:42 -04:00
|
|
|
end
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|