diff --git a/app/models/article.rb b/app/models/article.rb index 779316ff2..38b791275 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -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) diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index a346b6f98..226256129 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -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