]> source.dussan.org Git - redmine.git/commitdiff
Code cleanup: RuboCop: Fix Performance/Count and Performance/Detect.
authorGo MAEDA <maeda@farend.jp>
Wed, 2 Oct 2019 00:53:11 +0000 (00:53 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 2 Oct 2019 00:53:11 +0000 (00:53 +0000)
This change corrects newly detected offenses after updating rubocop-performance to 1.5.0 in r18579.

git-svn-id: http://svn.redmine.org/redmine/trunk@18580 e93f8b46-1217-0410-a6f0-8f06a7374b81

.rubocop_todo.yml
test/functional/workflows_controller_test.rb
test/integration/api_test/issues_test.rb
test/unit/issue_test.rb
test/unit/project_copy_test.rb

index 1e81345cd897fd1ebb1db7eed09962d60599ed91..69f85ebccc6e964e2bebd6d33edb6c5175ba8274 100644 (file)
@@ -690,18 +690,6 @@ Naming/VariableNumber:
     - 'test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb'
     - 'test/unit/project_test.rb'
 
-# Cop supports --auto-correct.
-Performance/Count:
-  Exclude:
-    - 'test/functional/workflows_controller_test.rb'
-    - 'test/integration/api_test/issues_test.rb'
-    - 'test/unit/issue_test.rb'
-
-# Cop supports --auto-correct.
-Performance/Detect:
-  Exclude:
-    - 'test/unit/project_copy_test.rb'
-
 Performance/FixedSize:
   Exclude:
     - 'test/integration/api_test/issues_test.rb'
index 708afa6f9bef1f3effe6154bf19a02ce3a819f60..42c5ae4a3b1672b5b5f0519addea62368cb2da9a 100644 (file)
@@ -95,7 +95,7 @@ class WorkflowsControllerTest < Redmine::ControllerTest
     assert_response :success
 
     assert_select 'select[name=?][multiple=multiple]', 'role_id[]' do
-      assert_select 'option[selected=selected]', Role.all.select(&:consider_workflow?).count
+      assert_select 'option[selected=selected]', Role.all.count(&:consider_workflow?)
     end
     assert_select 'select[name=?]', 'tracker_id[]' do
       assert_select 'option[selected=selected][value=all]'
index dbfb05debd58aca5866a137308c35944719cabd8..d7b9d4d5548723cf9a80ef1413a4b343370f50da 100644 (file)
@@ -338,7 +338,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
 
     json = ActiveSupport::JSON.decode(response.body)
     assert_equal 2, json['issue']['children'].size
-    assert_equal 1, json['issue']['children'].select {|child| child.key?('children')}.size
+    assert_equal 1, json['issue']['children'].count {|child| child.key?('children')}
   end
 
   test "GET /issues/:id.json with no spent time should return floats" do
index baedfec0f0f08650c810957d07128c5b86b78250..0c3315459412c24206bba0c0dd8ad895ca6464f6 100644 (file)
@@ -2499,7 +2499,7 @@ class IssueTest < ActiveSupport::TestCase
     assert_equal 2, assignable_user_ids.length
 
     assignable_user_ids.each do |user_id|
-      assert_equal 1, assignable_user_ids.select {|i| i == user_id}.length,
+      assert_equal 1, assignable_user_ids.count {|i| i == user_id},
                    "User #{user_id} appears more or less than once"
     end
   end
index fb07d6b65fe27f61f29b328b649f5ac98c422a2e..af56c15a9b262b8bb1dcda980ee70a03a2a84baf 100644 (file)
@@ -200,7 +200,7 @@ class ProjectCopyTest < ActiveSupport::TestCase
 
     # Second issue with a cross project relation
     assert_equal 2, copied_second_issue.relations.size, "Relation not copied"
-    copied_relation = copied_second_issue.relations.select {|r| r.relation_type == 'duplicates'}.first
+    copied_relation = copied_second_issue.relations.find {|r| r.relation_type == 'duplicates'}
     assert_equal "duplicates", copied_relation.relation_type
     assert_equal 1, copied_relation.issue_from_id, "Cross project relation not kept"
     assert_not_equal source_relation_cross_project.id, copied_relation.id