Fix #4957: Autotag non-web_source.

Autotag non-web_source on posts that have a non-http:// or https:// URL.
Add a fix script to backfill old posts.

Syntactically invalid URLs are still considered web sources. For
example, `https://google,com` technically isn't a valid URL, but it's
not considered a non-web source.
This commit is contained in:
evazion
2022-01-14 22:42:19 -06:00
parent adc5bbf906
commit c3c4f5a2a7
3 changed files with 54 additions and 1 deletions

View File

@@ -1046,6 +1046,30 @@ class PostTest < ActiveSupport::TestCase
end
end
context "a post with a non-web source" do
should "automatically add the non-web_source tag" do
@post.update!(source: "this was once revealed to me in a dream")
@post.save!
assert_equal("non-web_source tag1 tag2", @post.tag_string)
end
end
context "a post with a blank source" do
should "remove the non-web_source tag" do
@post.update!(source: "", tag_string: "non-web_source")
@post.save!
assert_equal("tagme", @post.tag_string)
end
end
context "a post with a https:// source" do
should "remove the non-web_source tag" do
@post.update!(source: "https://www.google.com", tag_string: "non-web_source")
@post.save!
assert_equal("tagme", @post.tag_string)
end
end
should "have an array representation of its tags" do
post = FactoryBot.create(:post)
post.reload