debian-mirror-gitlab/spec/lib/extracts_path_spec.rb

149 lines
3.9 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe ExtractsPath do
include described_class
2015-09-11 14:41:01 +05:30
include RepoHelpers
2017-09-10 17:25:29 +05:30
include Gitlab::Routing
2014-09-02 18:07:02 +05:30
2020-06-23 00:09:42 +05:30
let_it_be(:owner) { create(:user) }
let_it_be(:container) { create(:project, :repository, creator: owner) }
2016-11-03 12:29:30 +05:30
let(:request) { double('request') }
2014-09-02 18:07:02 +05:30
before do
2020-06-23 00:09:42 +05:30
@project = container
ref_names = ['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0', 'release/app', 'release/app/v1.0.0']
2015-09-11 14:41:01 +05:30
2020-06-23 00:09:42 +05:30
allow(container.repository).to receive(:ref_names).and_return(ref_names)
2016-11-03 12:29:30 +05:30
allow(request).to receive(:format=)
2015-09-11 14:41:01 +05:30
end
2016-11-03 12:29:30 +05:30
describe '#assign_ref_vars' do
2015-09-11 14:41:01 +05:30
let(:ref) { sample_commit[:id] }
let(:params) { { path: sample_commit[:line_code_path], ref: ref } }
2020-06-23 00:09:42 +05:30
it_behaves_like 'assigns ref vars'
2015-09-11 14:41:01 +05:30
2020-06-23 00:09:42 +05:30
it 'log tree path has no escape sequences' do
2015-09-11 14:41:01 +05:30
assign_ref_vars
2019-07-31 22:56:46 +05:30
2020-06-23 00:09:42 +05:30
expect(@logs_path).to eq("/#{@project.full_path}/-/refs/#{ref}/logs_tree/files/ruby/popen.rb")
2019-07-31 22:56:46 +05:30
end
context 'ref contains space in the middle' do
let(:ref) { 'master plan ' }
it 'returns 404' do
expect(self).to receive(:render_404)
assign_ref_vars
end
end
2016-11-03 12:29:30 +05:30
context 'ref only exists without .atom suffix' do
context 'with a path' do
let(:params) { { ref: 'v1.0.0.atom', path: 'README.md' } }
it 'renders a 404' do
expect(self).to receive(:render_404)
assign_ref_vars
end
end
context 'without a path' do
let(:params) { { ref: 'v1.0.0.atom' } }
2017-09-10 17:25:29 +05:30
before do
assign_ref_vars
end
2016-11-03 12:29:30 +05:30
it 'sets the un-suffixed version as @ref' do
expect(@ref).to eq('v1.0.0')
end
it 'sets the request format to Atom' do
expect(request).to have_received(:format=).with(:atom)
end
end
end
context 'ref exists with .atom suffix' do
context 'with a path' do
let(:params) { { ref: 'master.atom', path: 'README.md' } }
before do
repository = @project.repository
allow(repository).to receive(:commit).and_call_original
allow(repository).to receive(:commit).with('master.atom').and_return(repository.commit('master'))
assign_ref_vars
end
it 'sets the suffixed version as @ref' do
expect(@ref).to eq('master.atom')
end
it 'does not change the request format' do
expect(request).not_to have_received(:format=)
end
end
context 'without a path' do
let(:params) { { ref: 'master.atom' } }
before do
repository = @project.repository
allow(repository).to receive(:commit).and_call_original
allow(repository).to receive(:commit).with('master.atom').and_return(repository.commit('master'))
end
it 'sets the suffixed version as @ref' do
assign_ref_vars
expect(@ref).to eq('master.atom')
end
it 'does not change the request format' do
expect(request).not_to receive(:format=)
assign_ref_vars
end
end
end
2014-09-02 18:07:02 +05:30
end
2020-06-23 00:09:42 +05:30
it_behaves_like 'extracts refs'
2016-11-03 12:29:30 +05:30
describe '#extract_ref_without_atom' do
it 'ignores any matching refs suffixed with atom' do
expect(extract_ref_without_atom('master.atom')).to eq('master')
end
it 'returns the longest matching ref' do
expect(extract_ref_without_atom('release/app/v1.0.0.atom')).to eq('release/app/v1.0.0')
end
it 'returns nil if there are no matching refs' do
expect(extract_ref_without_atom('foo.atom')).to eq(nil)
end
end
2018-11-18 11:00:15 +05:30
describe '#lfs_blob_ids' do
2019-02-15 15:39:39 +05:30
let(:tag) { @project.repository.add_tag(@project.owner, 'my-annotated-tag', 'master', 'test tag') }
let(:ref) { tag.target }
let(:params) { { ref: ref, path: 'README.md' } }
2018-11-18 11:00:15 +05:30
2019-02-15 15:39:39 +05:30
before do
@project = create(:project, :repository)
2018-11-18 11:00:15 +05:30
end
2019-02-15 15:39:39 +05:30
it 'handles annotated tags' do
assign_ref_vars
2018-11-18 11:00:15 +05:30
2019-02-15 15:39:39 +05:30
expect(lfs_blob_ids).to eq([])
2018-11-18 11:00:15 +05:30
end
end
2014-09-02 18:07:02 +05:30
end