Make notes recognize downvotes

This commit is contained in:
Riyad Preukschas 2012-09-08 02:08:35 +02:00
parent cc7c6d5396
commit 06c1a8a9ae
2 changed files with 21 additions and 8 deletions

View file

@ -105,6 +105,12 @@ class Note < ActiveRecord::Base
def upvote? def upvote?
note.start_with?('+1') || note.start_with?(':+1:') note.start_with?('+1') || note.start_with?(':+1:')
end 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 end
# == Schema Information # == Schema Information
# #

View file

@ -24,6 +24,13 @@ describe Note do
it "recognizes a neutral note" do it "recognizes a neutral note" do
note = Factory(:note, note: "This is not a +1 note") note = Factory(:note, note: "This is not a +1 note")
note.should_not be_upvote 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 end
it "recognizes a +1 note" do it "recognizes a +1 note" do
@ -31,19 +38,19 @@ describe Note do
note.should be_upvote note.should be_upvote
end 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 it "recognizes a +1 emoji as a vote" do
note = build(:note, note: ":+1: for this") note = build(:note, note: ":+1: for this")
note.should be_upvote note.should be_upvote
end end
it "recognizes a neutral emoji note" do it "recognizes a -1 note" do
note = build(:note, note: "I would :+1: this, but I don't want to") note = Factory(:note, note: "-1 for this")
note.should_not be_upvote 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
end end