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,6 +105,12 @@ class Note < ActiveRecord::Base
105 def upvote? 105 def upvote?
106 note.start_with?('+1') || note.start_with?(':+1:') 106 note.start_with?('+1') || note.start_with?(':+1:')
107 end 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 end 114 end
109 # == Schema Information 115 # == Schema Information
110 # 116 #
spec/models/note_spec.rb
@@ -24,6 +24,13 @@ describe Note do @@ -24,6 +24,13 @@ describe Note do
24 it "recognizes a neutral note" do 24 it "recognizes a neutral note" do
25 note = Factory(:note, note: "This is not a +1 note") 25 note = Factory(:note, note: "This is not a +1 note")
26 note.should_not be_upvote 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 end 34 end
28 35
29 it "recognizes a +1 note" do 36 it "recognizes a +1 note" do
@@ -31,19 +38,19 @@ describe Note do @@ -31,19 +38,19 @@ describe Note do
31 note.should be_upvote 38 note.should be_upvote
32 end 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 it "recognizes a +1 emoji as a vote" do 41 it "recognizes a +1 emoji as a vote" do
40 note = build(:note, note: ":+1: for this") 42 note = build(:note, note: ":+1: for this")
41 note.should be_upvote 43 note.should be_upvote
42 end 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 end 54 end
48 end 55 end
49 56