From 06c1a8a9ae34e2a4fe7b4f4edb58bacfaf6df5c9 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sat, 8 Sep 2012 02:08:35 +0200 Subject: [PATCH] Make notes recognize downvotes --- app/models/note.rb | 6 ++++++ spec/models/note_spec.rb | 23 +++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/models/note.rb b/app/models/note.rb index d8494edd532..4c46c7dfffa 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -105,6 +105,12 @@ class Note < ActiveRecord::Base def upvote? note.start_with?('+1') || note.start_with?(':+1:') end + + # Returns true if this is a downvote note, + # otherwise false is returned + def downvote? + note.start_with?('-1') || note.start_with?(':-1:') + end end # == Schema Information # diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index dddfd34c499..7809953f5b3 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -24,6 +24,13 @@ describe Note do it "recognizes a neutral note" do note = Factory(:note, note: "This is not a +1 note") note.should_not be_upvote + note.should_not be_downvote + end + + it "recognizes a neutral emoji note" do + note = build(:note, note: "I would :+1: this, but I don't want to") + note.should_not be_upvote + note.should_not be_downvote end it "recognizes a +1 note" do @@ -31,19 +38,19 @@ describe Note do note.should be_upvote end - it "recognizes a -1 note as no vote" do - note = Factory(:note, note: "-1 for this") - note.should_not be_upvote - end - it "recognizes a +1 emoji as a vote" do note = build(:note, note: ":+1: for this") note.should be_upvote end - it "recognizes a neutral emoji note" do - note = build(:note, note: "I would :+1: this, but I don't want to") - note.should_not be_upvote + it "recognizes a -1 note" do + note = Factory(:note, note: "-1 for this") + note.should be_downvote + end + + it "recognizes a -1 emoji as a vote" do + note = build(:note, note: ":-1: for this") + note.should be_downvote end end -- GitLab