Fix Ruby 2.7 kwargs' warnings & misc spec warnings (#13256)

This commit is contained in:
Mac Siri 2021-04-06 16:57:59 -04:00 committed by GitHub
parent 9c54b7c7b7
commit aed41c3238
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 69 additions and 49 deletions

View file

@ -166,7 +166,7 @@ group :test do
gem "shoulda-matchers", "~> 4.5.1", require: false # Simple one-liner tests for common Rails functionality
gem "simplecov", "~> 0.21.2", require: false # Code coverage with a powerful configuration library and automatic merging of coverage across test suites
gem "stackprof", "~> 0.2", require: false, platforms: :ruby # stackprof is a fast sampling profiler for ruby code, with cpu, wallclock and object allocation samplers
gem "stripe-ruby-mock", "~> 3.0", require: "stripe_mock" # A drop-in library to test stripe without hitting their servers
gem "stripe-ruby-mock", "3.1.0.rc2", require: "stripe_mock" # A drop-in library to test stripe without hitting their servers
gem "test-prof", "~> 1.0" # Ruby Tests Profiling Toolbox
gem "timecop", "~> 0.9" # A gem providing "time travel" and "time freezing" capabilities, making it dead simple to test time-dependent code
gem "vcr", "~> 6.0" # Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests

View file

@ -760,7 +760,7 @@ GEM
activerecord (>= 4.0, < 6.2)
virtus
stripe (5.32.1)
stripe-ruby-mock (3.0.1)
stripe-ruby-mock (3.1.0.rc2)
dante (>= 0.2.0)
multi_json (~> 1.0)
stripe (> 5, < 6)
@ -979,7 +979,7 @@ DEPENDENCIES
store_attribute (~> 0.8.1)
storext (~> 3.3)
stripe (~> 5.32)
stripe-ruby-mock (~> 3.0)
stripe-ruby-mock (= 3.1.0.rc2)
strong_migrations (~> 0.7)
test-prof (~> 1.0)
timecop (~> 0.9)

View file

@ -62,7 +62,7 @@ module Api
.per(num)
.decorate
render("api/v0/articles/index")
render "api/v0/articles/index", formats: :json
end
private

View file

@ -14,7 +14,7 @@ class ChatChannelsController < ApplicationController
when "unopened"
authorize ChatChannel
@chat_channels_memberships = unopened_json_response
render "index.json"
render "index", formats: :json
when "unopened_ids"
authorize ChatChannel
@unopened_ids = unopened_ids_response
@ -22,11 +22,11 @@ class ChatChannelsController < ApplicationController
when "pending"
authorize ChatChannel
@chat_channels_memberships = pending_json_response
render "index.json"
render "index", formats: :json
when "joining_request"
authorize ChatChannel
@chat_channels_memberships = joining_request_json_response
render "index.json"
render "index", formats: :json
else
skip_authorization
render_channels_html

View file

