From 022f36769241c9e0007a3db13b047830912e0abc Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Thu, 21 Jul 2022 00:04:58 +0200 Subject: [PATCH] Fix some keyword args for ruby 3 compatibility --- app/helpers/notifications_helper.rb | 6 +++--- app/mailers/report_mailer.rb | 2 +- app/presenters/base_presenter.rb | 8 ++++++-- features/support/application_cuke_helpers.rb | 2 +- features/support/paths.rb | 2 +- spec/lib/diaspora/federated/retraction_spec.rb | 6 +++--- spec/models/user/connecting_spec.rb | 2 +- spec/workers/mail/invite_email_spec.rb | 3 +-- 8 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index ffe10a951..6972d811c 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -20,11 +20,11 @@ module NotificationsHelper opts.merge!(opts_for_birthday(note)) end end - translation(target_type, opts) + translation(target_type, **opts) end - def translation(target_type, opts = {}) - t("#{target_type}", opts).html_safe + def translation(target_type, **kwargs) + t(target_type, **kwargs).html_safe # rubocop:disable Rails/OutputSafety end def opts_for_post(post) diff --git a/app/mailers/report_mailer.rb b/app/mailers/report_mailer.rb index ad69332fd..851635562 100644 --- a/app/mailers/report_mailer.rb +++ b/app/mailers/report_mailer.rb @@ -26,7 +26,7 @@ class ReportMailer < ApplicationMailer private def format(resource) - body = I18n.t("notifier.report_email.body", resource) + body = I18n.t("notifier.report_email.body", **resource) mail(to: resource[:email], subject: I18n.t("notifier.report_email.subject", type: resource[:type])) do |format| format.html { render "notifier/plain_markdown_email", locals: {body: body} } format.text { render "notifier/plain_markdown_email", locals: {body: body} } diff --git a/app/presenters/base_presenter.rb b/app/presenters/base_presenter.rb index 5a55d147f..d4eac8ce1 100644 --- a/app/presenters/base_presenter.rb +++ b/app/presenters/base_presenter.rb @@ -20,8 +20,12 @@ class BasePresenter @current_user = curr_user end - def method_missing(method, *args) - @presentable.public_send(method, *args) + def respond_to_missing?(method, include_private=false) + @presentable.respond_to?(method) || super + end + + def method_missing(method, *args, **kwargs) # rubocop:disable Lint/MissingSuper + @presentable.public_send(method, *args, **kwargs) end class NilPresenter diff --git a/features/support/application_cuke_helpers.rb b/features/support/application_cuke_helpers.rb index 7d1f92cc9..5d7e2b550 100644 --- a/features/support/application_cuke_helpers.rb +++ b/features/support/application_cuke_helpers.rb @@ -20,7 +20,7 @@ module ApplicationCukeHelpers def flash_message(opts={}) selector = opts.delete(:selector) selector &&= ".alert-#{selector}" - find(selector || ".flash-message", {match: :first}.merge(opts)) + find(selector || ".flash-message", **{match: :first}.merge(opts)) end def confirm_form_validation_error(element) diff --git a/features/support/paths.rb b/features/support/paths.rb index d6c7ff157..01cada463 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -63,7 +63,7 @@ module NavigationHelpers if path.is_a?(Hash) visit(path[:path]) await_elem = path[:special_elem] - find(await_elem.delete(:selector), await_elem) + find(await_elem.delete(:selector), **await_elem) else visit(path) end diff --git a/spec/lib/diaspora/federated/retraction_spec.rb b/spec/lib/diaspora/federated/retraction_spec.rb index 8da330007..cf459d245 100644 --- a/spec/lib/diaspora/federated/retraction_spec.rb +++ b/spec/lib/diaspora/federated/retraction_spec.rb @@ -71,7 +71,7 @@ describe Retraction do expect(Workers::DeferredRetraction).to receive(:perform_async).with( local_luke.id, "Retraction", federation_retraction.to_h.deep_stringify_keys, [remote_raphael.id], - "service_types" => [] + {"service_types" => []} ) retraction.defer_dispatch(local_luke) @@ -87,7 +87,7 @@ describe Retraction do expect(Workers::DeferredRetraction).to receive(:perform_async).with( alice.id, "Retraction", federation_retraction.to_h.deep_stringify_keys, [], - "service_types" => ["Services::Twitter"], "tweet_id" => "123" + {"service_types" => ["Services::Twitter"], "tweet_id" => "123"} ) retraction.defer_dispatch(alice) @@ -98,7 +98,7 @@ describe Retraction do federation_retraction = Diaspora::Federation::Entities.retraction(retraction) expect(Workers::DeferredRetraction).to receive(:perform_async).with( - alice.id, "Retraction", federation_retraction.to_h.deep_stringify_keys, [], "service_types" => [] + alice.id, "Retraction", federation_retraction.to_h.deep_stringify_keys, [], {"service_types" => []} ) retraction.defer_dispatch(alice) diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index e93b6936f..0dab12553 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -181,7 +181,7 @@ describe User::Connecting, type: :model do it "delivers profile for remote persons" do allow(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch) expect(Diaspora::Federation::Dispatcher) - .to receive(:defer_dispatch).with(alice, alice.profile, subscriber_ids: [remote_raphael.id]) + .to receive(:defer_dispatch).with(alice, alice.profile, {subscriber_ids: [remote_raphael.id]}) alice.share_with(remote_raphael, alice.aspects.first) end diff --git a/spec/workers/mail/invite_email_spec.rb b/spec/workers/mail/invite_email_spec.rb index 44e0cef79..2db2d9e4e 100644 --- a/spec/workers/mail/invite_email_spec.rb +++ b/spec/workers/mail/invite_email_spec.rb @@ -6,8 +6,7 @@ describe Workers::Mail::InviteEmail do let(:email_inviter) { double('EmailInviter') } it 'creates a new email inviter' do - expect(EmailInviter).to receive(:new).with(emails, alice, message: message) - .and_return(email_inviter) + expect(EmailInviter).to receive(:new).with(emails, alice, {message: message}).and_return(email_inviter) expect(email_inviter).to receive(:send!) Workers::Mail::InviteEmail.new.perform(emails, alice.id, message: message) end