FIX: Don't count emojis within quotes
This commit is contained in:
parent
56c870cca2
commit
189d70661e
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue