From 64ac18843e8eed2ba49443a1a9b3150ee965ee6a Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Mon, 11 Dec 2023 19:56:50 +0100 Subject: [PATCH] Replace usages of `QuestionWorker` --- app/controllers/ajax/question_controller.rb | 33 ++++++++++--------- .../ajax/question_controller_spec.rb | 26 +++++++-------- .../question/create_followers_spec.rb | 2 +- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/app/controllers/ajax/question_controller.rb b/app/controllers/ajax/question_controller.rb index f3bef810..4cf425b5 100644 --- a/app/controllers/ajax/question_controller.rb +++ b/app/controllers/ajax/question_controller.rb @@ -1,19 +1,6 @@ # frozen_string_literal: true class Ajax::QuestionController < AjaxController - def destroy - params.require :question - - UseCase::Question::Destroy.call( - question_id: params[:question], - current_user: current_user - ) - - @response[:status] = :okay - @response[:message] = t(".success") - @response[:success] = true - end - def create params.require :question params.require :anonymousQuestion @@ -24,14 +11,14 @@ class Ajax::QuestionController < AjaxController @response = { success: true, message: t(".success"), - status: :okay + status: :okay, } if user_signed_in? && params[:rcpt] == "followers" UseCase::Question::CreateFollowers.call( source_user_id: current_user.id, content: params[:question], - author_identifier: AnonymousBlock.get_identifier(request.remote_ip) + author_identifier: AnonymousBlock.get_identifier(request.remote_ip), ) return end @@ -41,7 +28,21 @@ class Ajax::QuestionController < AjaxController target_user_id: params[:rcpt], content: params[:question], anonymous: params[:anonymousQuestion], - author_identifier: AnonymousBlock.get_identifier(request.remote_ip) + author_identifier: AnonymousBlock.get_identifier(request.remote_ip), ) end + + def destroy + params.require :question + + UseCase::Question::Destroy.call( + question_id: params[:question], + current_user: current_user, + ) + + @response[:status] = :okay + @response[:message] = t(".success") + @response[:success] = true + end + end diff --git a/spec/controllers/ajax/question_controller_spec.rb b/spec/controllers/ajax/question_controller_spec.rb index 0fc8922b..eaa37774 100644 --- a/spec/controllers/ajax/question_controller_spec.rb +++ b/spec/controllers/ajax/question_controller_spec.rb @@ -48,25 +48,25 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do include_examples "returns the expected response" end - shared_examples "enqueues QuestionWorker jobs" do - it "enqueues a QuestionWorker job" do - allow(QuestionWorker).to receive(:perform_bulk) + shared_examples "enqueues SendToInboxJob jobs" do + it "enqueues a SendToInboxJob job" do + allow(SendToInboxJob).to receive(:perform_bulk) subject question_id = Question.last.id bulk_args = followers.map { |f| [f.id, question_id] } - expect(QuestionWorker).to have_received(:perform_bulk).with(bulk_args) + expect(SendToInboxJob).to have_received(:perform_bulk).with(bulk_args) end include_examples "returns the expected response" end - shared_examples "does not enqueue a QuestionWorker job" do - it "does not enqueue a QuestionWorker job" do - allow(QuestionWorker).to receive(:perform_async) - allow(QuestionWorker).to receive(:perform_bulk) + shared_examples "does not enqueue a SendToInboxJob job" do + it "does not enqueue a SendToInboxJob job" do + allow(SendToInboxJob).to receive(:perform_async) + allow(SendToInboxJob).to receive(:perform_bulk) subject - expect(QuestionWorker).not_to have_received(:perform_async) - expect(QuestionWorker).not_to have_received(:perform_bulk) + expect(SendToInboxJob).not_to have_received(:perform_async) + expect(SendToInboxJob).not_to have_received(:perform_bulk) end include_examples "returns the expected response" @@ -209,7 +209,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do let(:expected_question_anonymous) { false } include_examples "creates the question", false - include_examples "enqueues QuestionWorker jobs" + include_examples "enqueues SendToInboxJob jobs" end context "when anonymousQuestion is false" do @@ -217,7 +217,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do let(:expected_question_anonymous) { false } include_examples "creates the question", false - include_examples "enqueues QuestionWorker jobs" + include_examples "enqueues SendToInboxJob jobs" end end @@ -384,7 +384,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do } end - include_examples "does not enqueue a QuestionWorker job" + include_examples "does not enqueue a SendToInboxJob job" end context "when rcpt is an invalid value" do diff --git a/spec/lib/use_case/question/create_followers_spec.rb b/spec/lib/use_case/question/create_followers_spec.rb index 3f048370..b5511459 100644 --- a/spec/lib/use_case/question/create_followers_spec.rb +++ b/spec/lib/use_case/question/create_followers_spec.rb @@ -29,7 +29,7 @@ describe UseCase::Question::CreateFollowers do it "enqueues a QuestionWorker job" do followers.each do |target_user| - expect(QuestionWorker).to have_enqueued_sidekiq_job(target_user.id, subject[:resource].id) + expect(SendToInboxJob).to have_enqueued_sidekiq_job(target_user.id, subject[:resource].id) end end