Maintenance: Treat Ruby deprecation warnings as test errors.

This commit is contained in:
Martin Gruner 2021-07-06 07:52:22 +00:00 committed by Thorsten Eckel
parent 697661cbf2
commit 33a5f470e0
22 changed files with 57 additions and 46 deletions

View file

@ -146,7 +146,7 @@ class FormController < ApplicationController
# we don't wann to tell what the cause for the authorization error is
# so we capture the exception and raise an anonymized one
def authorize!(*)
def authorize!(...)
super
rescue Pundit::NotAuthorizedError
raise Exceptions::Forbidden

View file

@ -95,8 +95,9 @@ class TicketsController < ApplicationController
clean_params[:customer_id] = current_user.id
end
# try to create customer if needed
if clean_params[:customer_id].present? && clean_params[:customer_id] =~ %r{^guess:(.+?)$}
# The parameter :customer_id is 'abused' in cases where it is not an integer, but a string like
# 'guess:customers.email@domain.com' which implies that the customer should be looked up.
if clean_params[:customer_id].is_a?(String) && clean_params[:customer_id] =~ %r{^guess:(.+?)$}
email_address = $1
email_address_validation = EmailAddressValidation.new(email_address)
if !email_address_validation.valid_format?

View file

@ -13,7 +13,7 @@ class ApplicationJob
class LogSubscriber < ActiveJob::Logging::LogSubscriber
# ATTENTION: Uncomment this line to enable info logging again
def info(*); end
def info(...); end
def enqueue(event)
super if job_enqueued?(event)

View file

@ -41,7 +41,7 @@ returns
raise ArgumentError, 'Need name, login, email or locale for create_or_update()' if attr.nil?
record = case_sensitive_find_by(data.slice(attr))
record = case_sensitive_find_by(**data.slice(attr))
record.nil? ? create(data) : record.tap { |r| r.update(data) }
end

View file

