From 75e135869e26a1aeae93f3334668de01c3bb2f69 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 9 Aug 2020 18:45:01 +0100 Subject: [PATCH] Fix Style/ExplicitBlockArgument warnings --- .rubocop_todo.yml | 9 --------- app/controllers/api/amf_controller.rb | 6 ++---- app/controllers/application_controller.rb | 12 ++++-------- app/mailers/notifier.rb | 6 ++---- test/integration/client_applications_test.rb | 12 ++++-------- 5 files changed, 12 insertions(+), 33 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4627479f5..18a5cf646 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -189,15 +189,6 @@ Rails/OutputSafety: Rails/TimeZone: Enabled: false -# Offense count: 6 -# Cop supports --auto-correct. -Style/ExplicitBlockArgument: - Exclude: - - 'app/controllers/api/amf_controller.rb' - - 'app/controllers/application_controller.rb' - - 'app/mailers/notifier.rb' - - 'test/integration/client_applications_test.rb' - # Offense count: 572 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. diff --git a/app/controllers/api/amf_controller.rb b/app/controllers/api/amf_controller.rb index c05a13098..fc8a304bb 100644 --- a/app/controllers/api/amf_controller.rb +++ b/app/controllers/api/amf_controller.rb @@ -128,11 +128,9 @@ module Api [-2, "An unusual error happened (in #{call}). The server said: #{e}"] end - def amf_handle_error_with_timeout(call, rootobj, rootid) + def amf_handle_error_with_timeout(call, rootobj, rootid, &block) amf_handle_error(call, rootobj, rootid) do - OSM::Timer.timeout(Settings.api_timeout, OSM::APITimeoutError) do - yield - end + OSM::Timer.timeout(Settings.api_timeout, OSM::APITimeoutError, &block) end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 68baa3115..3f6abc470 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -222,20 +222,16 @@ class ApplicationController < ActionController::Base ## # wrap an api call in a timeout - def api_call_timeout - OSM::Timer.timeout(Settings.api_timeout, Timeout::Error) do - yield - end + def api_call_timeout(&block) + OSM::Timer.timeout(Settings.api_timeout, Timeout::Error, &block) rescue Timeout::Error raise OSM::APITimeoutError end ## # wrap a web page in a timeout - def web_timeout - OSM::Timer.timeout(Settings.web_timeout, Timeout::Error) do - yield - end + def web_timeout(&block) + OSM::Timer.timeout(Settings.web_timeout, Timeout::Error, &block) rescue ActionView::Template::Error => e e = e.cause diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 3c794cca9..3e0ba446d 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -202,10 +202,8 @@ class Notifier < ApplicationMailer end end - def with_recipient_locale(recipient) - I18n.with_locale Locale.available.preferred(recipient.preferred_languages) do - yield - end + def with_recipient_locale(recipient, &block) + I18n.with_locale(Locale.available.preferred(recipient.preferred_languages), &block) end def from_address(name, type, id, digest, user_id = nil) diff --git a/test/integration/client_applications_test.rb b/test/integration/client_applications_test.rb index b50a990c6..4c3e9df47 100644 --- a/test/integration/client_applications_test.rb +++ b/test/integration/client_applications_test.rb @@ -78,17 +78,13 @@ class ClientApplicationsTest < ActionDispatch::IntegrationTest ## # utility method to make the HTML screening easier to read. - def assert_in_heading - assert_select "div.content-heading" do - yield - end + def assert_in_heading(&block) + assert_select("div.content-heading", &block) end ## # utility method to make the HTML screening easier to read. - def assert_in_body - assert_select "div#content" do - yield - end + def assert_in_body(&block) + assert_select("div#content", &block) end end -- 2.39.5