diff options
-rw-r--r-- | app/models/project.rb | 8 | ||||
-rw-r--r-- | changelogs/unreleased/52778-don-t-display-pipeline-status-if-pipelines-are-disabled.yml | 5 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 24 | ||||
-rw-r--r-- | spec/views/projects/commits/_commit.html.haml_spec.rb | 59 |
4 files changed, 92 insertions, 4 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 62e73e2ef9f..9c3dbf63867 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -595,6 +595,14 @@ class Project < ActiveRecord::Base end end + def ci_pipelines + if builds_enabled? + super + else + super.external + end + end + # returns all ancestor-groups upto but excluding the given namespace # when no namespace is given, all ancestors upto the top are returned def ancestors_upto(top = nil, hierarchy_order: nil) diff --git a/changelogs/unreleased/52778-don-t-display-pipeline-status-if-pipelines-are-disabled.yml b/changelogs/unreleased/52778-don-t-display-pipeline-status-if-pipelines-are-disabled.yml new file mode 100644 index 00000000000..7fa01e2835a --- /dev/null +++ b/changelogs/unreleased/52778-don-t-display-pipeline-status-if-pipelines-are-disabled.yml @@ -0,0 +1,5 @@ +--- +title: Hide pipeline status when pipelines are disabled on project. +merge_request: 25204 +author: +type: fixed diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 1f9088c2e6b..a78647cb89a 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -428,6 +428,30 @@ describe Project do end end + describe '#ci_pipelines' do + let(:project) { create(:project) } + + before do + create(:ci_pipeline, project: project, ref: 'master', source: :web) + create(:ci_pipeline, project: project, ref: 'master', source: :external) + end + + it 'has ci pipelines' do + expect(project.ci_pipelines.size).to eq(2) + end + + context 'when builds are disabled' do + before do + project.project_feature.update_attribute(:builds_access_level, ProjectFeature::DISABLED) + end + + it 'should return .external pipelines' do + expect(project.ci_pipelines).to all(have_attributes(source: 'external')) + expect(project.ci_pipelines.size).to eq(1) + end + end + end + describe 'project token' do it 'sets an random token if none provided' do project = FactoryBot.create(:project, runners_token: '') diff --git a/spec/views/projects/commits/_commit.html.haml_spec.rb b/spec/views/projects/commits/_commit.html.haml_spec.rb index 00547e433c4..6bf1b5fd2d0 100644 --- a/spec/views/projects/commits/_commit.html.haml_spec.rb +++ b/spec/views/projects/commits/_commit.html.haml_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' describe 'projects/commits/_commit.html.haml' do + let(:project) { create(:project, :repository) } + let(:commit) { project.repository.commit(ref) } + before do allow(view).to receive(:current_application_settings).and_return(Gitlab::CurrentSettings.current_application_settings) end - context 'with a singed commit' do - let(:project) { create(:project, :repository) } - let(:repository) { project.repository } + context 'with a signed commit' do let(:ref) { GpgHelpers::SIGNED_COMMIT_SHA } - let(:commit) { repository.commit(ref) } it 'does not display a loading spinner for GPG status' do render partial: 'projects/commits/commit', locals: { @@ -23,4 +23,55 @@ describe 'projects/commits/_commit.html.haml' do end end end + + context 'with ci status' do + let(:ref) { 'master' } + let(:user) { create(:user) } + + before do + allow(view).to receive(:current_user).and_return(user) + + project.add_developer(user) + + create( + :ci_empty_pipeline, + ref: 'master', + sha: commit.id, + status: 'success', + project: project + ) + end + + context 'when pipelines are disabled' do + before do + allow(project).to receive(:builds_enabled?).and_return(false) + end + + it 'does not display a ci status icon' do + render partial: 'projects/commits/commit', locals: { + project: project, + ref: ref, + commit: commit + } + + expect(rendered).not_to have_css('.ci-status-link') + end + end + + context 'when pipelines are enabled' do + before do + allow(project).to receive(:builds_enabled?).and_return(true) + end + + it 'does display a ci status icon when pipelines are enabled' do + render partial: 'projects/commits/commit', locals: { + project: project, + ref: ref, + commit: commit + } + + expect(rendered).to have_css('.ci-status-link') + end + end + end end |