@ -5,7 +5,7 @@ class Channel::Driver::Null
false
end
def fetch(*)
def fetch(...)
{
result: 'ok',
fetched: 0,

View file

@ -59,7 +59,7 @@ returns
raise Exceptions::UnprocessableEntity, "Unable to read file '#{data[:file]}': #{e.inspect}"
end
header, *rows = ::CSV.parse(data[:string], data[:parse_params])
header, *rows = ::CSV.parse(data[:string], **data[:parse_params])
header&.each do |column|
column.try(:strip!)
@ -117,7 +117,7 @@ returns
record = (lookup_keys & attributes.keys).lazy.map do |lookup_key|
params = attributes.slice(lookup_key)
params.transform_values!(&:downcase) if lookup_key.in?(%i[email login])
lookup(params)
lookup(**params)
end.detect(&:present?)
if record&.in?(records)
@ -296,7 +296,7 @@ returns
end
rows_to_add = []
end
::CSV.generate(params) do |csv|
::CSV.generate(**params) do |csv|
csv << header
rows.each do |row|
csv << row

View file

@ -1,8 +1,8 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
class ObjectManager::Attribute::Validation::Backend
def self.validate(*args)
new(*args).validate
def self.validate(...)
new(...).validate
end
attr_reader :record, :attribute, :value, :previous_value

View file

@ -9,7 +9,7 @@ module ActiveRecord
# on postgres create lower indices to support case-insensitive where conditions
def add_index(table_name, column_name, options = {}) #:nodoc:
index_name, index_type, index_columns, index_options, index_algorithm, index_using = add_index_options(table_name, column_name, options)
index_name, index_type, index_columns, index_options, index_algorithm, index_using = add_index_options(table_name, column_name, **options)
column_names = index_columns.split ', '
if column_names.instance_of?(Array)

View file

@ -470,8 +470,8 @@ class String
# * `:output_to_binary` returns an ASCII-8BIT-encoded string.
# * `:read_as_sanitized_binary` returns a UTF-8-encoded string with all
# invalid byte sequences replaced with "?" characters.
def utf8_encode(**options)
dup.utf8_encode!(options)
def utf8_encode(...)
dup.utf8_encode!(...)
end
def utf8_encode!(**options)

View file

@ -946,7 +946,7 @@ helper method for making HTTP calls and raising error if response was not succes
=end
def self.make_request_and_validate(url, **args)
response = make_request(url, args)
response = make_request(url, **args)
return true if response.success?

View file

@ -20,8 +20,8 @@ class Sequencer
# )
#
# @return [Hash{Symbol => Object}] the final result state attributes and values
def self.process(sequence, *args)
new(sequence, *args).process
def self.process(sequence, **args)
new(sequence, **args).process
end
# Provides the log level definition for the requested Sequencer component.

View file

@ -8,7 +8,7 @@ class Sequencer
class Conversation < Sequencer::Unit::Import::Freshdesk::Request::Generic
attr_reader :ticket
def initialize(*)
def initialize(...)
super
@ticket = request_params.delete(:ticket)
end

View file

@ -8,7 +8,7 @@ class Sequencer
class TimeEntry < Sequencer::Unit::Import::Freshdesk::Request::Generic
attr_reader :ticket
def initialize(*)
def initialize(...)
super
@ticket = request_params.delete(:ticket)
end

View file

@ -263,7 +263,7 @@ RSpec.describe Ldap do
allow(mocked_ldap).to receive(:search).with(include(expected)).and_yield(yield_entry).and_return(true)
check_entry = nil
instance.search(filter, additional) { |entry| check_entry = entry }
instance.search(filter, **additional) { |entry| check_entry = entry }
expect(check_entry).to eq(yield_entry)
end
@ -283,7 +283,7 @@ RSpec.describe Ldap do
allow(mocked_ldap).to receive(:search).with(include(expected)).and_yield(yield_entry).and_return(true)
check_entry = nil
instance.search(filter, additional) { |entry| check_entry = entry }
instance.search(filter, **additional) { |entry| check_entry = entry }
expect(check_entry).to eq(yield_entry)
end

View file

@ -93,7 +93,7 @@ RSpec.shared_examples 'ApplicationModel::CanLookup' do
expect { instance.update(attribute => new_attribute_val) }
.to change { described_class.cache_get(old_attribute_val) }.to(nil)
expect { described_class.lookup({ attribute => instance.send(attribute) }) }
expect { described_class.lookup(attribute => instance.send(attribute)) }
.to change { described_class.cache_get(new_attribute_val) }.to(instance)
end
end

View file

@ -23,11 +23,11 @@ RSpec.describe Channel, type: :model do
let(:failing_adapter_class) do
Class.new(Channel::Driver::Null) do
def fetchable?(*)
def fetchable?(...)
true
end
def fetch(*)
def fetch(...)
raise 'some error'
end
end
@ -35,7 +35,7 @@ RSpec.describe Channel, type: :model do
let(:dummy_adapter_class) do
Class.new(Channel::Driver::Null) do
def fetchable?(*)
def fetchable?(...)
true
end
end

View file

@ -18,6 +18,6 @@ RSpec.configure do |config|
authenticated = example.metadata.fetch(:authenticated_as, true)
credentials = authenticated_as_get_user(authenticated, return_type: :credentials)
login(credentials) if credentials
login(**credentials) if credentials
end
end

View file

@ -36,43 +36,43 @@ class Capybara::Node::Element
end
module ZammadCapybarActionDelegator
def select(*)
def select(...)
super.tap do
await_empty_ajax_queue
end
end
def click(*)
def click(...)
super.tap do
await_empty_ajax_queue
end
end
def click_on(*)
def click_on(...)
super.tap do
await_empty_ajax_queue
end
end
def click_link_or_button(*)
def click_link_or_button(...)
super.tap do
await_empty_ajax_queue
end
end
def click_button(*)
def click_button(...)
super.tap do
await_empty_ajax_queue
end
end
def select_option(*)
def select_option(...)
super.tap do
await_empty_ajax_queue
end
end
def send_keys(*)
def send_keys(...)
super.tap do
await_empty_ajax_queue
end
@ -80,31 +80,31 @@ module ZammadCapybarActionDelegator
end
module ZammadCapybarSelectorDelegator
def find_field(*)
def find_field(...)
ZammadCapybaraElementDelegator.new(element: super, context: self)
end
def find_button(*)
def find_button(...)
ZammadCapybaraElementDelegator.new(element: super, context: self)
end
def find_by_id(*)
def find_by_id(...)
ZammadCapybaraElementDelegator.new(element: super, context: self)
end
def find_link(*)
def find_link(...)
ZammadCapybaraElementDelegator.new(element: super, context: self)
end
def find(*)
def find(...)
ZammadCapybaraElementDelegator.new(element: super, context: self)
end
def first(*)
def first(...)
ZammadCapybaraElementDelegator.new(element: super, context: self)
end
def all(*)
def all(...)
super.map { |element| ZammadCapybaraElementDelegator.new(element: element, context: self) }
end
end
@ -131,7 +131,7 @@ module CapybaraCustomExtensions
include ZammadCapybarActionDelegator
include ZammadCapybarSelectorDelegator
def page(*)
def page(...)
ZammadCapybaraSessionDelegator.new(element: super, context: self)
end
end

View file

@ -11,7 +11,7 @@ RSpec.configure do |config|
Setting.set('fqdn', "#{host}:#{port}")
# start a silenced Puma as application server
Capybara.servers[:puma].call(app, port, host, { Silent: true, Host: '0.0.0.0', Threads: '0:16' })
Capybara.servers[:puma].call(app, port, host, Silent: true, Host: '0.0.0.0', Threads: '0:16')
end
Capybara.server = :puma_wrapper

View file

@ -29,7 +29,7 @@ Capybara.register_driver(:zammad_chrome) do |app|
options[:url] = ENV['REMOTE_URL']
end
Capybara::Selenium::Driver.new(app, options)
Capybara::Selenium::Driver.new(app, **options)
end
Capybara.register_driver(:zammad_firefox) do |app|
@ -54,5 +54,5 @@ Capybara.register_driver(:zammad_firefox) do |app|
options[:url] = ENV['REMOTE_URL']
end
Capybara::Selenium::Driver.new(app, options)
Capybara::Selenium::Driver.new(app, **options)
end

View file

@ -117,7 +117,7 @@ module DbMigrationHelper
# remove_foreign_key(:online_notifications, :users)
#
# @return [nil]
def respond_to_missing?(*)
def respond_to_missing?(...)
true
end

View file

@ -3,4 +3,14 @@
require 'deprecation_toolkit/rspec'
DeprecationToolkit::Configuration.test_runner = :rspec
# DeprecationToolkit::Configuration.warnings_treated_as_deprecation = [ %r{deprecat}i ]
# Treat Ruby deprecation warnings as errors.
DeprecationToolkit::Configuration.warnings_treated_as_deprecation = [ %r{deprecat}i ]
# Ignore deprecation warnings from dependencies.
DeprecationToolkit::Configuration.allowed_deprecations = [
lambda do |_message, stack|
path = stack.first.absolute_path.to_s
path.include?('/ruby/') || path.include?('/gems/')
end
]