mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Include post number in inline Onebox titles (#11515)
This commit is contained in:
@@ -116,6 +116,37 @@ describe InlineOneboxer do
|
||||
expect(onebox[:title]).to eq("Hello 🍕 with an emoji")
|
||||
end
|
||||
|
||||
it "will append the post number post auther's username to the title" do
|
||||
topic = Fabricate(:topic, title: "Inline oneboxer")
|
||||
Fabricate(:post, topic: topic) # OP
|
||||
Fabricate(:post, topic: topic)
|
||||
lookup = -> (number) do
|
||||
InlineOneboxer.lookup(
|
||||
"#{topic.url}/#{number}",
|
||||
skip_cache: true
|
||||
)[:title]
|
||||
end
|
||||
posts = topic.reload.posts.order("post_number ASC")
|
||||
|
||||
expect(lookup.call(0)).to eq("Inline oneboxer")
|
||||
expect(lookup.call(1)).to eq("Inline oneboxer")
|
||||
expect(lookup.call(2)).to eq("Inline oneboxer - #2 by #{posts[1].user.username}")
|
||||
|
||||
Fabricate(:post, topic: topic, post_type: Post.types[:whisper])
|
||||
posts = topic.reload.posts.order("post_number ASC")
|
||||
# because the last post in the topic is a whisper, the onebox title
|
||||
# will be the first regular post directly before our whisper
|
||||
expect(lookup.call(3)).to eq("Inline oneboxer - #2 by #{posts[1].user.username}")
|
||||
expect(lookup.call(99)).to eq("Inline oneboxer - #2 by #{posts[1].user.username}")
|
||||
|
||||
Fabricate(:post, topic: topic)
|
||||
posts = topic.reload.posts.order("post_number ASC")
|
||||
# username not appended to whisper posts
|
||||
expect(lookup.call(3)).to eq("Inline oneboxer - #3")
|
||||
expect(lookup.call(4)).to eq("Inline oneboxer - #4 by #{posts[3].user.username}")
|
||||
expect(lookup.call(99)).to eq("Inline oneboxer - #4 by #{posts[3].user.username}")
|
||||
end
|
||||
|
||||
it "will not crawl domains that aren't allowlisted" do
|
||||
onebox = InlineOneboxer.lookup("https://eviltrout.com", skip_cache: true)
|
||||
expect(onebox).to be_blank
|
||||
|
||||
@@ -621,9 +621,51 @@ describe TopicView do
|
||||
context "page_title" do
|
||||
fab!(:tag1) { Fabricate(:tag) }
|
||||
fab!(:tag2) { Fabricate(:tag, topic_count: 2) }
|
||||
fab!(:op_post) { Fabricate(:post, topic: topic) }
|
||||
fab!(:post1) { Fabricate(:post, topic: topic) }
|
||||
fab!(:whisper) { Fabricate(:post, topic: topic, post_type: Post.types[:whisper]) }
|
||||
|
||||
subject { TopicView.new(topic.id, evil_trout).page_title }
|
||||
|
||||
context "when a post number is specified" do
|
||||
context "admins" do
|
||||
it "see post number and username for all posts" do
|
||||
title = TopicView.new(topic.id, admin, post_number: 0).page_title
|
||||
expect(title).to eq(topic.title)
|
||||
title = TopicView.new(topic.id, admin, post_number: 1).page_title
|
||||
expect(title).to eq(topic.title)
|
||||
|
||||
title = TopicView.new(topic.id, admin, post_number: 2).page_title
|
||||
expect(title).to eq("#{topic.title} - #2 by #{post1.user.username}")
|
||||
title = TopicView.new(topic.id, admin, post_number: 3).page_title
|
||||
expect(title).to eq("#{topic.title} - #3 by #{whisper.user.username}")
|
||||
end
|
||||
end
|
||||
|
||||
context "regular users" do
|
||||
it "see post number and username for regular posts" do
|
||||
title = TopicView.new(topic.id, evil_trout, post_number: 0).page_title
|
||||
expect(title).to eq(topic.title)
|
||||
title = TopicView.new(topic.id, evil_trout, post_number: 1).page_title
|
||||
expect(title).to eq(topic.title)
|
||||
|
||||
title = TopicView.new(topic.id, evil_trout, post_number: 2).page_title
|
||||
expect(title).to eq("#{topic.title} - #2 by #{post1.user.username}")
|
||||
end
|
||||
|
||||
it "see only post number for whisper posts" do
|
||||
title = TopicView.new(topic.id, evil_trout, post_number: 3).page_title
|
||||
expect(title).to eq("#{topic.title} - #3")
|
||||
post2 = Fabricate(:post, topic: topic)
|
||||
topic.reload
|
||||
title = TopicView.new(topic.id, evil_trout, post_number: 3).page_title
|
||||
expect(title).to eq("#{topic.title} - #3")
|
||||
title = TopicView.new(topic.id, evil_trout, post_number: 4).page_title
|
||||
expect(title).to eq("#{topic.title} - #4 by #{post2.user.username}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "uncategorized topic" do
|
||||
context "topic_page_title_includes_category is false" do
|
||||
before { SiteSetting.topic_page_title_includes_category = false }
|
||||
|
||||
Reference in New Issue
Block a user