Replace usages of `QuestionWorker`
This commit is contained in:
parent
aaee04b5ed
commit
64ac18843e
|
@ -1,19 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Ajax::QuestionController < AjaxController
|
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
|
def create
|
||||||
params.require :question
|
params.require :question
|
||||||
params.require :anonymousQuestion
|
params.require :anonymousQuestion
|
||||||
|
@ -24,14 +11,14 @@ class Ajax::QuestionController < AjaxController
|
||||||
@response = {
|
@response = {
|
||||||
success: true,
|
success: true,
|
||||||
message: t(".success"),
|
message: t(".success"),
|
||||||
status: :okay
|
status: :okay,
|
||||||
}
|
}
|
||||||
|
|
||||||
if user_signed_in? && params[:rcpt] == "followers"
|
if user_signed_in? && params[:rcpt] == "followers"
|
||||||
UseCase::Question::CreateFollowers.call(
|
UseCase::Question::CreateFollowers.call(
|
||||||
source_user_id: current_user.id,
|
source_user_id: current_user.id,
|
||||||
content: params[:question],
|
content: params[:question],
|
||||||
author_identifier: AnonymousBlock.get_identifier(request.remote_ip)
|
author_identifier: AnonymousBlock.get_identifier(request.remote_ip),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -41,7 +28,21 @@ class Ajax::QuestionController < AjaxController
|
||||||
target_user_id: params[:rcpt],
|
target_user_id: params[:rcpt],
|
||||||
content: params[:question],
|
content: params[:question],
|
||||||
anonymous: params[:anonymousQuestion],
|
anonymous: params[:anonymousQuestion],
|
||||||
author_identifier: AnonymousBlock.get_identifier(request.remote_ip)
|
author_identifier: AnonymousBlock.get_identifier(request.remote_ip),
|
||||||
)
|
)
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -48,25 +48,25 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
|
||||||
include_examples "returns the expected response"
|
include_examples "returns the expected response"
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples "enqueues QuestionWorker jobs" do
|
shared_examples "enqueues SendToInboxJob jobs" do
|
||||||
it "enqueues a QuestionWorker job" do
|
it "enqueues a SendToInboxJob job" do
|
||||||
allow(QuestionWorker).to receive(:perform_bulk)
|
allow(SendToInboxJob).to receive(:perform_bulk)
|
||||||
subject
|
subject
|
||||||
question_id = Question.last.id
|
question_id = Question.last.id
|
||||||
bulk_args = followers.map { |f| [f.id, question_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
|
end
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
include_examples "returns the expected response"
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples "does not enqueue a QuestionWorker job" do
|
shared_examples "does not enqueue a SendToInboxJob job" do
|
||||||
it "does not enqueue a QuestionWorker job" do
|
it "does not enqueue a SendToInboxJob job" do
|
||||||
allow(QuestionWorker).to receive(:perform_async)
|
allow(SendToInboxJob).to receive(:perform_async)
|
||||||
allow(QuestionWorker).to receive(:perform_bulk)
|
allow(SendToInboxJob).to receive(:perform_bulk)
|
||||||
subject
|
subject
|
||||||
expect(QuestionWorker).not_to have_received(:perform_async)
|
expect(SendToInboxJob).not_to have_received(:perform_async)
|
||||||
expect(QuestionWorker).not_to have_received(:perform_bulk)
|
expect(SendToInboxJob).not_to have_received(:perform_bulk)
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
include_examples "returns the expected response"
|
||||||
|
@ -209,7 +209,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
|
||||||
let(:expected_question_anonymous) { false }
|
let(:expected_question_anonymous) { false }
|
||||||
|
|
||||||
include_examples "creates the question", false
|
include_examples "creates the question", false
|
||||||
include_examples "enqueues QuestionWorker jobs"
|
include_examples "enqueues SendToInboxJob jobs"
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when anonymousQuestion is false" do
|
context "when anonymousQuestion is false" do
|
||||||
|
@ -217,7 +217,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
|
||||||
let(:expected_question_anonymous) { false }
|
let(:expected_question_anonymous) { false }
|
||||||
|
|
||||||
include_examples "creates the question", false
|
include_examples "creates the question", false
|
||||||
include_examples "enqueues QuestionWorker jobs"
|
include_examples "enqueues SendToInboxJob jobs"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -384,7 +384,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "does not enqueue a QuestionWorker job"
|
include_examples "does not enqueue a SendToInboxJob job"
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when rcpt is an invalid value" do
|
context "when rcpt is an invalid value" do
|
||||||
|
|
|
@ -29,7 +29,7 @@ describe UseCase::Question::CreateFollowers do
|
||||||
|
|
||||||
it "enqueues a QuestionWorker job" do
|
it "enqueues a QuestionWorker job" do
|
||||||
followers.each do |target_user|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue