M .rubocop_todo.yml => .rubocop_todo.yml +0 -11
@@ 2435,17 2435,6 @@ Rails/Output:
Exclude:
- 'lib/mastodon/ip_blocks_cli.rb'
-# Offense count: 14
-# This cop supports safe autocorrection (--autocorrect).
-Rails/Pluck:
- Exclude:
- - 'app/lib/importer/base_importer.rb'
- - 'app/lib/link_details_extractor.rb'
- - 'app/workers/scheduler/accounts_statuses_cleanup_scheduler.rb'
- - 'spec/controllers/api/v1/notifications_controller_spec.rb'
- - 'spec/controllers/api/v1/suggestions_controller_spec.rb'
- - 'spec/controllers/settings/two_factor_authentication/webauthn_credentials_controller_spec.rb'
-
# Offense count: 9
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Include.
M app/lib/importer/base_importer.rb => app/lib/importer/base_importer.rb +1 -1
@@ 45,7 45,7 @@ class Importer::BaseImporter
# Remove documents from the index that no longer exist in the database
def clean_up!
index.scroll_batches do |documents|
- ids = documents.map { |doc| doc['_id'] }
+ ids = documents.pluck('_id')
existence_map = index.adapter.target.where(id: ids).pluck(:id).each_with_object({}) { |id, map| map[id.to_s] = true }
tmp = ids.reject { |id| existence_map[id] }
M => +4 -4
@@ 188,7 188,7 @@ class LinkDetailsExtractor
end
def language
valid_locale_or_nil(structured_data&.language || opengraph_tag('og:locale') || document.xpath('//html').map { |element| element['lang'] }.first)
valid_locale_or_nil(structured_data&.language || opengraph_tag('og:locale') || document.xpath('//html').pick('lang'))
end
def icon
@@ 220,15 220,15 @@ class LinkDetailsExtractor
end
def link_tag(name)
document.xpath("//link[@rel=\"#{name}\"]").map { |link| link['href'] }.first
document.xpath("//link[@rel=\"#{name}\"]").pick('href')
end
def opengraph_tag(name)
document.xpath("//meta[@property=\"#{name}\" or @name=\"#{name}\"]").map { |meta| meta['content'] }.first
document.xpath("//meta[@property=\"#{name}\" or @name=\"#{name}\"]").pick('content')
end
def meta_tag(name)
document.xpath("//meta[@name=\"#{name}\"]").map { |meta| meta['content'] }.first
document.xpath("//meta[@name=\"#{name}\"]").pick('content')
end
def structured_data
M app/workers/scheduler/accounts_statuses_cleanup_scheduler.rb => app/workers/scheduler/accounts_statuses_cleanup_scheduler.rb +1 -1
@@ 67,7 67,7 @@ class Scheduler::AccountsStatusesCleanupScheduler
end
def compute_budget
- threads = Sidekiq::ProcessSet.new.select { |x| x['queues'].include?('push') }.map { |x| x['concurrency'] }.sum
+ threads = Sidekiq::ProcessSet.new.select { |x| x['queues'].include?('push') }.pluck('concurrency').sum
[PER_THREAD_BUDGET * threads, MAX_BUDGET].min
end
M spec/controllers/api/v1/notifications_controller_spec.rb => spec/controllers/api/v1/notifications_controller_spec.rb +6 -6
@@ 70,19 70,19 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
end
it 'includes reblog' do
- expect(body_as_json.map { |x| x[:type] }).to include 'reblog'
+ expect(body_as_json.pluck(:type)).to include 'reblog'
end
it 'includes mention' do
- expect(body_as_json.map { |x| x[:type] }).to include 'mention'
+ expect(body_as_json.pluck(:type)).to include 'mention'
end
it 'includes favourite' do
- expect(body_as_json.map { |x| x[:type] }).to include 'favourite'
+ expect(body_as_json.pluck(:type)).to include 'favourite'
end
it 'includes follow' do
- expect(body_as_json.map { |x| x[:type] }).to include 'follow'
+ expect(body_as_json.pluck(:type)).to include 'follow'
end
end
@@ 125,7 125,7 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
it 'returns everything but excluded type' do
expect(body_as_json.size).to_not eq 0
- expect(body_as_json.map { |x| x[:type] }.uniq).to_not include 'mention'
+ expect(body_as_json.pluck(:type).uniq).to_not include 'mention'
end
end
@@ 139,7 139,7 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
end
it 'returns only requested type' do
- expect(body_as_json.map { |x| x[:type] }.uniq).to eq ['mention']
+ expect(body_as_json.pluck(:type).uniq).to eq ['mention']
end
end
end
M spec/controllers/api/v1/suggestions_controller_spec.rb => spec/controllers/api/v1/suggestions_controller_spec.rb +1 -1
@@ 29,7 29,7 @@ RSpec.describe Api::V1::SuggestionsController, type: :controller do
json = body_as_json
expect(json.size).to be >= 1
- expect(json.map { |i| i[:id] }).to include(*[bob, jeff].map { |i| i.id.to_s })
+ expect(json.pluck(:id)).to include(*[bob, jeff].map { |i| i.id.to_s })
end
end
end
M spec/controllers/settings/two_factor_authentication/webauthn_credentials_controller_spec.rb => spec/controllers/settings/two_factor_authentication/webauthn_credentials_controller_spec.rb +1 -1
@@ 140,7 140,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
it 'includes existing credentials in list of excluded credentials' do
get :options
- excluded_credentials_ids = JSON.parse(response.body)['excludeCredentials'].map { |credential| credential['id'] }
+ excluded_credentials_ids = JSON.parse(response.body)['excludeCredentials'].pluck('id')
expect(excluded_credentials_ids).to match_array(user.webauthn_credentials.pluck(:external_id))
end
end