Autofix Rubocop Rails/Pluck (#23730)
This commit is contained in:
		
							parent
							
								
									597767a9f7
								
							
						
					
					
						commit
						21bf326356
					
				
					 7 changed files with 14 additions and 25 deletions
				
			
		|  | @ -2435,17 +2435,6 @@ Rails/Output: | ||||||
|   Exclude: |   Exclude: | ||||||
|     - 'lib/mastodon/ip_blocks_cli.rb' |     - '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 | # Offense count: 9 | ||||||
| # This cop supports unsafe autocorrection (--autocorrect-all). | # This cop supports unsafe autocorrection (--autocorrect-all). | ||||||
| # Configuration parameters: Include. | # Configuration parameters: Include. | ||||||
|  |  | ||||||
|  | @ -45,7 +45,7 @@ class Importer::BaseImporter | ||||||
|   # Remove documents from the index that no longer exist in the database |   # Remove documents from the index that no longer exist in the database | ||||||
|   def clean_up! |   def clean_up! | ||||||
|     index.scroll_batches do |documents| |     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 } |       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] } |       tmp           = ids.reject { |id| existence_map[id] } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -188,7 +188,7 @@ class LinkDetailsExtractor | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def language |   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 |   end | ||||||
| 
 | 
 | ||||||
|   def icon |   def icon | ||||||
|  | @ -220,15 +220,15 @@ class LinkDetailsExtractor | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def link_tag(name) |   def link_tag(name) | ||||||
|     document.xpath("//link[@rel=\"#{name}\"]").map { |link| link['href'] }.first |     document.xpath("//link[@rel=\"#{name}\"]").pick('href') | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def opengraph_tag(name) |   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 |   end | ||||||
| 
 | 
 | ||||||
|   def meta_tag(name) |   def meta_tag(name) | ||||||
|     document.xpath("//meta[@name=\"#{name}\"]").map { |meta| meta['content'] }.first |     document.xpath("//meta[@name=\"#{name}\"]").pick('content') | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def structured_data |   def structured_data | ||||||
|  |  | ||||||
|  | @ -67,7 +67,7 @@ class Scheduler::AccountsStatusesCleanupScheduler | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def compute_budget |   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 |     [PER_THREAD_BUDGET * threads, MAX_BUDGET].min | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -70,19 +70,19 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       it 'includes reblog' do |       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 |       end | ||||||
| 
 | 
 | ||||||
|       it 'includes mention' do |       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 |       end | ||||||
| 
 | 
 | ||||||
|       it 'includes favourite' do |       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 |       end | ||||||
| 
 | 
 | ||||||
|       it 'includes follow' do |       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 | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  | @ -125,7 +125,7 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do | ||||||
| 
 | 
 | ||||||
|       it 'returns everything but excluded type' do |       it 'returns everything but excluded type' do | ||||||
|         expect(body_as_json.size).to_not eq 0 |         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 | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  | @ -139,7 +139,7 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       it 'returns only requested type' do |       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 |     end | ||||||
|   end |   end | ||||||
|  |  | ||||||
|  | @ -29,7 +29,7 @@ RSpec.describe Api::V1::SuggestionsController, type: :controller do | ||||||
|       json = body_as_json |       json = body_as_json | ||||||
| 
 | 
 | ||||||
|       expect(json.size).to be >= 1 |       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 |   end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -140,7 +140,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do | ||||||
|           it 'includes existing credentials in list of excluded credentials' do |           it 'includes existing credentials in list of excluded credentials' do | ||||||
|             get :options |             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)) |             expect(excluded_credentials_ids).to match_array(user.webauthn_credentials.pluck(:external_id)) | ||||||
|           end |           end | ||||||
|         end |         end | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue