diff options
author | Michael Clarke <michael.m.clarke@gmail.com> | 2014-11-05 20:45:18 +0000 |
---|---|---|
committer | Michael Clarke <michael.m.clarke@gmail.com> | 2015-01-19 21:18:36 +0000 |
commit | 505a492cd87be7683827c5f46a05b6a7dddffc86 (patch) | |
tree | 3d34981fbfb3e429475d2f6e87da0c63db5b9657 /spec/lib/votes_spec.rb | |
parent | 465f41673a418096b761d12438301c7b217f9a81 (diff) | |
download | gitlab-ce-505a492cd87be7683827c5f46a05b6a7dddffc86.tar.gz |
Only count the user's last vote
Diffstat (limited to 'spec/lib/votes_spec.rb')
-rw-r--r-- | spec/lib/votes_spec.rb | 100 |
1 files changed, 74 insertions, 26 deletions
diff --git a/spec/lib/votes_spec.rb b/spec/lib/votes_spec.rb index a3c353d5eab..63692814b97 100644 --- a/spec/lib/votes_spec.rb +++ b/spec/lib/votes_spec.rb @@ -20,11 +20,17 @@ describe Issue, 'Votes' do issue.upvotes.should == 1 end - it "should recognize multiple +1 notes" do - add_note "+1 This is awesome" - add_note "+1 I want this" + it 'should recognize multiple +1 notes' do + add_note '+1 This is awesome', create(:user) + add_note '+1 I want this', create(:user) issue.upvotes.should == 2 end + + it 'should not count 2 +1 votes from the same user' do + add_note '+1 This is awesome' + add_note '+1 I want this' + issue.upvotes.should == 1 + end end describe "#downvotes" do @@ -45,8 +51,8 @@ describe Issue, 'Votes' do end it "should recognize multiple -1 notes" do - add_note "-1 This is bad" - add_note "-1 Away with this" + add_note('-1 This is bad', create(:user)) + add_note('-1 Away with this', create(:user)) issue.downvotes.should == 2 end end @@ -73,11 +79,17 @@ describe Issue, 'Votes' do end it "should recognize multiple notes" do - add_note "+1 This is awesome" - add_note "-1 This is bad" - add_note "+1 I want this" + add_note('+1 This is awesome', create(:user)) + add_note('-1 This is bad', create(:user)) + add_note('+1 I want this', create(:user)) issue.votes_count.should == 3 end + + it 'should not count 2 -1 votes from the same user' do + add_note '-1 This is suspicious' + add_note '-1 This is bad' + issue.votes_count.should == 1 + end end describe "#upvotes_in_percent" do @@ -90,17 +102,17 @@ describe Issue, 'Votes' do issue.upvotes_in_percent.should == 100 end - it "should count multiple +1 notes as 100%" do - add_note "+1 This is awesome" - add_note "+1 I want this" + 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)) issue.upvotes_in_percent.should == 100 end - it "should count fractions for multiple +1 and -1 notes correctly" do - add_note "+1 This is awesome" - add_note "+1 I want this" - add_note "-1 This is bad" - add_note "+1 me too" + 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)) issue.upvotes_in_percent.should == 75 end end @@ -115,22 +127,58 @@ describe Issue, 'Votes' do issue.downvotes_in_percent.should == 100 end - it "should count multiple -1 notes as 100%" do - add_note "-1 This is bad" - add_note "-1 Away with this" + 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)) issue.downvotes_in_percent.should == 100 end - it "should count fractions for multiple +1 and -1 notes correctly" do - add_note "+1 This is awesome" - add_note "+1 I want this" - add_note "-1 This is bad" - add_note "+1 me too" + 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)) issue.downvotes_in_percent.should == 25 end end - def add_note(text) - issue.notes << create(:note, note: text, project: issue.project) + 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)) + issue.downvotes.should == 0 + issue.upvotes.should == 5 + 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!!!!' + p issue.downvotes.should == 0 + p issue.upvotes.should == 1 + 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' + p issue.downvotes.should == 0 + p issue.upvotes.should == 1 + end + + end + + def add_note(text, author = issue.author) + issue.notes << create(:note, note: text, project: issue.project, + author_id: author.id) end end |