From 189d70661e56a20590dcba2dd6f3c0efc3168c83 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 6 Apr 2016 12:02:18 -0400 Subject: [PATCH] FIX: Don't count emojis within quotes --- lib/cooked_post_processor.rb | 6 +++++- spec/models/user_firsts_spec.rb | 32 ++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index bab2cee51..cbb71e0d4 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -32,12 +32,16 @@ class CookedPostProcessor end end + def has_emoji? + (@doc.css("img.emoji") - @doc.css(".quote img")).size > 0 + end + def create_firsts return unless Guardian.new.can_see?(@post) created = false - if @doc.css("img.emoji").size > 0 + if has_emoji? created |= UserFirst.create_for(@post.user_id, :used_emoji, @post.id) end diff --git a/spec/models/user_firsts_spec.rb b/spec/models/user_firsts_spec.rb index 09323481e..5bbe8733f 100644 --- a/spec/models/user_firsts_spec.rb +++ b/spec/models/user_firsts_spec.rb @@ -11,12 +11,24 @@ describe UserFirst do end end - it "creates one the first time a user posts an emoji" do - post = PostCreator.create(user, title: "this topic is about candy", raw: "time to eat some sweet :candy: mmmm") + context "emoji" do + it "logs a user first" do + post = PostCreator.create(user, title: "this topic is about candy", raw: "time to eat some sweet :candy: mmmm") + + uf = UserFirst.where(user_id: user.id, first_type: UserFirst.types[:used_emoji]).first + expect(uf).to be_present + expect(uf.post_id).to eq(post.id) + end + + it "doesn't log a user first when in a quote" do + PostCreator.create(user, + title: "this topic is about candy", + raw: "time to eat some sweet [quote]:candy:[/quote] mmmm") + + uf = UserFirst.where(user_id: user.id, first_type: UserFirst.types[:used_emoji]).first + expect(uf).to be_blank + end - uf = UserFirst.where(user_id: user.id, first_type: UserFirst.types[:used_emoji]).first - expect(uf).to be_present - expect(uf.post_id).to eq(post.id) end context 'mentioning' do @@ -34,11 +46,11 @@ describe UserFirst do let(:codinghorror) { Fabricate(:codinghorror) } it "doesn't create the userfirst on private posts" do - post = PostCreator.create(user, - archetype: Archetype.private_message, - target_usernames: ['codinghorror'], - title: "this topic is about candy", - raw: "time to eat some sweet :candy: mmmm") + PostCreator.create(user, + archetype: Archetype.private_message, + target_usernames: ['codinghorror'], + title: "this topic is about candy", + raw: "time to eat some sweet :candy: mmmm") uf = UserFirst.where(user_id: user.id, first_type: UserFirst.types[:used_emoji]).first expect(uf).to be_blank