run Rubocop
This commit is contained in:
parent
7ccad7bfab
commit
f0d26a1555
|
@ -1,40 +1,42 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require "rails_helper"
|
||||||
|
|
||||||
describe ShareWorker do
|
describe ShareWorker do
|
||||||
let(:user) { FactoryBot.create(:user) }
|
let(:user) { FactoryBot.create(:user) }
|
||||||
let(:answer) { FactoryBot.create(:answer, user: user) }
|
let(:answer) { FactoryBot.create(:answer, user: user) }
|
||||||
let!(:service) { Services::Twitter.create!(type: 'Services::Twitter',
|
let!(:service) do
|
||||||
user: user) }
|
Services::Twitter.create!(type: "Services::Twitter",
|
||||||
|
user: user)
|
||||||
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_const("APP_CONFIG", {
|
stub_const("APP_CONFIG", {
|
||||||
'hostname' => 'example.com',
|
"hostname" => "example.com",
|
||||||
'anonymous_name' => 'Anonymous',
|
"anonymous_name" => "Anonymous",
|
||||||
'https' => true,
|
"https" => true,
|
||||||
'items_per_page' => 5,
|
"items_per_page" => 5,
|
||||||
'sharing' => {
|
"sharing" => {
|
||||||
'twitter' => {
|
"twitter" => {
|
||||||
'consumer_key' => '',
|
"consumer_key" => ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#perform" do
|
describe "#perform" do
|
||||||
before do
|
before do
|
||||||
allow(Sidekiq.logger).to receive(:info)
|
allow(Sidekiq.logger).to receive(:info)
|
||||||
end
|
end
|
||||||
|
|
||||||
subject do
|
subject do
|
||||||
Sidekiq::Testing.fake! do
|
Sidekiq::Testing.fake! do
|
||||||
ShareWorker.perform_async(user.id, answer.id, 'twitter')
|
ShareWorker.perform_async(user.id, answer.id, "twitter")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when answer doesn\'t exist' do
|
context "when answer doesn't exist" do
|
||||||
it 'prevents the job from retrying and logs a message' do
|
it "prevents the job from retrying and logs a message" do
|
||||||
answer.destroy!
|
answer.destroy!
|
||||||
expect { subject }.to change(ShareWorker.jobs, :size).by(1)
|
expect { subject }.to change(ShareWorker.jobs, :size).by(1)
|
||||||
expect { ShareWorker.drain }.to change(ShareWorker.jobs, :size).by(-1)
|
expect { ShareWorker.drain }.to change(ShareWorker.jobs, :size).by(-1)
|
||||||
|
@ -42,22 +44,22 @@ describe ShareWorker do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when answer exists' do
|
context "when answer exists" do
|
||||||
it 'handles Twitter::Error::DuplicateStatus' do
|
it "handles Twitter::Error::DuplicateStatus" do
|
||||||
allow_any_instance_of(Services::Twitter).to receive(:post).with(answer).and_raise(Twitter::Error::DuplicateStatus)
|
allow_any_instance_of(Services::Twitter).to receive(:post).with(answer).and_raise(Twitter::Error::DuplicateStatus)
|
||||||
subject
|
subject
|
||||||
ShareWorker.drain
|
ShareWorker.drain
|
||||||
expect(Sidekiq.logger).to have_received(:info).with("Tried to post answer ##{answer.id} from user ##{user.id} to Twitter but the status was already posted.")
|
expect(Sidekiq.logger).to have_received(:info).with("Tried to post answer ##{answer.id} from user ##{user.id} to Twitter but the status was already posted.")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles Twitter::Error::Unauthorized' do
|
it "handles Twitter::Error::Unauthorized" do
|
||||||
allow_any_instance_of(Services::Twitter).to receive(:post).with(answer).and_raise(Twitter::Error::Unauthorized)
|
allow_any_instance_of(Services::Twitter).to receive(:post).with(answer).and_raise(Twitter::Error::Unauthorized)
|
||||||
subject
|
subject
|
||||||
ShareWorker.drain
|
ShareWorker.drain
|
||||||
expect(Sidekiq.logger).to have_received(:info).with("Tried to post answer ##{answer.id} from user ##{user.id} to Twitter but the token has exired or been revoked.")
|
expect(Sidekiq.logger).to have_received(:info).with("Tried to post answer ##{answer.id} from user ##{user.id} to Twitter but the token has exired or been revoked.")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'retries on unhandled exceptions' do
|
it "retries on unhandled exceptions" do
|
||||||
expect { subject }.to change(ShareWorker.jobs, :size).by(1)
|
expect { subject }.to change(ShareWorker.jobs, :size).by(1)
|
||||||
expect { ShareWorker.drain }.to raise_error(Twitter::Error::BadRequest)
|
expect { ShareWorker.drain }.to raise_error(Twitter::Error::BadRequest)
|
||||||
expect(Sidekiq.logger).to have_received(:info)
|
expect(Sidekiq.logger).to have_received(:info)
|
||||||
|
|
Loading…
Reference in New Issue