From 05884acd19fe09baebc2d3cbc7a3b634c1fe07ec Mon Sep 17 00:00:00 2001 From: Anna Buianova Date: Tue, 14 Jan 2020 18:45:26 +0300 Subject: [PATCH] Fixed rubocop issues (#5506) --- spec/models/organization_spec.rb | 1 + spec/models/user_spec.rb | 159 ++++++++---------- .../comments/calculate_score_worker_spec.rb | 2 + .../send_email_notification_worker_spec.rb | 2 +- .../notifications/new_reaction_worker_spec.rb | 6 +- .../bust_cache_worker_spec.rb | 2 +- 6 files changed, 78 insertions(+), 94 deletions(-) diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index 178cf6cda..30b77e66a 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -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) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index cbbf050af..ef9ca7876 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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 diff --git a/spec/workers/comments/calculate_score_worker_spec.rb b/spec/workers/comments/calculate_score_worker_spec.rb index c7999d537..3652478ac 100644 --- a/spec/workers/comments/calculate_score_worker_spec.rb +++ b/spec/workers/comments/calculate_score_worker_spec.rb @@ -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 diff --git a/spec/workers/comments/send_email_notification_worker_spec.rb b/spec/workers/comments/send_email_notification_worker_spec.rb index d270b5f90..fe1642d9a 100644 --- a/spec/workers/comments/send_email_notification_worker_spec.rb +++ b/spec/workers/comments/send_email_notification_worker_spec.rb @@ -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) diff --git a/spec/workers/notifications/new_reaction_worker_spec.rb b/spec/workers/notifications/new_reaction_worker_spec.rb index 93a148953..115203a90 100644 --- a/spec/workers/notifications/new_reaction_worker_spec.rb +++ b/spec/workers/notifications/new_reaction_worker_spec.rb @@ -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 diff --git a/spec/workers/podcast_episodes/bust_cache_worker_spec.rb b/spec/workers/podcast_episodes/bust_cache_worker_spec.rb index 86831d0ea..052e03c3a 100644 --- a/spec/workers/podcast_episodes/bust_cache_worker_spec.rb +++ b/spec/workers/podcast_episodes/bust_cache_worker_spec.rb @@ -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) }