summaryrefslogtreecommitdiff
path: root/spec/roles/votes_spec.rb
blob: 43817999dc1e3b2e16c8c35e121bba90fb44cee8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
end