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 # we don't wann to tell what the cause for the authorization error is
# so we capture the exception and raise an anonymized one # so we capture the exception and raise an anonymized one
def authorize!(*) def authorize!(...)
super super
rescue Pundit::NotAuthorizedError rescue Pundit::NotAuthorizedError
raise Exceptions::Forbidden raise Exceptions::Forbidden

View file

@ -95,8 +95,9 @@ class TicketsController < ApplicationController
clean_params[:customer_id] = current_user.id clean_params[:customer_id] = current_user.id
end end
# try to create customer if needed # The parameter :customer_id is 'abused' in cases where it is not an integer, but a string like
if clean_params[:customer_id].present? && clean_params[:customer_id] =~ %r{^guess:(.+?)$} # '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 = $1
email_address_validation = EmailAddressValidation.new(email_address) email_address_validation = EmailAddressValidation.new(email_address)
if !email_address_validation.valid_format? if !email_address_validation.valid_format?

View file

@ -13,7 +13,7 @@ class ApplicationJob
class LogSubscriber < ActiveJob::Logging::LogSubscriber class LogSubscriber < ActiveJob::Logging::LogSubscriber
# ATTENTION: Uncomment this line to enable info logging again # ATTENTION: Uncomment this line to enable info logging again
def info(*); end def info(...); end
def enqueue(event) def enqueue(event)
super if job_enqueued?(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? 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) } record.nil? ? create(data) : record.tap { |r| r.update(data) }
end end

View file

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

View file

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

View file

@ -1,8 +1,8 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
class ObjectManager::Attribute::Validation::Backend class ObjectManager::Attribute::Validation::Backend
def self.validate(*args) def self.validate(...)
new(*args).validate new(...).validate
end end
attr_reader :record, :attribute, :value, :previous_value 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 # on postgres create lower indices to support case-insensitive where conditions
def add_index(table_name, column_name, options = {}) #:nodoc: 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 ', ' column_names = index_columns.split ', '
if column_names.instance_of?(Array) if column_names.instance_of?(Array)

View file

@ -470,8 +470,8 @@ class String
# * `:output_to_binary` returns an ASCII-8BIT-encoded string. # * `:output_to_binary` returns an ASCII-8BIT-encoded string.
# * `:read_as_sanitized_binary` returns a UTF-8-encoded string with all # * `:read_as_sanitized_binary` returns a UTF-8-encoded string with all
# invalid byte sequences replaced with "?" characters. # invalid byte sequences replaced with "?" characters.
def utf8_encode(**options) def utf8_encode(...)
dup.utf8_encode!(options) dup.utf8_encode!(...)
end end
def utf8_encode!(**options) 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 =end
def self.make_request_and_validate(url, **args) def self.make_request_and_validate(url, **args)
response = make_request(url, args) response = make_request(url, **args)
return true if response.success? return true if response.success?

View file

@ -20,8 +20,8 @@ class Sequencer
# ) # )
# #
# @return [Hash{Symbol => Object}] the final result state attributes and values # @return [Hash{Symbol => Object}] the final result state attributes and values
def self.process(sequence, *args) def self.process(sequence, **args)
new(sequence, *args).process new(sequence, **args).process
end end
# Provides the log level definition for the requested Sequencer component. # 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 class Conversation < Sequencer::Unit::Import::Freshdesk::Request::Generic
attr_reader :ticket attr_reader :ticket
def initialize(*) def initialize(...)
super super
@ticket = request_params.delete(:ticket) @ticket = request_params.delete(:ticket)
end end

View file

@ -8,7 +8,7 @@ class Sequencer
class TimeEntry < Sequencer::Unit::Import::Freshdesk::Request::Generic class TimeEntry < Sequencer::Unit::Import::Freshdesk::Request::Generic
attr_reader :ticket attr_reader :ticket
def initialize(*) def initialize(...)
super super
@ticket = request_params.delete(:ticket) @ticket = request_params.delete(:ticket)
end 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) allow(mocked_ldap).to receive(:search).with(include(expected)).and_yield(yield_entry).and_return(true)
check_entry = nil 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) expect(check_entry).to eq(yield_entry)
end 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) allow(mocked_ldap).to receive(:search).with(include(expected)).and_yield(yield_entry).and_return(true)
check_entry = nil 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) expect(check_entry).to eq(yield_entry)
end end

View file

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

View file

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

View file

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

View file

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

View file

@ -11,7 +11,7 @@ RSpec.configure do |config|
Setting.set('fqdn', "#{host}:#{port}") Setting.set('fqdn', "#{host}:#{port}")
# start a silenced Puma as application server # 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 end
Capybara.server = :puma_wrapper Capybara.server = :puma_wrapper

View file

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

View file

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

View file

@ -3,4 +3,14 @@
require 'deprecation_toolkit/rspec' require 'deprecation_toolkit/rspec'
DeprecationToolkit::Configuration.test_runner = :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
]