A platform for community discussion. Free, open, simple.
FIX: Support Ruby 3 keyword arguments
Yasuo Hondadbbfad7ed07c
diff --git a/app/models/theme.rb b/app/models/theme.rbindex 494e6fad35d..e6c81bb4e92 100644--- a/app/models/theme.rb+++ b/app/models/theme.rb@@ -679,10 +679,10 @@ class Theme < ActiveRecord::Basekeys = schema["items"]["properties"].keysreturn if !keys- current_values = CSV.parse(setting_row.value, { col_sep: '|' }).flatten+ current_values = CSV.parse(setting_row.value, **{ col_sep: '|' }).flattennew_values = []current_values.each do |item|- parts = CSV.parse(item, { col_sep: ',' }).flatten+ parts = CSV.parse(item, **{ col_sep: ',' }).flattenprops = parts.map.with_index { |p, idx| [keys[idx], p] }.to_hnew_values << propsenddiff --git a/app/views/about/index.html.erb b/app/views/about/index.html.erbindex 2caba687754..fc0e22a5c33 100644--- a/app/views/about/index.html.erb+++ b/app/views/about/index.html.erb@@ -2,7 +2,7 @@<section itemscope itemtype="https://schema.org/AboutPage"><h1 itemprop="name">- <%=t "js.about.title", {title: @about.title} %>+ <%=t "js.about.title", **{title: @about.title} %></h1><div itemprop="text">diff --git a/lib/discourse_redis.rb b/lib/discourse_redis.rbindex 45902dcac4b..341f3d131c5 100644--- a/lib/discourse_redis.rb+++ b/lib/discourse_redis.rb@@ -94,12 +94,12 @@ class DiscourseRedisendif block- @redis.scan_each(options) do |key|+ @redis.scan_each(**options) do |key|key = remove_namespace(key) if @namespaceblock.call(key)endelse- @redis.scan_each(options).map do |key|+ @redis.scan_each(**options).map do |key|key = remove_namespace(key) if @namespacekeyenddiff --git a/lib/seed_data/categories.rb b/lib/seed_data/categories.rbindex c4e2948bba4..b697b7ba84a 100644--- a/lib/seed_data/categories.rb+++ b/lib/seed_data/categories.rb@@ -21,7 +21,7 @@ module SeedDatacategories(site_setting_names).each do |params|params.slice!(:site_setting_name, :name, :description)params[:skip_changed] = skip_changed- update_category(params)+ update_category(**params)endendenddiff --git a/lib/seed_data/topics.rb b/lib/seed_data/topics.rbindex 03936ce4f69..7ebd2bda25b 100644--- a/lib/seed_data/topics.rb+++ b/lib/seed_data/topics.rb@@ -23,7 +23,7 @@ module SeedDatatopics(site_setting_names).each do |params|params.except!(:category, :after_create)params[:skip_changed] = skip_changed- update_topic(params)+ update_topic(**params)endendenddiff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rakeindex 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_lowend- post.rebake!(opts)+ post.rebake!(**opts)rescue => eputs "", "Failed to rebake (topic_id: #{post.topic_id}, post_id: #{post.id})", e, e.backtrace.join("\n")enddiff --git a/lib/upload_recovery.rb b/lib/upload_recovery.rbindex 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)endenddiff --git a/lib/validators/post_validator.rb b/lib/validators/post_validator.rbindex 8428bed8412..5a65d743f57 100644--- a/lib/validators/post_validator.rb+++ b/lib/validators/post_validator.rb@@ -20,11 +20,11 @@ class PostValidator < ActiveModel::Validatordef 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?endif post.new_record? && post.user_id.nil?- post.errors.add(:user_id, :blank, options)+ post.errors.add(:user_id, :blank, **options)endenddiff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rbindex 59f76e51413..2f4c26fcb3d 100644--- a/spec/requests/posts_controller_spec.rb+++ b/spec/requests/posts_controller_spec.rb@@ -72,7 +72,7 @@ endshared_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)endenddiff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex 456ab0ab4c1..281b3aeda42 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -3369,7 +3369,7 @@ RSpec.describe TopicsController doTopicTrackingState.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.reloadexpect(user.user_stat.new_since.to_date).not_to eq(old_date.to_date)@@ -3391,7 +3391,7 @@ RSpec.describe TopicsController doold_date = 2.years.agouser.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.reloadexpect(user.user_stat.new_since.to_date).to eq(old_date.to_date)@@ -3412,7 +3412,7 @@ RSpec.describe TopicsController docreate_post # This is a new post, but is not tracked so a record will not be created for itexpect 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])enddiff --git a/spec/requests/uploads_controller_spec.rb b/spec/requests/uploads_controller_spec.rbindex 8fbb68633e0..b142eed0f69 100644--- a/spec/requests/uploads_controller_spec.rb+++ b/spec/requests/uploads_controller_spec.rb@@ -742,7 +742,7 @@ describe UploadsController doendit "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 doit "returns 422 when the create request errors" doFileStore::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 doit "returns 422 when the file is an attachment and it's too big" doSiteSetting.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 doit "creates a multipart upload and creates an external upload stub that is marked as multipart" dostub_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.rbindex 718f779afb9..e5d707777c6 100644--- a/spec/services/user_authenticator_spec.rb+++ b/spec/services/user_authenticator_spec.rb@@ -50,7 +50,7 @@ describe UserAuthenticator doauthentication = github_auth(true)- UserAuthenticator.new(user, authentication: authentication).finish+ UserAuthenticator.new(user, { authentication: authentication }).finishexpect(user.email_confirmed?).to be_truthyexpect(group.usernames).to include(user.username)end@@ -60,7 +60,7 @@ describe UserAuthenticator doauthentication = github_auth(false)- UserAuthenticator.new(user, authentication: authentication).finish+ UserAuthenticator.new(user, { authentication: authentication }).finishexpect(user.email_confirmed?).to be_falseyexpect(group.usernames).not_to include(user.username)end@@ -70,7 +70,7 @@ describe UserAuthenticator doauthentication = github_auth(true)- UserAuthenticator.new(user, authentication: authentication).finish+ UserAuthenticator.new(user, { authentication: authentication }).finishexpect(user.email_confirmed?).to be_falseyexpect(group.usernames).not_to include(user.username)end