From ee1476f802d34ee31d1e1c990165165338867ff6 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Fri, 28 Oct 2022 07:50:11 +0000 Subject: [PATCH] Fix RuboCop offense Rails/Pluck (#37248). git-svn-id: https://svn.redmine.org/redmine/trunk@21928 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/versions_helper.rb | 2 +- app/models/changeset.rb | 2 +- app/models/query.rb | 2 +- app/models/repository/git.rb | 2 +- lib/redmine/helpers/time_report.rb | 4 ++-- test/integration/api_test/search_test.rb | 4 ++-- test/system/issues_test.rb | 2 +- test/unit/query_test.rb | 26 ++++++++++++------------ 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/helpers/versions_helper.rb b/app/helpers/versions_helper.rb index ffaa54675..ef4bb9d04 100644 --- a/app/helpers/versions_helper.rb +++ b/app/helpers/versions_helper.rb @@ -75,7 +75,7 @@ module VersionsHelper sorted_keys.collect do |k| {:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])} end - max = counts.collect {|c| c[:total]}.max + max = counts.pluck(:total).max render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max} end diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 4e04e4965..b4501b19e 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -129,7 +129,7 @@ class Changeset < ActiveRecord::Base ref_keywords_any = ref_keywords.delete('*') # keywords used to fix issues - fix_keywords = Setting.commit_update_keywords_array.map {|r| r['keywords']}.flatten.compact + fix_keywords = Setting.commit_update_keywords_array.pluck('keywords').flatten.compact kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|") referenced_issues = [] diff --git a/app/models/query.rb b/app/models/query.rb index 9f7de57c7..e18b06805 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -542,7 +542,7 @@ class Query < ActiveRecord::Base if has_filter?(field) || !filter.remote options[:values] = filter.values if options[:values] && values_for(field) - missing = Array(values_for(field)).select(&:present?) - options[:values].map{|v| v[1]} + missing = Array(values_for(field)).select(&:present?) - options[:values].pluck(1) if missing.any? && respond_to?(method = "find_#{field}_filter_values") options[:values] += send(method, missing) end diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb index bd160b3e5..a19f38f2a 100644 --- a/app/models/repository/git.rb +++ b/app/models/repository/git.rb @@ -232,7 +232,7 @@ class Repository::Git < Repository def heads_from_branches_hash h = extra_info&.dup || {} h["branches"] ||= {} - h['branches'].map{|br, hs| hs['last_scmid']} + h['branches'].map{|br, hs| hs['last_scmid']} # rubocop:disable Rails/Pluck end def latest_changesets(path, rev, limit=10) diff --git a/lib/redmine/helpers/time_report.rb b/lib/redmine/helpers/time_report.rb index 2ae5fd8eb..449869c9f 100644 --- a/lib/redmine/helpers/time_report.rb +++ b/lib/redmine/helpers/time_report.rb @@ -71,10 +71,10 @@ module Redmine end end - min = @hours.collect {|row| row['spent_on']}.min + min = @hours.pluck('spent_on').min @from = min ? min.to_date : User.current.today - max = @hours.collect {|row| row['spent_on']}.max + max = @hours.pluck('spent_on').max @to = max ? max.to_date : User.current.today @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f} diff --git a/test/integration/api_test/search_test.rb b/test/integration/api_test/search_test.rb index 67cadad51..f05832079 100644 --- a/test/integration/api_test/search_test.rb +++ b/test/integration/api_test/search_test.rb @@ -82,14 +82,14 @@ class Redmine::ApiTest::SearchTest < Redmine::ApiTest::Base assert_equal 11, json['total_count'] assert_equal 0, json['offset'] assert_equal 4, json['limit'] - assert_equal issue[0..3], json['results'].map {|r| r['id']} + assert_equal issue[0..3], json['results'].pluck('id') get '/search.json', :params => {:q => 'search_with_limited_results', :offset => 8, :limit => 4} json = ActiveSupport::JSON.decode(response.body) assert_equal 11, json['total_count'] assert_equal 8, json['offset'] assert_equal 4, json['limit'] - assert_equal issue[8..10], json['results'].map {|r| r['id']} + assert_equal issue[8..10], json['results'].pluck('id') end test "GET /search.xml should not quick jump to the issue with given id" do diff --git a/test/system/issues_test.rb b/test/system/issues_test.rb index 6d19b65df..6e34ce62c 100644 --- a/test/system/issues_test.rb +++ b/test/system/issues_test.rb @@ -580,7 +580,7 @@ class IssuesSystemTest < ApplicationSystemTestCase csv = CSV.read(downloaded_file("issues.csv")) subject_index = csv.shift.index('Subject') - subjects = csv.map {|row| row[subject_index]} + subjects = csv.pluck(subject_index) assert_equal subjects.sort, subjects end diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 4d6650ee8..1591e985e 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -65,7 +65,7 @@ class QueryTest < ActiveSupport::TestCase "Priority" ] assert_equal expected_order, - (query.available_filters.values.map{|v| v[:name]} & expected_order) + (query.available_filters.values.pluck(:name) & expected_order) end def test_available_filters_with_custom_fields_should_be_ordered @@ -83,7 +83,7 @@ class QueryTest < ActiveSupport::TestCase "Assignee's order test" ] assert_equal expected_order, - (query.available_filters.values.map{|v| v[:name]} & expected_order) + (query.available_filters.values.pluck(:name) & expected_order) end def test_custom_fields_for_all_projects_should_be_available_in_global_queries @@ -103,7 +103,7 @@ class QueryTest < ActiveSupport::TestCase query = IssueQuery.new(:project => nil, :name => '_') project_filter = query.available_filters["project_id"] assert_not_nil project_filter - project_ids = project_filter[:values].map{|p| p[1]} + project_ids = project_filter[:values].pluck(1) assert project_ids.include?("1") # public project assert !project_ids.include?("2") # private project user cannot see end @@ -940,7 +940,7 @@ class QueryTest < ActiveSupport::TestCase query = IssueQuery.new(:name => '_', :project => Project.find(1)) filter = query.available_filters["cf_#{cf.id}"] assert_not_nil filter - assert_include 'me', filter[:values].map{|v| v[1]} + assert_include 'me', filter[:values].pluck(1) query.filters = {"cf_#{cf.id}" => {:operator => '=', :values => ['me']}} result = query.issues @@ -998,7 +998,7 @@ class QueryTest < ActiveSupport::TestCase query = IssueQuery.new(:name => '_') filter = query.available_filters['project_id'] assert_not_nil filter - assert_include 'mine', filter[:values].map{|v| v[1]} + assert_include 'mine', filter[:values].pluck(1) query.filters = {'project_id' => {:operator => '=', :values => ['mine']}} result = query.issues @@ -1010,7 +1010,7 @@ class QueryTest < ActiveSupport::TestCase query = ProjectQuery.new(:name => '_') filter = query.available_filters['id'] assert_not_nil filter - assert_include 'bookmarks', filter[:values].map{|v| v[1]} + assert_include 'bookmarks', filter[:values].pluck(1) query.filters = {'id' => {:operator => '=', :values => ['bookmarks']}} result = query.results_scope @@ -1023,7 +1023,7 @@ class QueryTest < ActiveSupport::TestCase query = ProjectQuery.new(:name => '_') filter = query.available_filters['id'] - assert_not_include 'bookmarks', filter[:values].map{|v| v[1]} + assert_not_include 'bookmarks', filter[:values].pluck(1) end def test_filter_project_parent_id_with_my_projects @@ -1031,7 +1031,7 @@ class QueryTest < ActiveSupport::TestCase query = ProjectQuery.new(:name => '_') filter = query.available_filters['parent_id'] assert_not_nil filter - assert_include 'mine', filter[:values].map{|v| v[1]} + assert_include 'mine', filter[:values].pluck(1) query.filters = {'parent_id' => {:operator => '=', :values => ['mine']}} result = query.results_scope @@ -1045,7 +1045,7 @@ class QueryTest < ActiveSupport::TestCase query = ProjectQuery.new(:name => '_') filter = query.available_filters['parent_id'] assert_not_nil filter - assert_include 'bookmarks', filter[:values].map{|v| v[1]} + assert_include 'bookmarks', filter[:values].pluck(1) query.filters = {'parent_id' => {:operator => '=', :values => ['bookmarks']}} result = query.results_scope @@ -2387,7 +2387,7 @@ class QueryTest < ActiveSupport::TestCase test "#available_filters should include users of visible projects in cross-project view" do users = IssueQuery.new.available_filters["assigned_to_id"] assert_not_nil users - assert users[:values].map{|u| u[1]}.include?("3") + assert users[:values].pluck(1).include?("3") end test "#available_filters should include users of subprojects" do @@ -2397,14 +2397,14 @@ class QueryTest < ActiveSupport::TestCase Member.create!(:principal => user1, :project => project.children.visible.first, :role_ids => [1]) users = IssueQuery.new(:project => project).available_filters["assigned_to_id"] assert_not_nil users - assert users[:values].map{|u| u[1]}.include?(user1.id.to_s) - assert !users[:values].map{|u| u[1]}.include?(user2.id.to_s) + assert users[:values].pluck(1).include?(user1.id.to_s) + assert !users[:values].pluck(1).include?(user2.id.to_s) end test "#available_filters should include visible projects in cross-project view" do projects = IssueQuery.new.available_filters["project_id"] assert_not_nil projects - assert projects[:values].map{|u| u[1]}.include?("1") + assert projects[:values].pluck(1).include?("1") end test "#available_filters should include 'member_of_group' filter" do -- 2.39.5