Add :detect_animated_images feature flag to guard animated images detection (#13906)

This commit is contained in:
rhymes 2021-06-03 23:21:43 +02:00 committed by GitHub
parent 88a9a4b0a7
commit 3ca2f5413f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View file

@ -817,6 +817,7 @@ class Article < ApplicationRecord
end
def detect_animated_images
return unless FeatureFlag.enabled?(:detect_animated_images)
return unless saved_change_to_attribute?(:processed_html)
::Articles::DetectAnimatedImagesWorker.perform_async(id)

View file

@ -975,8 +975,17 @@ RSpec.describe Article, type: :model do
context "when callbacks are triggered after create" do
describe "detect animated images" do
it "enqueues Articles::DetectAnimatedImagesWorker" do
sidekiq_assert_enqueued_with(job: Articles::DetectAnimatedImagesWorker, args: [article.id]) do
it "does not enqueue Articles::DetectAnimatedImagesWorker if the feature :detect_animated_images is disabled" do
allow(FeatureFlag).to receive(:enabled?).with(:detect_animated_images).and_return(false)
sidekiq_assert_no_enqueued_jobs(only: Articles::DetectAnimatedImagesWorker) do
build(:article).save
end
end
it "enqueues Articles::DetectAnimatedImagesWorker if the feature :detect_animated_images is enabled" do
allow(FeatureFlag).to receive(:enabled?).with(:detect_animated_images).and_return(true)
sidekiq_assert_enqueued_jobs(1, only: Articles::DetectAnimatedImagesWorker) do
build(:article).save
end
end
@ -1104,13 +1113,25 @@ RSpec.describe Article, type: :model do
end
describe "detect animated images" do
it "does not enqueue Articles::DetectAnimatedImagesWorker if the feature :detect_animated_images is disabled" do
allow(FeatureFlag).to receive(:enabled?).with(:detect_animated_images).and_return(false)
sidekiq_assert_no_enqueued_jobs(only: Articles::DetectAnimatedImagesWorker) do
article.update(body_markdown: "a body")
end
end
it "enqueues Articles::DetectAnimatedImagesWorker if the HTML has changed" do
allow(FeatureFlag).to receive(:enabled?).with(:detect_animated_images).and_return(true)
sidekiq_assert_enqueued_with(job: Articles::DetectAnimatedImagesWorker, args: [article.id]) do
article.update(body_markdown: "a body")
end
end
it "does not Articles::DetectAnimatedImagesWorker if the HTML does not change" do
allow(FeatureFlag).to receive(:enabled?).with(:detect_animated_images).and_return(true)
sidekiq_assert_no_enqueued_jobs(only: Articles::DetectAnimatedImagesWorker) do
article.update(tag_list: %w[fsharp go])
end