summaryrefslogtreecommitdiff
path: root/spec/models/plan_limits_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
commit9f46488805e86b1bc341ea1620b866016c2ce5ed (patch)
treef9748c7e287041e37d6da49e0a29c9511dc34768 /spec/models/plan_limits_spec.rb
parentdfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff)
downloadgitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/models/plan_limits_spec.rb')
-rw-r--r--spec/models/plan_limits_spec.rb74
1 files changed, 74 insertions, 0 deletions
diff --git a/spec/models/plan_limits_spec.rb b/spec/models/plan_limits_spec.rb
new file mode 100644
index 00000000000..1366f088623
--- /dev/null
+++ b/spec/models/plan_limits_spec.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe PlanLimits do
+ let(:plan_limits) { create(:plan_limits) }
+ let(:model) { ProjectHook }
+ let(:count) { model.count }
+
+ before do
+ create(:project_hook)
+ end
+
+ context 'without plan limits configured' do
+ describe '#exceeded?' do
+ it 'does not exceed any relation offset' do
+ expect(plan_limits.exceeded?(:project_hooks, model)).to be false
+ expect(plan_limits.exceeded?(:project_hooks, count)).to be false
+ end
+ end
+ end
+
+ context 'with plan limits configured' do
+ before do
+ plan_limits.update!(project_hooks: 2)
+ end
+
+ describe '#exceeded?' do
+ it 'does not exceed the relation offset' do
+ expect(plan_limits.exceeded?(:project_hooks, model)).to be false
+ expect(plan_limits.exceeded?(:project_hooks, count)).to be false
+ end
+ end
+
+ context 'with boundary values' do
+ before do
+ create(:project_hook)
+ end
+
+ describe '#exceeded?' do
+ it 'does exceed the relation offset' do
+ expect(plan_limits.exceeded?(:project_hooks, model)).to be true
+ expect(plan_limits.exceeded?(:project_hooks, count)).to be true
+ end
+ end
+ end
+ end
+
+ context 'validates default values' do
+ let(:columns_with_zero) do
+ %w[
+ ci_active_pipelines
+ ci_pipeline_size
+ ci_active_jobs
+ ]
+ end
+
+ it "has positive values for enabled limits" do
+ attributes = plan_limits.attributes
+ attributes = attributes.except(described_class.primary_key)
+ attributes = attributes.except(described_class.reflections.values.map(&:foreign_key))
+ attributes = attributes.except(*columns_with_zero)
+
+ expect(attributes).to all(include(be_positive))
+ end
+
+ it "has zero values for disabled limits" do
+ attributes = plan_limits.attributes
+ attributes = attributes.slice(*columns_with_zero)
+
+ expect(attributes).to all(include(be_zero))
+ end
+ end
+end