Commit 1b73e05d authored by Igor Drozdov's avatar Igor Drozdov

Fix Performance/Detect offences

It encourages using `.find` instead of `select {...}.first`
parent 7530be6f
......@@ -289,17 +289,6 @@ Performance/DeleteSuffix:
- 'ee/app/models/geo/upload_registry.rb'
- 'ee/app/workers/geo/file_download_dispatch_worker/attachment_job_finder.rb'
# Offense count: 13
# Cop supports --auto-correct.
Performance/Detect:
Exclude:
- 'ee/spec/controllers/projects/dependencies_controller_spec.rb'
- 'ee/spec/requests/api/dependencies_spec.rb'
- 'qa/qa/runtime/feature.rb'
- 'spec/lib/gitlab/git/tree_spec.rb'
- 'spec/lib/gitlab/import_export/project/tree_restorer_spec.rb'
- 'spec/models/event_spec.rb'
# Offense count: 121
Performance/MethodObjectAsBlock:
Enabled: false
......
......@@ -147,7 +147,7 @@ RSpec.describe Projects::DependenciesController do
end
it 'returns vulnerability params' do
dependency = json_response['dependencies'].select { |dep| dep['name'] == 'nokogiri' }.first
dependency = json_response['dependencies'].find { |dep| dep['name'] == 'nokogiri' }
vulnerability = dependency['vulnerabilities'].first
path = "/security/vulnerabilities/#{finding.vulnerability_id}"
......@@ -182,7 +182,7 @@ RSpec.describe Projects::DependenciesController do
end
it 'include license information to response' do
nokogiri = json_response['dependencies'].select { |dep| dep['name'] == 'nokogiri' }.first
nokogiri = json_response['dependencies'].find { |dep| dep['name'] == 'nokogiri' }
expect(nokogiri['licenses']).not_to be_empty
end
......
......@@ -37,7 +37,7 @@ RSpec.describe API::Dependencies do
end
it 'returns vulnerabilities info' do
vulnerability = json_response.select { |dep| dep['name'] == 'nokogiri' }[0]['vulnerabilities'][0]
vulnerability = json_response.find { |dep| dep['name'] == 'nokogiri' }['vulnerabilities'][0]
path = "/security/vulnerabilities/#{finding.vulnerability_id}"
expect(vulnerability['name']).to eq('Vulnerabilities in libxml2 in nokogiri')
......
......@@ -43,7 +43,7 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
end
describe '#dir?' do
let(:dir) { entries.select(&:dir?).first }
let(:dir) { entries.find(&:dir?) }
it { expect(dir).to be_kind_of Gitlab::Git::Tree }
it { expect(dir.id).to eq('3c122d2b7830eca25235131070602575cf8b41a1') }
......@@ -134,7 +134,7 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
end
describe '#file?' do
let(:file) { entries.select(&:file?).first }
let(:file) { entries.find(&:file?) }
it { expect(file).to be_kind_of Gitlab::Git::Tree }
it { expect(file.id).to eq('dfaa3f97ca337e20154a98ac9d0be76ddd1fcc82') }
......@@ -143,21 +143,21 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
end
describe '#readme?' do
let(:file) { entries.select(&:readme?).first }
let(:file) { entries.find(&:readme?) }
it { expect(file).to be_kind_of Gitlab::Git::Tree }
it { expect(file.name).to eq('README.md') }
end
describe '#contributing?' do
let(:file) { entries.select(&:contributing?).first }
let(:file) { entries.find(&:contributing?) }
it { expect(file).to be_kind_of Gitlab::Git::Tree }
it { expect(file.name).to eq('CONTRIBUTING.md') }
end
describe '#submodule?' do
let(:submodule) { entries.select(&:submodule?).first }
let(:submodule) { entries.find(&:submodule?) }
it { expect(submodule).to be_kind_of Gitlab::Git::Tree }
it { expect(submodule.id).to eq('79bceae69cb5750d6567b223597999bfa91cb3b9') }
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
def match_mr1_note(content_regex)
MergeRequest.find_by(title: 'MR1').notes.select { |n| n.note.match(/#{content_regex}/)}.first
MergeRequest.find_by(title: 'MR1').notes.find { |n| n.note.match(/#{content_regex}/) }
end
RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
......@@ -75,7 +75,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
context 'for an Issue' do
it 'does not import note_html' do
note_content = 'Quo reprehenderit aliquam qui dicta impedit cupiditate eligendi'
issue_note = Issue.find_by(description: 'Aliquam enim illo et possimus.').notes.select { |n| n.note.match(/#{note_content}/)}.first
issue_note = Issue.find_by(description: 'Aliquam enim illo et possimus.').notes.find { |n| n.note.match(/#{note_content}/) }
expect(issue_note.note_html).to match(/#{note_content}/)
end
......@@ -552,7 +552,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
it 'issue system note metadata restored successfully' do
note_content = 'created merge request !1 to address this issue'
note = project.issues.first.notes.select { |n| n.note.match(/#{note_content}/)}.first
note = project.issues.first.notes.find { |n| n.note.match(/#{note_content}/)}
expect(note.noteable_type).to eq('Issue')
expect(note.system).to eq(true)
......
......@@ -706,7 +706,7 @@ RSpec.describe Event do
describe '.for_wiki_meta' do
it 'finds events for a given wiki page metadata object' do
event = events.select(&:wiki_page?).first
event = events.find(&:wiki_page?)
expect(described_class.for_wiki_meta(event.target)).to contain_exactly(event)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment