summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2023-08-23 09:05:20 +0000
committerGo MAEDA <maeda@farend.jp>2023-08-23 09:05:20 +0000
commit21a6fc71d6806dc74e087de4cbf7b4acf3b8a3ba (patch)
tree5e205ca3488eb4301266fcdbccfde2a444be0e33
parent86c5d7814f4c3e860e449cdda05717984ca21405 (diff)
downloadredmine-21a6fc71d6806dc74e087de4cbf7b4acf3b8a3ba.tar.gz
redmine-21a6fc71d6806dc74e087de4cbf7b4acf3b8a3ba.zip
Fix RuboCop offense Performance/MapMethodChain (#37247).
git-svn-id: https://svn.redmine.org/redmine/trunk@22280 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/repositories_controller.rb2
-rw-r--r--app/models/query.rb2
-rw-r--r--test/functional/custom_fields_controller_test.rb2
-rw-r--r--test/functional/news_controller_test.rb2
-rw-r--r--test/functional/timelog_controller_test.rb12
-rw-r--r--test/functional/workflows_controller_test.rb10
-rw-r--r--test/test_helper.rb2
-rw-r--r--test/unit/enumeration_test.rb10
-rw-r--r--test/unit/issue_import_test.rb2
-rw-r--r--test/unit/principal_test.rb4
-rw-r--r--test/unit/time_entry_query_test.rb6
-rw-r--r--test/unit/user_test.rb4
12 files changed, 29 insertions, 29 deletions
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index 9ef62edd1..8ecb0022f 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -66,7 +66,7 @@ class RepositoriesController < ApplicationController
def committers
@committers = @repository.committers
@users = @project.users.to_a
- additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id)
+ additional_user_ids = @committers.collect {|c| c.last.to_i} - @users.collect(&:id)
@users += User.where(:id => additional_user_ids).to_a unless additional_user_ids.empty?
@users.compact!
@users.sort!
diff --git a/app/models/query.rb b/app/models/query.rb
index c09932203..5630f95c7 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -996,7 +996,7 @@ class Query < ActiveRecord::Base
if field == 'project_id' || (self.type == 'ProjectQuery' && %w[id parent_id].include?(field))
if v.delete('mine')
- v += User.current.memberships.map(&:project_id).map(&:to_s)
+ v += User.current.memberships.map {|m| m.project_id.to_s}
end
if v.delete('bookmarks')
v += User.current.bookmarked_project_ids
diff --git a/test/functional/custom_fields_controller_test.rb b/test/functional/custom_fields_controller_test.rb
index 8ab392b5a..8dcc2a2be 100644
--- a/test/functional/custom_fields_controller_test.rb
+++ b/test/functional/custom_fields_controller_test.rb
@@ -597,7 +597,7 @@ class CustomFieldsControllerTest < Redmine::ControllerTest
files =
Dir.glob(File.join(Rails.root, 'app/models/*_custom_field.rb')).
map {|f| File.basename(f).sub(/\.rb$/, '')}
- classes = files.map(&:classify).map(&:constantize)
+ classes = files.map {|x| x.classify.constantize}
assert classes.size > 0
classes
end
diff --git a/test/functional/news_controller_test.rb b/test/functional/news_controller_test.rb
index 44242e299..4812eeeab 100644
--- a/test/functional/news_controller_test.rb
+++ b/test/functional/news_controller_test.rb
@@ -101,7 +101,7 @@ class NewsControllerTest < Redmine::ControllerTest
get(:show, :params => {:id => 1})
assert_response :success
- comments = css_select('#comments .wiki').map(&:text).map(&:strip)
+ comments = css_select('#comments .wiki').map {|e| e.text.strip}
assert_equal ["This is an other comment", "my first comment"], comments
end
diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb
index 1646f0367..7e50952f5 100644
--- a/test/functional/timelog_controller_test.rb
+++ b/test/functional/timelog_controller_test.rb
@@ -1177,7 +1177,7 @@ class TimelogControllerTest < Redmine::ControllerTest
}
assert_response :success
assert_equal(
- [t2, t1, t3].map(&:id).map(&:to_s),
+ [t2, t1, t3].map {|t| t.id.to_s},
css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
)
get(
@@ -1192,7 +1192,7 @@ class TimelogControllerTest < Redmine::ControllerTest
)
assert_response :success
assert_equal(
- [t3, t1, t2].map(&:id).map(&:to_s),
+ [t3, t1, t2].map {|t| t.id.to_s},
css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
)
end
@@ -1218,7 +1218,7 @@ class TimelogControllerTest < Redmine::ControllerTest
].each do |sort_criteria, expected|
get :index, :params => params.dup.merge(sort_criteria)
assert_response :success
- expected_ids = expected.map(&:id).map(&:to_s)
+ expected_ids = expected.map {|t| t.id.to_s}
actual_ids = css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
assert_equal expected_ids, actual_ids
end
@@ -1255,7 +1255,7 @@ class TimelogControllerTest < Redmine::ControllerTest
}
)
assert_response :success
- assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
+ assert_equal [entry.id.to_s], css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
end
def text_index_with_issue_subject_filter
@@ -1334,7 +1334,7 @@ class TimelogControllerTest < Redmine::ControllerTest
:v => {'issue.tracker_id' => ['2']}
}
assert_response :success
- assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
+ assert_equal [entry.id.to_s], css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
end
def test_index_with_issue_tracker_column
@@ -1518,7 +1518,7 @@ class TimelogControllerTest < Redmine::ControllerTest
}
assert_response :success
assert_equal(
- [entry].map(&:id).map(&:to_s),
+ [entry.id.to_s],
css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
)
end
diff --git a/test/functional/workflows_controller_test.rb b/test/functional/workflows_controller_test.rb
index b368939d8..a3b9250cd 100644
--- a/test/functional/workflows_controller_test.rb
+++ b/test/functional/workflows_controller_test.rb
@@ -52,7 +52,7 @@ class WorkflowsControllerTest < Redmine::ControllerTest
statuses = IssueStatus.where(:id => [2, 3, 5]).sorted.pluck(:name)
assert_equal(
["New issue"] + statuses,
- css_select('table.workflows.transitions-always tbody tr td:first').map(&:text).map(&:strip)
+ css_select('table.workflows.transitions-always tbody tr td:first').map {|e| e.text.strip}
)
# allowed transitions
assert_select 'input[type=checkbox][name=?][value="1"][checked=checked]', 'transitions[3][5][always]'
@@ -79,7 +79,7 @@ class WorkflowsControllerTest < Redmine::ControllerTest
statuses = IssueStatus.where(:id => [2, 3]).sorted.pluck(:name)
assert_equal(
["New issue"] + statuses,
- css_select('table.workflows.transitions-always tbody tr td:first').map(&:text).map(&:strip)
+ css_select('table.workflows.transitions-always tbody tr td:first').map {|e| e.text.strip}
)
end
@@ -95,7 +95,7 @@ class WorkflowsControllerTest < Redmine::ControllerTest
statuses = IssueStatus.where(:id => [2, 3]).sorted.pluck(:name)
assert_equal(
["New issue"] + statuses,
- css_select('table.workflows.transitions-always tbody tr td:first').map(&:text).map(&:strip)
+ css_select('table.workflows.transitions-always tbody tr td:first').map {|e| e.text.strip}
)
end
@@ -130,7 +130,7 @@ class WorkflowsControllerTest < Redmine::ControllerTest
statuses = IssueStatus.all.sorted.pluck(:name)
assert_equal(
["New issue"] + statuses,
- css_select('table.workflows.transitions-always tbody tr td:first').map(&:text).map(&:strip)
+ css_select('table.workflows.transitions-always tbody tr td:first').map {|e| e.text.strip}
)
assert_select 'input[type=checkbox][name=?]', 'transitions[0][1][always]'
end
@@ -343,7 +343,7 @@ class WorkflowsControllerTest < Redmine::ControllerTest
statuses = IssueStatus.all.sorted.pluck(:name)
assert_equal(
statuses,
- css_select('table.workflows.fields_permissions thead tr:nth-child(2) td:not(:first-child)').map(&:text).map(&:strip)
+ css_select('table.workflows.fields_permissions thead tr:nth-child(2) td:not(:first-child)').map {|e| e.text.strip}
)
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index ed98f24f8..c5fe079c8 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -340,7 +340,7 @@ module Redmine
class ControllerTest < ActionController::TestCase
# Returns the issues that are displayed in the list in the same order
def issues_in_list
- ids = css_select('tr.issue td.id').map(&:text).map(&:to_i)
+ ids = css_select('tr.issue td.id').map {|e| e.text.to_i}
Issue.where(:id => ids).sort_by {|issue| ids.index(issue.id)}
end
diff --git a/test/unit/enumeration_test.rb b/test/unit/enumeration_test.rb
index a9d0e8eb3..ad516b615 100644
--- a/test/unit/enumeration_test.rb
+++ b/test/unit/enumeration_test.rb
@@ -141,7 +141,7 @@ class EnumerationTest < ActiveSupport::TestCase
b = IssuePriority.create!(:name => 'B')
c = DocumentCategory.create!(:name => 'C')
- assert_equal [1, 2, 1], [a, b, c].map(&:reload).map(&:position)
+ assert_equal [1, 2, 1], [a, b, c].map {|e| e.reload.position}
end
def test_override_should_be_created_with_same_position_as_parent
@@ -151,7 +151,7 @@ class EnumerationTest < ActiveSupport::TestCase
b = IssuePriority.create!(:name => 'B')
override = IssuePriority.create!(:name => 'BB', :parent_id => b.id)
- assert_equal [1, 2, 2], [a, b, override].map(&:reload).map(&:position)
+ assert_equal [1, 2, 2], [a, b, override].map {|e| e.reload.position}
end
def test_override_position_should_be_updated_with_parent_position
@@ -163,7 +163,7 @@ class EnumerationTest < ActiveSupport::TestCase
b.position -= 1
b.save!
- assert_equal [2, 1, 1], [a, b, override].map(&:reload).map(&:position)
+ assert_equal [2, 1, 1], [a, b, override].map {|e| e.reload.position}
end
def test_destroying_override_should_not_update_positions
@@ -174,10 +174,10 @@ class EnumerationTest < ActiveSupport::TestCase
b = IssuePriority.create!(:name => 'B')
c = IssuePriority.create!(:name => 'C')
override = IssuePriority.create!(:name => 'BB', :parent_id => b.id)
- assert_equal [1, 2, 3, 2], [a, b, c, override].map(&:reload).map(&:position)
+ assert_equal [1, 2, 3, 2], [a, b, c, override].map {|e| e.reload.position}
override.destroy
- assert_equal [1, 2, 3], [a, b, c].map(&:reload).map(&:position)
+ assert_equal [1, 2, 3], [a, b, c].map {|e| e.reload.position}
end
def test_spaceship_operator_with_incomparable_value_should_return_nil
diff --git a/test/unit/issue_import_test.rb b/test/unit/issue_import_test.rb
index f6ea0570e..04d9a2ba3 100644
--- a/test/unit/issue_import_test.rb
+++ b/test/unit/issue_import_test.rb
@@ -110,7 +110,7 @@ class IssueImportTest < ActiveSupport::TestCase
import.save!
issues = new_records(Issue, 3) {import.run}
- assert_equal ['New', 'New', 'Assigned'], issues.map(&:status).map(&:name)
+ assert_equal ['New', 'New', 'Assigned'], issues.map {|x| x.status.name}
end
def test_parent_should_be_set
diff --git a/test/unit/principal_test.rb b/test/unit/principal_test.rb
index 31b7c3de0..f36ace7be 100644
--- a/test/unit/principal_test.rb
+++ b/test/unit/principal_test.rb
@@ -85,8 +85,8 @@ class PrincipalTest < ActiveSupport::TestCase
users = scope.select {|p| p.is_a?(User)}.sort
groups = scope.select {|p| p.is_a?(Group)}.sort
- assert_equal (users + groups).map(&:name).map(&:downcase),
- scope.sorted.map(&:name).map(&:downcase)
+ assert_equal (users + groups).map {|p| p.name.downcase},
+ scope.sorted.map {|p| p.name.downcase}
end
test "like scope should search login" do
diff --git a/test/unit/time_entry_query_test.rb b/test/unit/time_entry_query_test.rb
index 562917a4d..66243d92b 100644
--- a/test/unit/time_entry_query_test.rb
+++ b/test/unit/time_entry_query_test.rb
@@ -111,9 +111,9 @@ class TimeEntryQueryTest < ActiveSupport::TestCase
:is_filter => true)
query = TimeEntryQuery.new(:project => Project.find(3))
- assert_include "issue.cf_#{global.id}", query.available_columns.map(&:name).map(&:to_s)
- assert_include "issue.cf_#{field_on_project.id}", query.available_columns.map(&:name).map(&:to_s)
- assert_not_include "issue.cf_#{field_not_on_project.id}", query.available_columns.map(&:name).map(&:to_s)
+ assert_include "issue.cf_#{global.id}", query.available_columns.map {|c| c.name.to_s}
+ assert_include "issue.cf_#{field_on_project.id}", query.available_columns.map {|c| c.name.to_s}
+ assert_not_include "issue.cf_#{field_not_on_project.id}", query.available_columns.map {|c| c.name.to_s}
end
def test_issue_category_filter_should_not_be_available_in_global_queries
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index bb108549b..704728a60 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -61,8 +61,8 @@ class UserTest < ActiveSupport::TestCase
def test_sorted_scope_should_sort_user_by_display_name
# Use .active to ignore anonymous with localized display name
- assert_equal User.active.map(&:name).map(&:downcase).sort,
- User.active.sorted.map(&:name).map(&:downcase)
+ assert_equal User.active.map {|u| u.name.downcase}.sort,
+ User.active.sorted.map {|u| u.name.downcase}
end
def test_generate