FIX: use the avatar of the post rather than the topic in local oneboxes

This commit is contained in:
Régis Hanol 2018-02-20 19:49:39 +01:00
parent a4bc54a686
commit 0799831dbe
2 changed files with 13 additions and 4 deletions

View File

@ -202,7 +202,7 @@ module Oneboxer
else else
args = { args = {
topic_id: topic.id, topic_id: topic.id,
avatar: PrettyText.avatar_img(topic.user.avatar_template, "tiny"), avatar: PrettyText.avatar_img(post.user.avatar_template, "tiny"),
original_url: url, original_url: url,
title: PrettyText.unescape_emoji(CGI::escapeHTML(topic.title)), title: PrettyText.unescape_emoji(CGI::escapeHTML(topic.title)),
category_html: CategoryBadge.html_for(topic.category), category_html: CategoryBadge.html_for(topic.category),

View File

@ -33,9 +33,11 @@ describe Oneboxer do
secured_category.permissions = { staff: :full } secured_category.permissions = { staff: :full }
secured_category.save! secured_category.save!
replier = Fabricate(:user)
public_post = Fabricate(:post) public_post = Fabricate(:post)
public_topic = public_post.topic public_topic = public_post.topic
public_reply = Fabricate(:post, topic: public_topic, post_number: 2) public_reply = Fabricate(:post, topic: public_topic, post_number: 2, user: replier)
public_hidden = Fabricate(:post, topic: public_topic, post_number: 3, hidden: true) public_hidden = Fabricate(:post, topic: public_topic, post_number: 3, hidden: true)
user = public_post.user user = public_post.user
@ -47,8 +49,15 @@ describe Oneboxer do
expect(preview(public_topic.relative_url, user, public_category)).to include(public_topic.title) expect(preview(public_topic.relative_url, user, public_category)).to include(public_topic.title)
expect(preview(public_post.url, user, public_category)).to include(public_topic.title) expect(preview(public_post.url, user, public_category)).to include(public_topic.title)
expect(preview(public_reply.url, user, public_category)).to include(public_reply.excerpt)
expect(preview(public_reply.url, user, public_category, public_topic)).not_to include(public_topic.title) onebox = preview(public_reply.url, user, public_category)
expect(onebox).to include(public_reply.excerpt)
expect(onebox).to include(PrettyText.avatar_img(replier.avatar_template, "tiny"))
onebox = preview(public_reply.url, user, public_category, public_topic)
expect(onebox).not_to include(public_topic.title)
expect(onebox).to include(replier.avatar_template.sub("{size}", "40"))
expect(preview(public_hidden.url, user, public_category)).to match_html(link(public_hidden.url)) expect(preview(public_hidden.url, user, public_category)).to match_html(link(public_hidden.url))
expect(preview(secured_topic.relative_url, user, public_category)).to match_html(link(secured_topic.relative_url)) expect(preview(secured_topic.relative_url, user, public_category)).to match_html(link(secured_topic.relative_url))
expect(preview(secured_post.url, user, public_category)).to match_html(link(secured_post.url)) expect(preview(secured_post.url, user, public_category)).to match_html(link(secured_post.url))