OSDN Git Service

Make notes recognize downvotes
authorRiyad Preukschas <riyad@informatik.uni-bremen.de>
Sat, 8 Sep 2012 00:08:35 +0000 (02:08 +0200)
committerRiyad Preukschas <riyad@informatik.uni-bremen.de>
Sat, 8 Sep 2012 14:05:48 +0000 (16:05 +0200)
app/models/note.rb
spec/models/note_spec.rb

index d8494ed..4c46c7d 100644 (file)
@@ -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
 #
index dddfd34..7809953 100644 (file)
@@ -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