@ -79,7 +79,7 @@ class CommentsController < ApplicationController
return
end
render partial: "comments/comment.json"
render partial: "comments/comment", formats: :json
elsif (comment = Comment.where(
body_markdown: @comment.body_markdown,

View file

@ -24,7 +24,7 @@ class GithubReposController < ApplicationController
return
end
repo = GithubRepo.upsert(current_user, fetched_repo_params(fetched_repo))
repo = GithubRepo.upsert(current_user, **fetched_repo_params(fetched_repo))
current_user.touch(:github_repos_updated_at)

View file

@ -76,7 +76,7 @@ module ApplicationHelper
def optimized_image_tag(image_url, optimizer_options: {}, image_options: {})
image_options[:width] ||= optimizer_options[:width]
image_options[:height] ||= optimizer_options[:height]
updated_image_url = Images::Optimizer.call(image_url, optimizer_options)
updated_image_url = Images::Optimizer.call(image_url, **optimizer_options)
image_tag(updated_image_url, image_options)
end

View file

@ -58,6 +58,6 @@ module ArticlesHelper
end
def active_threads(**options)
Articles::ActiveThreadsQuery.call(options)
Articles::ActiveThreadsQuery.call(**options)
end
end

View file

@ -18,7 +18,7 @@ module SocialImageHelper
end
def article_social_image_url(article, **options)
Articles::SocialImage.new(article, options).url
Articles::SocialImage.new(article, **options).url
end
def comment_social_image_url(comment)

View file

@ -21,11 +21,11 @@ class ApplicationMailer < ActionMailer::Base
end
def generate_unsubscribe_token(id, email_type)
Rails.application.message_verifier(:unsubscribe).generate(
user_id: id,
email_type: email_type.to_sym,
expires_at: 31.days.from_now,
)
Rails.application.message_verifier(:unsubscribe).generate({
user_id: id,
email_type: email_type.to_sym,
expires_at: 31.days.from_now
})
end
def use_custom_host

View file

@ -8,7 +8,7 @@ module Articles
MINIMUM_SCORE = -4
def self.call(relation: Article.published, options: {})
def self.call(relation: Article.published, **options)
options = DEFAULT_OPTIONS.merge(options)
tags, time_ago, count = options.values_at(:tags, :time_ago, :count)

View file

@ -2,7 +2,7 @@
<div id="sidebar-wrapper-right" class="sidebar-wrapper sidebar-wrapper-right">
<div class="sidebar-bg" id="sidebar-bg-right"></div>
<div class="side-bar sidebar-additional showing" id="sidebar-additional">
<% active_threads = active_threads(options: { tags: [@tag, "discuss"], time_ago: Timeframe.datetime(params[:timeframe]) }) %>
<% active_threads = active_threads(tags: [@tag, "discuss"], time_ago: Timeframe.datetime(params[:timeframe])) %>
<% if active_threads.present? %>
<div class="widget">
<header>

View file

@ -1,5 +1,11 @@
Rails.application.config.to_prepare do
Dir.glob(Rails.root.join("lib/slack/notifier/util/*.rb")).each do |filename|
require_dependency filename
end
end
class NoOpHTTPClient
def self.post(uri, **kwargs)
def self.post(uri, kwargs = {})
# bonus, you could log or observe posted params here
end
end

View file

@ -0,0 +1,13 @@
module Slack
class Notifier
module Util
class LinkFormatter
class << self
def format string, opts={}
LinkFormatter.new(string, **opts).formatted
end
end
end
end
end
end

View file

@ -59,12 +59,12 @@ RSpec.describe GithubRepo, type: :model do
it "creates a new repo" do
expect do
described_class.upsert(user, params)
described_class.upsert(user, **params)
end.to change(described_class, :count).by(1)
end
it "creates a repo for the given user" do
repo = described_class.upsert(user, params)
repo = described_class.upsert(user, **params)
expect(repo.user_id).to eq(user.id)
end

View file

@ -34,7 +34,7 @@ RSpec.describe Articles::ActiveThreadsQuery, type: :query do
create(:article, published_at: time - 2.days, comments_count: 30, tags: "discuss",
score: described_class::MINIMUM_SCORE)
result = described_class.call(options: { tags: "discuss", time_ago: time, count: 10 })
result = described_class.call(tags: "discuss", time_ago: time, count: 10)
expect(result.length).to eq(2)
expect(result.first.first).to eq(article.path)
end
@ -45,7 +45,7 @@ RSpec.describe Articles::ActiveThreadsQuery, type: :query do
score: described_class::MINIMUM_SCORE)
create(:article, comments_count: 10, tags: "discuss", score: described_class::MINIMUM_SCORE - 10)
result = described_class.call(options: { tags: "discuss", time_ago: time, count: 10 })
result = described_class.call(tags: "discuss", time_ago: time, count: 10)
expect(result.length).to eq(2)
expect(result.first.first).to eq(article.path)
end
@ -57,7 +57,7 @@ RSpec.describe Articles::ActiveThreadsQuery, type: :query do
score: described_class::MINIMUM_SCORE)
create(:article, last_comment_at: nil, tags: "discuss", score: described_class::MINIMUM_SCORE)
result = described_class.call(options: { tags: "discuss", time_ago: nil, count: 10 })
result = described_class.call(tags: "discuss", time_ago: nil, count: 10)
expect(result.length).to eq(2)
expect(result.first.first).to eq(article.path)
end
@ -67,7 +67,7 @@ RSpec.describe Articles::ActiveThreadsQuery, type: :query do
score: described_class::MINIMUM_SCORE - 10)
create(:article, last_comment_at: 2.days.ago, tags: "discuss", score: described_class::MINIMUM_SCORE - 10)
result = described_class.call(options: { tags: "discuss", time_ago: nil, count: 10 })
result = described_class.call(tags: "discuss", time_ago: nil, count: 10)
expect(result.length).to eq(2)
expect(result.first.first).to eq(article.path)
end

View file

@ -252,7 +252,7 @@ RSpec.describe "Api::V0::Listings", type: :request do
include_context "when param list is valid"
it "fails to create a listing if user does not have enough credit" do
post_listing(listing_params)
post_listing(**listing_params)
expect(response).to have_http_status(:payment_required)
end
@ -284,7 +284,7 @@ RSpec.describe "Api::V0::Listings", type: :request do
end
it "fails if body_markdown is missing" do
post_listing(invalid_params)
post_listing(**invalid_params)
expect(response).to have_http_status(:unprocessable_entity)
end
@ -302,7 +302,7 @@ RSpec.describe "Api::V0::Listings", type: :request do
it "does not subtract credits or create a listing if the listing is not valid" do
expect do
post_listing(invalid_params)
post_listing(**invalid_params)
end.to change(Listing, :count).by(0).and change(user.credits.spent, :size).by(0)
end
end
@ -313,7 +313,7 @@ RSpec.describe "Api::V0::Listings", type: :request do
include_context "when user has enough credit"
it "properly deducts the amount of credits" do
post_listing(listing_params)
post_listing(**listing_params)
expect(response).to have_http_status(:created)
expect(user.credits.spent.size).to eq(cfp_category.cost)
@ -330,14 +330,14 @@ RSpec.describe "Api::V0::Listings", type: :request do
it "creates a listing under the org" do
org = user_admin_organization(user)
Credit.create(organization_id: org.id)
post_listing(listing_params.merge(organization_id: org.id))
post_listing(**listing_params.merge(organization_id: org.id))
expect(Listing.first.organization_id).to eq org.id
end
it "does not create a listing draft for an org not belonging to the user" do
org = create(:organization)
expect do
post_listing(draft_params.merge(organization_id: org.id))
post_listing(**draft_params.merge(organization_id: org.id))
expect(response).to have_http_status(:unauthorized)
end.to change(Listing, :count).by(0)
end
@ -345,13 +345,13 @@ RSpec.describe "Api::V0::Listings", type: :request do
it "does not create a listing for an org not belonging to the user" do
org = create(:organization)
expect do
post_listing(listing_params.merge(organization_id: org.id))
post_listing(**listing_params.merge(organization_id: org.id))
expect(response).to have_http_status(:unauthorized)
end.to change(Listing, :count).by(0)
end
it "assigns the spent credits to the listing" do
post_listing(listing_params)
post_listing(**listing_params)
spent_credit = user.credits.spent.last
expect(spent_credit.purchase_type).to eq("Listing")
expect(spent_credit.spent_at).not_to be_nil
@ -359,7 +359,7 @@ RSpec.describe "Api::V0::Listings", type: :request do
it "cannot create a draft due to internal error" do
allow(Organization).to receive(:find_by)
post_listing(draft_params.except(:category))
post_listing(**draft_params.except(:category))
expect(response.parsed_body.dig("errors", "listing_category").first)
.to match(/must exist/)
expect(response).to have_http_status(:unprocessable_entity)
@ -368,7 +368,7 @@ RSpec.describe "Api::V0::Listings", type: :request do
it "creates listing draft and does not subtract credits" do
allow(Credits::Buyer).to receive(:call).and_raise(ActiveRecord::Rollback)
expect do
post_listing(draft_params)
post_listing(**draft_params)
end.to change(Listing, :count).by(1)
.and change(user.credits.spent, :size).by(0)
end
@ -376,14 +376,14 @@ RSpec.describe "Api::V0::Listings", type: :request do
it "does not create a listing or subtract credits if the purchase does not go through" do
allow(Credits::Buyer).to receive(:call).and_raise(ActiveRecord::Rollback)
expect do
post_listing(listing_params)
post_listing(**listing_params)
end.to change(Listing, :count).by(0)
.and change(user.credits.spent, :size).by(0)
end
it "creates a listing belonging to the user" do
expect do
post_listing(listing_params)
post_listing(**listing_params)
expect(response).to have_http_status(:created)
end.to change(Listing, :count).by(1)
expect(Listing.find(response.parsed_body["id"]).user).to eq(user)
@ -391,7 +391,7 @@ RSpec.describe "Api::V0::Listings", type: :request do
it "creates a listing with a title, a body markdown, a category" do
expect do
post_listing(listing_params)
post_listing(**listing_params)
expect(response).to have_http_status(:created)
end.to change(Listing, :count).by(1)
@ -405,7 +405,7 @@ RSpec.describe "Api::V0::Listings", type: :request do
it "creates a listing with a location" do
params = listing_params.merge(location: "Frejus")
expect do
post_listing(params)
post_listing(**params)
expect(response).to have_http_status(:created)
end.to change(Listing, :count).by(1)
expect(Listing.find(response.parsed_body["id"]).location).to eq("Frejus")
@ -414,7 +414,7 @@ RSpec.describe "Api::V0::Listings", type: :request do
it "creates a listing with a list of tags and a contact" do
params = listing_params.merge(tags: %w[discuss javascript], contact_via_connect: true)
expect do
post_listing(params)
post_listing(**params)
expect(response).to have_http_status(:created)
end.to change(Listing, :count).by(1)

