Apply the same url normalisation to embed_urls inserted in the PostCreator ()

This commit is contained in:
Angus McLeod 2025-01-09 20:59:08 +01:00 committed by GitHub
parent 773857848b
commit 427ea5301b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

@ -405,7 +405,7 @@ class PostCreator
TopicEmbed.new(
topic_id: @post.topic_id,
post_id: @post.id,
embed_url: @opts[:embed_url],
embed_url: TopicEmbed.normalize_url(@opts[:embed_url]),
content_sha1: @opts[:embed_content_sha1],
)
rollback_from_errors!(embed) unless embed.save

@ -1512,6 +1512,20 @@ RSpec.describe PostCreator do
expect(post.topic).not_to be_visible
end
end
it "normalizes the embed url" do
embed_url = "http://eviltrout.com/stupid-url/"
creator =
PostCreator.new(
user,
embed_url: embed_url,
title: "Reviews of Science Ovens",
raw: "Did you know that you can use microwaves to cook your dinner? Science!",
)
creator.create
expect(creator.errors).to be_blank
expect(TopicEmbed.where(embed_url: "http://eviltrout.com/stupid-url").exists?).to eq(true)
end
end
describe "read credit for creator" do