Commit a6948538 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Improve specs

parent 71ef0c9e
...@@ -538,7 +538,7 @@ module Ci ...@@ -538,7 +538,7 @@ module Ci
end end
def shared_runners_minutes_quota? def shared_runners_minutes_quota?
runner && runner.shared? && !project.public? runner && runner.shared? && project.shared_runners_minutes_quota?
end end
private private
......
...@@ -1567,6 +1567,10 @@ class Project < ActiveRecord::Base ...@@ -1567,6 +1567,10 @@ class Project < ActiveRecord::Base
end end
end end
def shared_runners_minutes_quota?
!public? && shared_runners_enabled?
end
private private
# Check if a reference is being done cross-project # Check if a reference is being done cross-project
......
- project = local_assigns.fetch(:project, nil) - project = local_assigns.fetch(:project, nil)
- namespace = local_assigns.fetch(:namespace, project && project.namespace)
- has_limit = (project || namespace).shared_runners_minutes_limit_enabled? - if cookies[:hide_shared_runner_quota_message].blank? &&
- can_see_status = project.nil? || can?(current_user, :create_pipeline, project) project.shared_runners_minutes_quota? &&
- if cookies[:hide_shared_runner_quota_message].blank? && has_limit && namespace.shared_runners_minutes_used? && can_see_status namespace.shared_runners_minutes_used? &&
can?(current_user, :create_pipeline, project)
.shared-runner-quota-message.alert.alert-warning.hidden-xs .shared-runner-quota-message.alert.alert-warning.hidden-xs
= namespace.name = namespace.name
has exceeded their build minutes quota. Pipelines will not run anymore on shared runners. has exceeded their build minutes quota. Pipelines will not run anymore on shared runners.
......
...@@ -1330,28 +1330,11 @@ describe Ci::Build, models: true do ...@@ -1330,28 +1330,11 @@ describe Ci::Build, models: true do
build.runner = create(:ci_runner, :shared) build.runner = create(:ci_runner, :shared)
end end
context 'for public project' do it do
before do expect(build.project).to receive(:shared_runners_minutes_quota?).
build.project.visibility_level = Gitlab::VisibilityLevel::PUBLIC and_return(true)
end
it { is_expected.to be_falsey }
end
context 'for internal project' do
before do
build.project.visibility_level = Gitlab::VisibilityLevel::INTERNAL
end
it { is_expected.to be_truthy } is_expected.to be_truthy
end
context 'for private project' do
before do
build.project.visibility_level = Gitlab::VisibilityLevel::INTERNAL
end
it { is_expected.to be_truthy }
end end
end end
......
...@@ -2092,6 +2092,48 @@ describe Project, models: true do ...@@ -2092,6 +2092,48 @@ describe Project, models: true do
end end
end end
describe '#shared_runners_minutes_quota?' do
subject { project.shared_runners_minutes_quota? }
context 'with shared runners enabled' do
before do
project.shared_runners_enabled = true
end
context 'for public project' do
before do
project.visibility_level = Project::PUBLIC
end
it { is_expected.to be_falsey }
end
context 'for internal project' do
before do
project.visibility_level = Project::INTERNAL
end
it { is_expected.to be_truthy }
end
context 'for private project' do
before do
project.visibility_level = Project::INTERNAL
end
it { is_expected.to be_truthy }
end
end
context 'without shared runners' do
before do
project.shared_runners_enabled = false
end
it { is_expected.to be_falsey }
end
end
def enable_lfs def enable_lfs
allow(Gitlab.config.lfs).to receive(:enabled).and_return(true) allow(Gitlab.config.lfs).to receive(:enabled).and_return(true)
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