From 814468ccfae7d69dd5113a846ebe2ddbab1ff507 Mon Sep 17 00:00:00 2001 From: Pedro Paiva Date: Tue, 26 Dec 2023 18:22:41 -0300 Subject: [PATCH] chore: bump rubocop to 1.59.0 (#1600) --- .rubocop.yml | 1 + Gemfile.lock | 24 +++++++++++-------- .../active_record/association_matcher.rb | 14 ++++------- .../have_readonly_attribute_matcher.rb | 2 +- .../matchers/doublespeak/double_collection.rb | 8 ++----- lib/shoulda/matchers/doublespeak/world.rb | 8 ++----- lib/shoulda/matchers/util.rb | 14 +++++------ spec/support/unit/matchers/match_against.rb | 12 +++++----- .../model_creation_strategies/active_model.rb | 4 ++-- spec/support/unit/model_creators/basic.rb | 4 ++-- 10 files changed, 41 insertions(+), 50 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 89f9ba853..35045a4b0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -86,6 +86,7 @@ Metrics/MethodLength: Metrics/ModuleLength: Enabled: true Exclude: + - lib/shoulda/matchers/rails_shim.rb - spec/**/* Metrics/ParameterLists: CountKeywordArgs: false diff --git a/Gemfile.lock b/Gemfile.lock index 0e852160d..6ff7f84de 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,24 +18,27 @@ GEM fssm (0.2.10) i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.6.3) + json (2.7.1) + language_server-protocol (3.17.0.3) method_source (1.0.0) minitest (5.16.3) - parallel (1.23.0) - parser (3.2.2.1) + parallel (1.24.0) + parser (3.2.2.4) ast (~> 2.4.1) + racc pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) pry-byebug (3.10.1) byebug (~> 11.0) pry (>= 0.13, < 0.15) + racc (1.7.3) rack (3.0.0) rainbow (3.1.1) rake (13.0.1) redcarpet (3.5.0) - regexp_parser (2.8.0) - rexml (3.2.5) + regexp_parser (2.8.3) + rexml (3.2.6) rouge (3.22.0) rspec (3.12.0) rspec-core (~> 3.12.0) @@ -50,17 +53,18 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.0) - rubocop (1.52.0) + rubocop (1.59.0) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.29.0) + rubocop-ast (1.30.0) parser (>= 3.2.1.0) rubocop-packaging (0.5.2) rubocop (>= 1.33, < 2.0) @@ -72,7 +76,7 @@ GEM thor (1.2.2) tzinfo (2.0.5) concurrent-ruby (~> 1.0) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) warnings_logger (0.1.1) yard (0.9.25) zeus (0.15.14) diff --git a/lib/shoulda/matchers/active_record/association_matcher.rb b/lib/shoulda/matchers/active_record/association_matcher.rb index 28e13d66e..6ceaaf674 100644 --- a/lib/shoulda/matchers/active_record/association_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matcher.rb @@ -1299,10 +1299,7 @@ def class_name_correct? end def join_table_correct? - if ( - macro != :has_and_belongs_to_many || - join_table_matcher.matches?(@subject) - ) + if macro != :has_and_belongs_to_many || join_table_matcher.matches?(@subject) true else @missing = join_table_matcher.failure_message @@ -1457,11 +1454,10 @@ def actual_foreign_key end def foreign_key_reflection - if ( - [:has_one, :has_many].include?(macro) && - reflection.options.include?(:inverse_of) && - reflection.options[:inverse_of] != false - ) + if [:has_one, :has_many].include?(macro) && + reflection.options.include?(:inverse_of) && + reflection.options[:inverse_of] != false + associated_class.reflect_on_association( reflection.options[:inverse_of], ) diff --git a/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb b/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb index 58465c6e3..43e6debc3 100644 --- a/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +++ b/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb @@ -59,7 +59,7 @@ def description private def readonly_attributes - @_readonly_attributes ||= (@subject.class.readonly_attributes || []) + @_readonly_attributes ||= @subject.class.readonly_attributes || [] end def class_name diff --git a/lib/shoulda/matchers/doublespeak/double_collection.rb b/lib/shoulda/matchers/doublespeak/double_collection.rb index fb520f4ce..0ac9698bc 100644 --- a/lib/shoulda/matchers/doublespeak/double_collection.rb +++ b/lib/shoulda/matchers/doublespeak/double_collection.rb @@ -18,15 +18,11 @@ def register_proxy(method_name) end def activate - doubles_by_method_name.each do |_method_name, double| - double.activate - end + doubles_by_method_name.each_value(&:activate) end def deactivate - doubles_by_method_name.each do |_method_name, double| - double.deactivate - end + doubles_by_method_name.each_value(&:deactivate) end def calls_by_method_name diff --git a/lib/shoulda/matchers/doublespeak/world.rb b/lib/shoulda/matchers/doublespeak/world.rb index 686d0e242..8b7aaf4b5 100644 --- a/lib/shoulda/matchers/doublespeak/world.rb +++ b/lib/shoulda/matchers/doublespeak/world.rb @@ -39,15 +39,11 @@ def doubles_activated? private def activate - double_collections_by_class.each do |_klass, double_collection| - double_collection.activate - end + double_collections_by_class.each_value(&:activate) end def deactivate - double_collections_by_class.each do |_klass, double_collection| - double_collection.deactivate - end + double_collections_by_class.each_value(&:deactivate) end def double_collections_by_class diff --git a/lib/shoulda/matchers/util.rb b/lib/shoulda/matchers/util.rb index 771fb1daa..7813860d5 100644 --- a/lib/shoulda/matchers/util.rb +++ b/lib/shoulda/matchers/util.rb @@ -7,10 +7,9 @@ module Util MAXIMUM_LENGTH_OF_VALUE_TO_DISPLAY = 500 def self.deconstantize(path) - if ( - defined?(ActiveSupport::Inflector) && - ActiveSupport::Inflector.respond_to?(:deconstantize) - ) + if defined?(ActiveSupport::Inflector) && + ActiveSupport::Inflector.respond_to?(:deconstantize) + ActiveSupport::Inflector.deconstantize(path) else path.to_s[0...(path.to_s.rindex('::') || 0)] @@ -18,10 +17,9 @@ def self.deconstantize(path) end def self.safe_constantize(camel_cased_word) - if ( - defined?(ActiveSupport::Inflector) && - ActiveSupport::Inflector.respond_to?(:safe_constantize) - ) + if defined?(ActiveSupport::Inflector) && + ActiveSupport::Inflector.respond_to?(:safe_constantize) + ActiveSupport::Inflector.safe_constantize(camel_cased_word) else begin diff --git a/spec/support/unit/matchers/match_against.rb b/spec/support/unit/matchers/match_against.rb index d5410cdd6..35d3b5a98 100644 --- a/spec/support/unit/matchers/match_against.rb +++ b/spec/support/unit/matchers/match_against.rb @@ -79,10 +79,10 @@ def does_not_match?(generate_matcher) end if matcher_fails_in_positive? - if ( + if negative_matcher.respond_to?(:does_not_match?) && !negative_matcher.does_not_match?(object) - ) + @failure_message_when_negated = <<-MESSAGE Expected the matcher to match in the negative, but it failed with this message: @@ -116,10 +116,10 @@ def should_be_negated? def matcher_fails_in_negative? if does_not_match_in_negative? - if ( + if !expected_message || expected_message == negative_matcher.failure_message_when_negated.strip - ) + true else diff_result = diff( @@ -166,10 +166,10 @@ def does_not_match_in_negative? def matcher_fails_in_positive? if !positive_matcher.matches?(object) - if ( + if !expected_message || expected_message == positive_matcher.failure_message.strip - ) + true else diff_result = diff( diff --git a/spec/support/unit/model_creation_strategies/active_model.rb b/spec/support/unit/model_creation_strategies/active_model.rb index dda3e470d..61937a463 100644 --- a/spec/support/unit/model_creation_strategies/active_model.rb +++ b/spec/support/unit/model_creation_strategies/active_model.rb @@ -67,10 +67,10 @@ def attribute(name) name = name.to_sym - if ( + if attribute_names.include?(name) && attributes_module.instance_methods.include?(name) - ) + attributes_module.module_eval do remove_method(name) remove_method("#{name}=") diff --git a/spec/support/unit/model_creators/basic.rb b/spec/support/unit/model_creators/basic.rb index 596eb0681..77d732f52 100644 --- a/spec/support/unit/model_creators/basic.rb +++ b/spec/support/unit/model_creators/basic.rb @@ -79,12 +79,12 @@ def possibly_override_attribute_writer_method_for(model) overrides[:changing_values_with], ) - if ( + if respond_to?(:write_attribute) && ( !self.class.respond_to?(:reflect_on_association) || !self.class.reflect_on_association(attribute_name) ) - ) + write_attribute(attribute_name, new_value) else super(new_value)