diff --git a/app/models/reaction.rb b/app/models/reaction.rb index 9578c426c..a5c72e966 100644 --- a/app/models/reaction.rb +++ b/app/models/reaction.rb @@ -49,7 +49,7 @@ class Reaction < ApplicationRecord before_save :assign_points after_create :notify_slack_channel_about_vomit_reaction, if: -> { category == "vomit" } before_destroy :bust_reactable_cache_without_delay - before_destroy :update_reactable_without_delay, unless: :destroyed_by_association + before_destroy :update_reactable, unless: :destroyed_by_association after_commit :async_bust after_commit :bust_reactable_cache, :update_reactable, on: %i[create update] after_commit :record_field_test_event, on: %i[create] @@ -194,10 +194,6 @@ class Reaction < ApplicationRecord Reactions::BustReactableCacheWorker.new.perform(id) end - def update_reactable_without_delay - Reactions::UpdateRelevantScoresWorker.new.perform(id) - end - def reading_time reactable.reading_time if category == "readinglist" end diff --git a/spec/models/reaction_spec.rb b/spec/models/reaction_spec.rb index ef64e472d..b27d5cfc5 100644 --- a/spec/models/reaction_spec.rb +++ b/spec/models/reaction_spec.rb @@ -139,10 +139,10 @@ RSpec.describe Reaction do expected_result = [ { category: "like", count: 1 }, - { category: "unicorn", count: 1 }, { category: "readinglist", count: 0 }, + { category: "unicorn", count: 1 }, ] - expect(described_class.count_for_article(article.id)).to eq(expected_result) + expect(described_class.count_for_article(article.id)).to contain_exactly(*expected_result) end end @@ -234,7 +234,7 @@ RSpec.describe Reaction do end context "when callbacks are called before destroy" do - let(:reaction) { create(:reaction, reactable: article, user: user) } + let!(:reaction) { create(:reaction, reactable: article, user: user) } it "enqueues a ScoreCalcWorker on article reaction destroy" do sidekiq_assert_enqueued_with(job: Articles::ScoreCalcWorker, args: [article.id]) do @@ -242,10 +242,10 @@ RSpec.describe Reaction do end end - it "updates reactable without delay" do - allow(reaction).to receive(:update_reactable_without_delay) + it "updates reactable with delay" do + allow(Reactions::UpdateRelevantScoresWorker).to receive(:perform_async) reaction.destroy - expect(reaction).to have_received(:update_reactable_without_delay) + expect(Reactions::UpdateRelevantScoresWorker).to have_received(:perform_async) end it "busts reactable cache without delay" do