diff options
Diffstat (limited to 'spec/presenters')
-rw-r--r-- | spec/presenters/ci/build_runner_presenter_spec.rb | 28 | ||||
-rw-r--r-- | spec/presenters/packages/nuget/service_index_presenter_spec.rb | 55 |
2 files changed, 68 insertions, 15 deletions
diff --git a/spec/presenters/ci/build_runner_presenter_spec.rb b/spec/presenters/ci/build_runner_presenter_spec.rb index ce4c5a2db7d..f78ad38f4e8 100644 --- a/spec/presenters/ci/build_runner_presenter_spec.rb +++ b/spec/presenters/ci/build_runner_presenter_spec.rb @@ -189,7 +189,21 @@ RSpec.describe Ci::BuildRunnerPresenter do it 'returns the correct refspecs' do is_expected.to contain_exactly("+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}", - "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}") + "+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") + end + + it 'uses a SHA in the persistent refspec' do + expect(subject[0]).to match(/^\+[0-9a-f]{40}:refs\/pipelines\/[0-9]+$/) + end + + context 'when the scalability_ci_fetch_sha feature flag is disabled' do + before do + stub_feature_flags(scalability_ci_fetch_sha: false) + end + + it 'fetches the ref by name' do + expect(subject[0]).to eq("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}") + end end context 'when ref is tag' do @@ -197,7 +211,7 @@ RSpec.describe Ci::BuildRunnerPresenter do it 'returns the correct refspecs' do is_expected.to contain_exactly("+refs/tags/#{build.ref}:refs/tags/#{build.ref}", - "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}") + "+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") end context 'when GIT_DEPTH is zero' do @@ -208,7 +222,7 @@ RSpec.describe Ci::BuildRunnerPresenter do it 'returns the correct refspecs' do is_expected.to contain_exactly('+refs/tags/*:refs/tags/*', '+refs/heads/*:refs/remotes/origin/*', - "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}") + "+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") end end end @@ -224,7 +238,7 @@ RSpec.describe Ci::BuildRunnerPresenter do it 'returns the correct refspecs' do is_expected - .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}") + .to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") end context 'when GIT_DEPTH is zero' do @@ -234,7 +248,7 @@ RSpec.describe Ci::BuildRunnerPresenter do it 'returns the correct refspecs' do is_expected - .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}", + .to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", '+refs/heads/*:refs/remotes/origin/*', '+refs/tags/*:refs/tags/*') end @@ -244,7 +258,7 @@ RSpec.describe Ci::BuildRunnerPresenter do let(:merge_request) { create(:merge_request, :with_legacy_detached_merge_request_pipeline) } it 'returns the correct refspecs' do - is_expected.to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}", + is_expected.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", "+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}") end end @@ -262,7 +276,7 @@ RSpec.describe Ci::BuildRunnerPresenter do it 'exposes the persistent pipeline ref' do is_expected - .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}", + .to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", "+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}") end end diff --git a/spec/presenters/packages/nuget/service_index_presenter_spec.rb b/spec/presenters/packages/nuget/service_index_presenter_spec.rb index 19ef890e19f..9c95fbc8fd2 100644 --- a/spec/presenters/packages/nuget/service_index_presenter_spec.rb +++ b/spec/presenters/packages/nuget/service_index_presenter_spec.rb @@ -4,25 +4,64 @@ require 'spec_helper' RSpec.describe ::Packages::Nuget::ServiceIndexPresenter do let_it_be(:project) { create(:project) } - let_it_be(:presenter) { described_class.new(project) } + let_it_be(:group) { create(:group) } + + let(:presenter) { described_class.new(target) } describe '#version' do subject { presenter.version } - it { is_expected.to eq '3.0.0' } + context 'for a group' do + let(:target) { group } + + it { is_expected.to eq '3.0.0' } + end + + context 'for a project' do + let(:target) { project } + + it { is_expected.to eq '3.0.0' } + end end describe '#resources' do subject { presenter.resources } - it 'has valid resources' do - expect(subject.size).to eq 8 - subject.each do |resource| - %i[@id @type comment].each do |field| - expect(resource).to have_key(field) - expect(resource[field]).to be_a(String) + shared_examples 'returning valid resources' do |resources_count: 8, include_publish_service: true| + it 'has valid resources' do + expect(subject.size).to eq resources_count + subject.each do |resource| + %i[@id @type comment].each do |field| + expect(resource).to have_key(field) + expect(resource[field]).to be_a(String) + end + end + end + + it "does #{'not ' unless include_publish_service}return the publish resource" do + services_types = subject.map { |res| res[:@type] } + + described_class::SERVICE_VERSIONS[:publish].each do |publish_service_version| + if include_publish_service + expect(services_types).to include(publish_service_version) + else + expect(services_types).not_to include(publish_service_version) + end end end end + + context 'for a group' do + let(:target) { group } + + # at the group level we don't have the publish and download service + it_behaves_like 'returning valid resources', resources_count: 6, include_publish_service: false + end + + context 'for a project' do + let(:target) { project } + + it_behaves_like 'returning valid resources' + end end end |