Commit 2de7ac3b authored by Patrick Bajao's avatar Patrick Bajao

Merge branch '280795-stop-finding-commit-empty-ref' into 'master'

Stop finding commit with empty ref

See merge request gitlab-org/gitlab!47497
parents 10332fe7 469d8c66
---
title: Stop finding commit with empty ref
merge_request: 47497
author:
type: fixed
...@@ -68,7 +68,7 @@ module ExtractsRef ...@@ -68,7 +68,7 @@ module ExtractsRef
raise InvalidPathError if @ref.match?(/\s/) raise InvalidPathError if @ref.match?(/\s/)
@commit = @repo.commit(@ref) @commit = @repo.commit(@ref) if @ref.present?
end end
# rubocop:enable Gitlab/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
......
...@@ -112,6 +112,19 @@ RSpec.describe ExtractsPath do ...@@ -112,6 +112,19 @@ RSpec.describe ExtractsPath do
end end
end end
end end
context 'ref and path are nil' do
let(:params) { { path: nil, ref: nil } }
it 'does not set commit' do
expect(container.repository).not_to receive(:commit).with('')
expect(self).to receive(:render_404)
assign_ref_vars
expect(@commit).to be_nil
end
end
end end
it_behaves_like 'extracts refs' it_behaves_like 'extracts refs'
......
...@@ -18,6 +18,21 @@ RSpec.describe ExtractsRef do ...@@ -18,6 +18,21 @@ RSpec.describe ExtractsRef do
allow_any_instance_of(described_class).to receive(:repository_container).and_return(container) allow_any_instance_of(described_class).to receive(:repository_container).and_return(container)
end end
it_behaves_like 'assigns ref vars' describe '#assign_ref_vars' do
it_behaves_like 'assigns ref vars'
context 'ref and path are nil' do
let(:params) { { path: nil, ref: nil } }
it 'does not set commit' do
expect(container.repository).not_to receive(:commit).with('')
assign_ref_vars
expect(@commit).to be_nil
end
end
end
it_behaves_like 'extracts refs' it_behaves_like 'extracts refs'
end 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