From dbbfad7ed07c47674f9dee4ac7021ca51cc04e2e Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Mon, 27 Sep 2021 21:45:05 +0900 Subject: [PATCH] FIX: Support Ruby 3 keyword arguments --- app/models/theme.rb | 4 ++-- app/views/about/index.html.erb | 2 +- lib/discourse_redis.rb | 4 ++-- lib/seed_data/categories.rb | 2 +- lib/seed_data/topics.rb | 2 +- lib/tasks/posts.rake | 2 +- lib/upload_recovery.rb | 4 ++-- lib/validators/post_validator.rb | 4 ++-- spec/requests/posts_controller_spec.rb | 2 +- spec/requests/topics_controller_spec.rb | 6 +++--- spec/requests/uploads_controller_spec.rb | 10 +++++----- spec/services/user_authenticator_spec.rb | 6 +++--- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/models/theme.rb b/app/models/theme.rb index 494e6fad35d..e6c81bb4e92 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -679,10 +679,10 @@ class Theme < ActiveRecord::Base keys = schema["items"]["properties"].keys return if !keys - current_values = CSV.parse(setting_row.value, { col_sep: '|' }).flatten + current_values = CSV.parse(setting_row.value, **{ col_sep: '|' }).flatten new_values = [] current_values.each do |item| - parts = CSV.parse(item, { col_sep: ',' }).flatten + parts = CSV.parse(item, **{ col_sep: ',' }).flatten props = parts.map.with_index { |p, idx| [keys[idx], p] }.to_h new_values << props end diff --git a/app/views/about/index.html.erb b/app/views/about/index.html.erb index 2caba687754..fc0e22a5c33 100644 --- a/app/views/about/index.html.erb +++ b/app/views/about/index.html.erb @@ -2,7 +2,7 @@

- <%=t "js.about.title", {title: @about.title} %> + <%=t "js.about.title", **{title: @about.title} %>

diff --git a/lib/discourse_redis.rb b/lib/discourse_redis.rb index 45902dcac4b..341f3d131c5 100644 --- a/lib/discourse_redis.rb +++ b/lib/discourse_redis.rb @@ -94,12 +94,12 @@ class DiscourseRedis end if block - @redis.scan_each(options) do |key| + @redis.scan_each(**options) do |key| key = remove_namespace(key) if @namespace block.call(key) end else - @redis.scan_each(options).map do |key| + @redis.scan_each(**options).map do |key| key = remove_namespace(key) if @namespace key end diff --git a/lib/seed_data/categories.rb b/lib/seed_data/categories.rb index c4e2948bba4..b697b7ba84a 100644 --- a/lib/seed_data/categories.rb +++ b/lib/seed_data/categories.rb @@ -21,7 +21,7 @@ module SeedData categories(site_setting_names).each do |params| params.slice!(:site_setting_name, :name, :description) params[:skip_changed] = skip_changed - update_category(params) + update_category(**params) end end end diff --git a/lib/seed_data/topics.rb b/lib/seed_data/topics.rb index 03936ce4f69..7ebd2bda25b 100644 --- a/lib/seed_data/topics.rb +++ b/lib/seed_data/topics.rb @@ -23,7 +23,7 @@ module SeedData topics(site_setting_names).each do |params| params.except!(:category, :after_create) params[:skip_changed] = skip_changed - update_topic(params) + update_topic(**params) end end end diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake index 4abfaf01a6c..955fa97d8b6 100644 --- a/lib/tasks/posts.rake +++ b/lib/tasks/posts.rake @@ -137,7 +137,7 @@ def rebake_post(post, opts = {}) if !opts[:priority] opts[:priority] = :ultra_low end - post.rebake!(opts) + post.rebake!(**opts) rescue => e puts "", "Failed to rebake (topic_id: #{post.topic_id}, post_id: #{post.id})", e, e.backtrace.join("\n") end diff --git a/lib/upload_recovery.rb b/lib/upload_recovery.rb index 9092ee03f96..04f5ea93704 100644 --- a/lib/upload_recovery.rb +++ b/lib/upload_recovery.rb @@ -60,9 +60,9 @@ class UploadRecovery } if Discourse.store.external? - recover_post_upload_from_s3(attributes) + recover_post_upload_from_s3(**attributes) else - recover_post_upload_from_local(attributes) + recover_post_upload_from_local(**attributes) end end diff --git a/lib/validators/post_validator.rb b/lib/validators/post_validator.rb index 8428bed8412..5a65d743f57 100644 --- a/lib/validators/post_validator.rb +++ b/lib/validators/post_validator.rb @@ -20,11 +20,11 @@ class PostValidator < ActiveModel::Validator def presence(post) unless options[:skip_topic] - post.errors.add(:topic_id, :blank, options) if post.topic_id.blank? + post.errors.add(:topic_id, :blank, **options) if post.topic_id.blank? end if post.new_record? && post.user_id.nil? - post.errors.add(:user_id, :blank, options) + post.errors.add(:user_id, :blank, **options) end end diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rb index 59f76e51413..2f4c26fcb3d 100644 --- a/spec/requests/posts_controller_spec.rb +++ b/spec/requests/posts_controller_spec.rb @@ -72,7 +72,7 @@ end shared_examples 'action requires login' do |method, url, params = {}| it 'raises an exception when not logged in' do - self.public_send(method, url, params) + self.public_send(method, url, **params) expect(response.status).to eq(403) end end diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 456ab0ab4c1..281b3aeda42 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -3369,7 +3369,7 @@ RSpec.describe TopicsController do TopicTrackingState.expects(:publish_dismiss_new).with(user.id, topic_ids: [topic2.id, topic3.id]).at_least_once - put "/topics/reset-new.json", { params: { topic_ids: [topic2.id, topic3.id] } } + put "/topics/reset-new.json", **{ params: { topic_ids: [topic2.id, topic3.id] } } expect(response.status).to eq(200) user.reload expect(user.user_stat.new_since.to_date).not_to eq(old_date.to_date) @@ -3391,7 +3391,7 @@ RSpec.describe TopicsController do old_date = 2.years.ago user.user_stat.update_column(:new_since, old_date) - put "/topics/reset-new.json?tracked=true", { params: { topic_ids: [topic2.id, topic3.id] } } + put "/topics/reset-new.json?tracked=true", **{ params: { topic_ids: [topic2.id, topic3.id] } } expect(response.status).to eq(200) user.reload expect(user.user_stat.new_since.to_date).to eq(old_date.to_date) @@ -3412,7 +3412,7 @@ RSpec.describe TopicsController do create_post # This is a new post, but is not tracked so a record will not be created for it expect do - put "/topics/reset-new.json?tracked=true", { params: { topic_ids: [tracked_topic.id, topic2.id, topic3.id] } } + put "/topics/reset-new.json?tracked=true", **{ params: { topic_ids: [tracked_topic.id, topic2.id, topic3.id] } } end.to change { DismissedTopicUser.where(user_id: user.id).count }.by(2) expect(DismissedTopicUser.where(user_id: user.id).pluck(:topic_id)).to match_array([tracked_topic.id, topic2.id]) end diff --git a/spec/requests/uploads_controller_spec.rb b/spec/requests/uploads_controller_spec.rb index 8fbb68633e0..b142eed0f69 100644 --- a/spec/requests/uploads_controller_spec.rb +++ b/spec/requests/uploads_controller_spec.rb @@ -742,7 +742,7 @@ describe UploadsController do end it "includes accepted metadata in the presigned url when provided" do - post "/uploads/generate-presigned-put.json", { + post "/uploads/generate-presigned-put.json", **{ params: { file_name: "test.png", file_size: 1024, @@ -806,7 +806,7 @@ describe UploadsController do it "returns 422 when the create request errors" do FileStore::S3Store.any_instance.stubs(:create_multipart).raises(Aws::S3::Errors::ServiceError.new({}, "test")) - post "/uploads/create-multipart.json", { + post "/uploads/create-multipart.json", **{ params: { file_name: "test.png", file_size: 1024, @@ -818,7 +818,7 @@ describe UploadsController do it "returns 422 when the file is an attachment and it's too big" do SiteSetting.max_attachment_size_kb = 1024 - post "/uploads/create-multipart.json", { + post "/uploads/create-multipart.json", **{ params: { file_name: "test.zip", file_size: 9999999, @@ -846,7 +846,7 @@ describe UploadsController do it "creates a multipart upload and creates an external upload stub that is marked as multipart" do stub_create_multipart_request - post "/uploads/create-multipart.json", { + post "/uploads/create-multipart.json", **{ params: { file_name: "test.png", file_size: 1024, @@ -879,7 +879,7 @@ describe UploadsController do "test.png", "image/png", metadata: { "sha1-checksum" => "testing" } ).returns({ key: "test" }) - post "/uploads/create-multipart.json", { + post "/uploads/create-multipart.json", **{ params: { file_name: "test.png", file_size: 1024, diff --git a/spec/services/user_authenticator_spec.rb b/spec/services/user_authenticator_spec.rb index 718f779afb9..e5d707777c6 100644 --- a/spec/services/user_authenticator_spec.rb +++ b/spec/services/user_authenticator_spec.rb @@ -50,7 +50,7 @@ describe UserAuthenticator do authentication = github_auth(true) - UserAuthenticator.new(user, authentication: authentication).finish + UserAuthenticator.new(user, { authentication: authentication }).finish expect(user.email_confirmed?).to be_truthy expect(group.usernames).to include(user.username) end @@ -60,7 +60,7 @@ describe UserAuthenticator do authentication = github_auth(false) - UserAuthenticator.new(user, authentication: authentication).finish + UserAuthenticator.new(user, { authentication: authentication }).finish expect(user.email_confirmed?).to be_falsey expect(group.usernames).not_to include(user.username) end @@ -70,7 +70,7 @@ describe UserAuthenticator do authentication = github_auth(true) - UserAuthenticator.new(user, authentication: authentication).finish + UserAuthenticator.new(user, { authentication: authentication }).finish expect(user.email_confirmed?).to be_falsey expect(group.usernames).not_to include(user.username) end