From 2faa4bba40909778c1732894faf42a0f00e87cc4 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 6 Sep 2012 15:31:25 -0400 Subject: [PATCH] Update Note#upvote? to support emoji voting --- app/models/note.rb | 2 +- spec/models/note_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/note.rb b/app/models/note.rb index 711a4ee6..d8494edd 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -103,7 +103,7 @@ class Note < ActiveRecord::Base # Returns true if this is an upvote note, # otherwise false is returned def upvote? - note =~ /^\+1/ ? true : false + 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 ffaf442d..dddfd34c 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -35,6 +35,16 @@ describe Note 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 + end end let(:project) { create(:project) }