Commit 06c1a8a9ae34e2a4fe7b4f4edb58bacfaf6df5c9

Authored by Riyad Preukschas
1 parent cc7c6d53

Make notes recognize downvotes

Showing 2 changed files with 21 additions and 8 deletions   Show diff stats
app/models/note.rb
... ... @@ -105,6 +105,12 @@ class Note < ActiveRecord::Base
105 105 def upvote?
106 106 note.start_with?('+1') || note.start_with?(':+1:')
107 107 end
  108 +
  109 + # Returns true if this is a downvote note,
  110 + # otherwise false is returned
  111 + def downvote?
  112 + note.start_with?('-1') || note.start_with?(':-1:')
  113 + end
108 114 end
109 115 # == Schema Information
110 116 #
... ...
spec/models/note_spec.rb
... ... @@ -24,6 +24,13 @@ describe Note do
24 24 it "recognizes a neutral note" do
25 25 note = Factory(:note, note: "This is not a +1 note")
26 26 note.should_not be_upvote
  27 + note.should_not be_downvote
  28 + end
  29 +
  30 + it "recognizes a neutral emoji note" do
  31 + note = build(:note, note: "I would :+1: this, but I don't want to")
  32 + note.should_not be_upvote
  33 + note.should_not be_downvote
27 34 end
28 35  
29 36 it "recognizes a +1 note" do
... ... @@ -31,19 +38,19 @@ describe Note do
31 38 note.should be_upvote
32 39 end
33 40  
34   - it "recognizes a -1 note as no vote" do
35   - note = Factory(:note, note: "-1 for this")
36   - note.should_not be_upvote
37   - end
38   -
39 41 it "recognizes a +1 emoji as a vote" do
40 42 note = build(:note, note: ":+1: for this")
41 43 note.should be_upvote
42 44 end
43 45  
44   - it "recognizes a neutral emoji note" do
45   - note = build(:note, note: "I would :+1: this, but I don't want to")
46   - note.should_not be_upvote
  46 + it "recognizes a -1 note" do
  47 + note = Factory(:note, note: "-1 for this")
  48 + note.should be_downvote
  49 + end
  50 +
  51 + it "recognizes a -1 emoji as a vote" do
  52 + note = build(:note, note: ":-1: for this")
  53 + note.should be_downvote
47 54 end
48 55 end
49 56  
... ...