View file

@ -8,11 +8,11 @@ RSpec.describe "EmailSubscriptions", type: :request do
end
def generate_token(user_id)
Rails.application.message_verifier(:unsubscribe).generate(
user_id: user_id,
email_type: :email_mention_notifications,
expires_at: 31.days.from_now,
)
Rails.application.message_verifier(:unsubscribe).generate({
user_id: user_id,
email_type: :email_mention_notifications,
expires_at: 31.days.from_now
})
end
describe "GET /email_subscriptions/unsubscribe" do

View file

@ -202,14 +202,14 @@ RSpec.describe "UserProfiles", type: :request do
end
it "renders emoji in description of featured repository" do
GithubRepo.upsert(github_user, params)
GithubRepo.upsert(github_user, **params)
get "/#{github_user.username}"
expect(response.body).to include("A book bot 🤖")
end
it "does not show a non featured repository" do
GithubRepo.upsert(github_user, params.merge(featured: false))
GithubRepo.upsert(github_user, **params.merge(featured: false))
get "/#{github_user.username}"
expect(response.body).not_to include("A book bot 🤖")

View file

@ -12,6 +12,7 @@ RSpec.describe "viewing podcast comments", type: :system, js: true do
end
it "renders comment" do
# TODO: this spec is broken
expect(page).to have_content(comment.body_html)
end
end

View file

@ -68,7 +68,7 @@ describe ArticleImageUploader, type: :uploader do
end
it "raises a CarrierWave error which can be parsed if MiniMagick timeout occurs" do
allow(MiniMagick::Image).to receive(:new).and_raise(TimeoutError)
allow(MiniMagick::Image).to receive(:new).and_raise(Timeout::Error)
expect { uploader.store!(image_jpg) }.to raise_error(CarrierWave::IntegrityError, /Image processing timed out/)
end

Binary file not shown.

Binary file not shown.