From 0b926a43e4355909687e67846d43a4eb8c7161dc Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Mon, 27 Dec 2021 18:53:59 +0100 Subject: [PATCH] Test `ShareWorker`'s handling of deleted records --- spec/workers/share_worker_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 spec/workers/share_worker_spec.rb diff --git a/spec/workers/share_worker_spec.rb b/spec/workers/share_worker_spec.rb new file mode 100644 index 00000000..5c5c3a3f --- /dev/null +++ b/spec/workers/share_worker_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe ShareWorker do + let(:user) { FactoryBot.create(:user) } + let(:answer) { FactoryBot.create(:answer, user: user) } + + describe "#perform" do + subject { ShareWorker.new.perform(user.id, answer.id, 'twitter') } + + before do + Service.create!(type: 'Services::Twitter', + user: user) + end + + context 'when answer doesn\'t exist' do + it 'prevents the job from retrying and logs a message' do + answer.destroy! + Sidekiq.logger.should_receive(:info) + subject + expect(ShareWorker.jobs.size).to eq(0) + end + end + end +end