diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/lib/extracts_path_spec.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/lib/extracts_path_spec.rb')
-rw-r--r-- | spec/lib/extracts_path_spec.rb | 126 |
1 files changed, 9 insertions, 117 deletions
diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb index ef9929a9dce..a56768a1a88 100644 --- a/spec/lib/extracts_path_spec.rb +++ b/spec/lib/extracts_path_spec.rb @@ -7,17 +7,15 @@ describe ExtractsPath do include RepoHelpers include Gitlab::Routing - let(:project) { double('project') } + let_it_be(:owner) { create(:user) } + let_it_be(:container) { create(:project, :repository, creator: owner) } let(:request) { double('request') } before do - @project = project + @project = container + ref_names = ['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0', 'release/app', 'release/app/v1.0.0'] - repo = double(ref_names: ['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0', - 'release/app', 'release/app/v1.0.0']) - allow(project).to receive(:repository).and_return(repo) - allow(project).to receive(:full_path) - .and_return('gitlab/gitlab-ci') + allow(container.repository).to receive(:ref_names).and_return(ref_names) allow(request).to receive(:format=) end @@ -25,45 +23,12 @@ describe ExtractsPath do let(:ref) { sample_commit[:id] } let(:params) { { path: sample_commit[:line_code_path], ref: ref } } - before do - @project = create(:project, :repository) - end + it_behaves_like 'assigns ref vars' - it "log tree path has no escape sequences" do + it 'log tree path has no escape sequences' do assign_ref_vars - expect(@logs_path).to eq("/#{@project.full_path}/-/refs/#{ref}/logs_tree/files/ruby/popen.rb") - end - - context 'ref contains %20' do - let(:ref) { 'foo%20bar' } - - it 'is not converted to a space in @id' do - @project.repository.add_branch(@project.owner, 'foo%20bar', 'master') - - assign_ref_vars - - expect(@id).to start_with('foo%20bar/') - end - end - - context 'ref contains trailing space' do - let(:ref) { 'master ' } - - it 'strips surrounding space' do - assign_ref_vars - expect(@ref).to eq('master') - end - end - - context 'ref contains leading space' do - let(:ref) { ' master ' } - - it 'strips surrounding space' do - assign_ref_vars - - expect(@ref).to eq('master') - end + expect(@logs_path).to eq("/#{@project.full_path}/-/refs/#{ref}/logs_tree/files/ruby/popen.rb") end context 'ref contains space in the middle' do @@ -76,28 +41,6 @@ describe ExtractsPath do end end - context 'path contains space' do - let(:params) { { path: 'with space', ref: '38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e' } } - - it 'is not converted to %20 in @path' do - assign_ref_vars - - expect(@path).to eq(params[:path]) - end - end - - context 'subclass overrides get_id' do - it 'uses ref returned by get_id' do - allow_next_instance_of(self.class) do |instance| - allow(instance).to receive(:get_id) { '38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e' } - end - - assign_ref_vars - - expect(@id).to eq(get_id) - end - end - context 'ref only exists without .atom suffix' do context 'with a path' do let(:params) { { ref: 'v1.0.0.atom', path: 'README.md' } } @@ -171,58 +114,7 @@ describe ExtractsPath do end end - describe '#extract_ref' do - it "returns an empty pair when no @project is set" do - @project = nil - expect(extract_ref('master/CHANGELOG')).to eq(['', '']) - end - - context "without a path" do - it "extracts a valid branch" do - expect(extract_ref('master')).to eq(['master', '']) - end - - it "extracts a valid tag" do - expect(extract_ref('v2.0.0')).to eq(['v2.0.0', '']) - end - - it "extracts a valid commit ref without a path" do - expect(extract_ref('f4b14494ef6abf3d144c28e4af0c20143383e062')).to eq( - ['f4b14494ef6abf3d144c28e4af0c20143383e062', ''] - ) - end - - it "falls back to a primitive split for an invalid ref" do - expect(extract_ref('stable')).to eq(['stable', '']) - end - - it "extracts the longest matching ref" do - expect(extract_ref('release/app/v1.0.0/README.md')).to eq( - ['release/app/v1.0.0', 'README.md']) - end - end - - context "with a path" do - it "extracts a valid branch" do - expect(extract_ref('foo/bar/baz/CHANGELOG')).to eq( - ['foo/bar/baz', 'CHANGELOG']) - end - - it "extracts a valid tag" do - expect(extract_ref('v2.0.0/CHANGELOG')).to eq(['v2.0.0', 'CHANGELOG']) - end - - it "extracts a valid commit SHA" do - expect(extract_ref('f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG')).to eq( - %w(f4b14494ef6abf3d144c28e4af0c20143383e062 CHANGELOG) - ) - end - - it "falls back to a primitive split for an invalid ref" do - expect(extract_ref('stable/CHANGELOG')).to eq(%w(stable CHANGELOG)) - end - end - end + it_behaves_like 'extracts refs' describe '#extract_ref_without_atom' do it 'ignores any matching refs suffixed with atom' do |