From a0c9f2447e8da95dca629082af32c2e2616b7715 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 3 May 2023 04:30:54 -0400 Subject: [PATCH] Fix Performance/MethodObjectAsBlock cop (#24798) --- .rubocop_todo.yml | 5 ----- app/models/account_suggestions/source.rb | 2 +- spec/models/export_spec.rb | 12 ++++++------ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f2a5cf4c4..2b2a110fa 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -322,11 +322,6 @@ Performance/MapCompact: - 'db/migrate/20200407202420_migrate_unavailable_inboxes.rb' - 'spec/presenters/status_relationships_presenter_spec.rb' -Performance/MethodObjectAsBlock: - Exclude: - - 'app/models/account_suggestions/source.rb' - - 'spec/models/export_spec.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: MaxKeyValuePairs. Performance/RedundantMerge: diff --git a/app/models/account_suggestions/source.rb b/app/models/account_suggestions/source.rb index bd1068d20..be462cd0f 100644 --- a/app/models/account_suggestions/source.rb +++ b/app/models/account_suggestions/source.rb @@ -18,7 +18,7 @@ class AccountSuggestions::Source def as_ordered_suggestions(scope, ordered_list) return [] if ordered_list.empty? - map = scope.index_by(&method(:to_ordered_list_key)) + map = scope.index_by { |account| to_ordered_list_key(account) } ordered_list.map { |ordered_list_key| map[ordered_list_key] }.compact.map do |account| AccountSuggestions::Suggestion.new( diff --git a/spec/models/export_spec.rb b/spec/models/export_spec.rb index 3fb5fc3a5..a863678a3 100644 --- a/spec/models/export_spec.rb +++ b/spec/models/export_spec.rb @@ -10,7 +10,7 @@ describe Export do describe 'to_csv' do it 'returns a csv of the blocked accounts' do - target_accounts.each(&account.method(:block!)) + target_accounts.each { |target_account| account.block!(target_account) } export = Export.new(account).to_blocked_accounts_csv results = export.strip.split @@ -20,7 +20,7 @@ describe Export do end it 'returns a csv of the muted accounts' do - target_accounts.each(&account.method(:mute!)) + target_accounts.each { |target_account| account.mute!(target_account) } export = Export.new(account).to_muted_accounts_csv results = export.strip.split("\n") @@ -31,7 +31,7 @@ describe Export do end it 'returns a csv of the following accounts' do - target_accounts.each(&account.method(:follow!)) + target_accounts.each { |target_account| account.follow!(target_account) } export = Export.new(account).to_following_accounts_csv results = export.strip.split("\n") @@ -51,17 +51,17 @@ describe Export do describe 'total_follows' do it 'returns the total number of the followed accounts' do - target_accounts.each(&account.method(:follow!)) + target_accounts.each { |target_account| account.follow!(target_account) } expect(Export.new(account.reload).total_follows).to eq 2 end it 'returns the total number of the blocked accounts' do - target_accounts.each(&account.method(:block!)) + target_accounts.each { |target_account| account.block!(target_account) } expect(Export.new(account.reload).total_blocks).to eq 2 end it 'returns the total number of the muted accounts' do - target_accounts.each(&account.method(:mute!)) + target_accounts.each { |target_account| account.mute!(target_account) } expect(Export.new(account.reload).total_mutes).to eq 2 end end