Fixed rubocop issues (#5506)

This commit is contained in:
Anna Buianova 2020-01-14 18:45:26 +03:00 committed by Molly Struve
parent 2d99ddba2d
commit 05884acd19
6 changed files with 78 additions and 94 deletions

View file

@ -112,6 +112,7 @@ RSpec.describe Organization, type: :model do
before do
allow(Organizations::BustCacheWorker).to receive(:perform_async)
end
it "triggers cache busting on save" do
organization.save
expect(Organizations::BustCacheWorker).to have_received(:perform_async).with(organization.id, organization.slug)

View file

@ -520,119 +520,100 @@ RSpec.describe User, type: :model do
describe "#conditionally_resave_articles" do
let!(:user) { create(:user) }
context "when changing username" do
it "enqueue resave articles job" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority"
) do
user.username = "#{user.username} changed"
user.save
end
it "enqueues resave articles job when changing username" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority",
) do
user.username = "#{user.username} changed"
user.save
end
end
context "when changing name" do
it "enqueue resave articles job" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority"
) do
user.name = "#{user.name} changed"
user.save
end
it "enqueues resave articles job when changing name" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority",
) do
user.name = "#{user.name} changed"
user.save
end
end
context "when changing summary" do
it "enqueue resave articles job" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority"
) do
user.summary = "#{user.summary} changed"
user.save
end
it "enqueues resave articles job when changing summary" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority",
) do
user.summary = "#{user.summary} changed"
user.save
end
end
context "when changing bg_color_hex" do
it "enqueue resave articles job" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority"
) do
user.bg_color_hex = "#12345F"
user.save
end
it "enqueues resave articles job when changing bg_color_hex" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority",
) do
user.bg_color_hex = "#12345F"
user.save
end
end
context "when changing text_color_hex" do
it "enqueue resave articles job" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority"
) do
user.text_color_hex = "#FA345E"
user.save
end
it "enqueues resave articles job when changing text_color_hex" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority",
) do
user.text_color_hex = "#FA345E"
user.save
end
end
context "when changing profile_image" do
it "enqueue resave articles job" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority"
) do
user.profile_image = "https://fakeimg.pl/300/"
user.save
end
it "enqueues resave articles job when changing profile_image" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority",
) do
user.profile_image = "https://fakeimg.pl/300/"
user.save
end
end
context "when changing github_username" do
it "enqueue resave articles job" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority"
) do
user.github_username = "mygreatgithubname"
user.save
end
it "enqueues resave articles job when changing github_username" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority",
) do
user.github_username = "mygreatgithubname"
user.save
end
end
context "when changing twitter_username" do
it "enqueue resave articles job" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority"
) do
user.twitter_username = "mygreattwittername"
user.save
end
it "enqueues resave articles job when changing twitter_username" do
sidekiq_assert_enqueued_with(
job: Users::ResaveArticlesWorker,
args: [user.id],
queue: "medium_priority",
) do
user.twitter_username = "mygreattwittername"
user.save
end
end
context "when changing resave attributes but user is banned" do
let!(:user) { create(:user, :banned) }
it "doesn't enqueue resave articles" do
expect do
user.twitter_username = "mygreattwittername"
user.save
end.to_not change(Users::ResaveArticlesWorker.jobs, :size)
end
it "doesn't enqueue resave articles when changing resave attributes but user is banned" do
banned_user = create(:user, :banned)
expect do
banned_user.twitter_username = "mygreattwittername"
banned_user.save
end.not_to change(Users::ResaveArticlesWorker.jobs, :size)
end
end
end

View file

@ -23,6 +23,7 @@ RSpec.describe Comments::CalculateScoreWorker, type: :worker do
expect(comment.spaminess_rating).to be(99)
end
# rubocop:disable RSpec/ExampleLength
it "calls save on the root comment when given a descendant comment" do
child_comment = double
root_comment = double
@ -39,6 +40,7 @@ RSpec.describe Comments::CalculateScoreWorker, type: :worker do
expect(child_comment).to have_received(:root)
expect(root_comment).to have_received(:save!)
end
# rubocop:enable RSpec/ExampleLength
it "does not call save on the root comment" do
root_comment = double

View file

@ -18,7 +18,7 @@ RSpec.describe Comments::SendEmailNotificationWorker, type: :worker do
allow(mailer).to receive(:deliver_now)
allow(NotifyMailer).to receive(:new_reply_email).and_return(mailer)
subject.perform(1)
worker.perform(1)
expect(NotifyMailer).to have_received(:new_reply_email).with(comment)
expect(mailer).to have_received(:deliver_now)

View file

@ -14,17 +14,17 @@ RSpec.describe Notifications::NewReactionWorker, type: :worker do
before { allow(reaction_service).to receive(:call) }
it "calls the service" do
subject.perform(reaction_data, receiver_data)
worker.perform(reaction_data, receiver_data)
allow(reaction_service).to receive(:call).with(reaction_data, org).once
end
it "doesn't call if is a receiver is of a wrong class" do
subject.perform(reaction_data, { klass: "Tag", id: 10 })
worker.perform(reaction_data, klass: "Tag", id: 10)
expect(reaction_service).not_to have_received(:call)
end
it "doesn't call if is a receiver doesn't exist" do
subject.perform(reaction_data, { klass: "Organization", id: nil })
worker.perform(reaction_data, klass: "Organization", id: nil)
expect(reaction_service).not_to have_received(:call)
end
end

View file

@ -15,7 +15,7 @@ RSpec.describe PodcastEpisodes::BustCacheWorker, type: :worker do
end
end
context "When podcast episode is found" do
context "when podcast episode is found" do
let(:podcast) { create(:podcast) }
let(:podcast_episode) { FactoryBot.create(:podcast_episode, podcast_id: podcast.id) }