diff options
Diffstat (limited to 'spec/models/concerns')
-rw-r--r-- | spec/models/concerns/case_sensitivity_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/concerns/ci/has_status_spec.rb | 12 | ||||
-rw-r--r-- | spec/models/concerns/each_batch_spec.rb | 13 | ||||
-rw-r--r-- | spec/models/concerns/has_integrations_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/concerns/limitable_spec.rb | 58 | ||||
-rw-r--r-- | spec/models/concerns/sortable_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/concerns/spammable_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/concerns/strip_attribute_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/concerns/vulnerability_finding_signature_helpers_spec.rb | 32 | ||||
-rw-r--r-- | spec/models/concerns/where_composite_spec.rb | 4 |
10 files changed, 110 insertions, 37 deletions
diff --git a/spec/models/concerns/case_sensitivity_spec.rb b/spec/models/concerns/case_sensitivity_spec.rb index 7cf7b825d7d..269f9577267 100644 --- a/spec/models/concerns/case_sensitivity_spec.rb +++ b/spec/models/concerns/case_sensitivity_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe CaseSensitivity do describe '.iwhere' do - let_it_be(:connection) { ActiveRecord::Base.connection } + let_it_be(:connection) { Namespace.connection } let_it_be(:model) do Class.new(ActiveRecord::Base) do include CaseSensitivity diff --git a/spec/models/concerns/ci/has_status_spec.rb b/spec/models/concerns/ci/has_status_spec.rb index b16420bc658..0709a050056 100644 --- a/spec/models/concerns/ci/has_status_spec.rb +++ b/spec/models/concerns/ci/has_status_spec.rb @@ -351,6 +351,18 @@ RSpec.describe Ci::HasStatus do it_behaves_like 'not containing the job', status end end + + describe '.complete' do + subject { CommitStatus.complete } + + described_class::COMPLETED_STATUSES.each do |status| + it_behaves_like 'containing the job', status + end + + described_class::ACTIVE_STATUSES.each do |status| + it_behaves_like 'not containing the job', status + end + end end describe '::DEFAULT_STATUS' do diff --git a/spec/models/concerns/each_batch_spec.rb b/spec/models/concerns/each_batch_spec.rb index 5f4e5d4bd98..f1fb4fcbd03 100644 --- a/spec/models/concerns/each_batch_spec.rb +++ b/spec/models/concerns/each_batch_spec.rb @@ -9,6 +9,8 @@ RSpec.describe EachBatch do include EachBatch self.table_name = 'users' + + scope :never_signed_in, -> { where(sign_in_count: 0) } end end @@ -72,5 +74,16 @@ RSpec.describe EachBatch do expect(ids).to eq(ids.sort.reverse) end + + describe 'current scope' do + let(:entry) { create(:user, sign_in_count: 1) } + let(:ids_with_new_relation) { model.where(id: entry.id).pluck(:id) } + + it 'does not leak current scope to block being executed' do + model.never_signed_in.each_batch(of: 5) do |relation| + expect(ids_with_new_relation).to include(entry.id) + end + end + end end end diff --git a/spec/models/concerns/has_integrations_spec.rb b/spec/models/concerns/has_integrations_spec.rb index 6b3f75bfcfd..ea6b0e69209 100644 --- a/spec/models/concerns/has_integrations_spec.rb +++ b/spec/models/concerns/has_integrations_spec.rb @@ -17,14 +17,6 @@ RSpec.describe HasIntegrations do create(:integrations_slack, project: project_4, inherit_from_id: nil) end - describe '.with_custom_integration_for' do - it 'returns projects with custom integrations' do - # We use pagination to verify that the group is excluded from the query - expect(Project.with_custom_integration_for(instance_integration, 0, 2)).to contain_exactly(project_2, project_3) - expect(Project.with_custom_integration_for(instance_integration)).to contain_exactly(project_2, project_3) - end - end - describe '.without_integration' do it 'returns projects without integration' do expect(Project.without_integration(instance_integration)).to contain_exactly(project_4) diff --git a/spec/models/concerns/limitable_spec.rb b/spec/models/concerns/limitable_spec.rb index 6b25ed39efb..850282d54c7 100644 --- a/spec/models/concerns/limitable_spec.rb +++ b/spec/models/concerns/limitable_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true -require 'fast_spec_helper' -require 'active_model' +require 'spec_helper' RSpec.describe Limitable do let(:minimal_test_class) do @@ -17,7 +16,7 @@ RSpec.describe Limitable do end before do - stub_const("MinimalTestClass", minimal_test_class) + stub_const('MinimalTestClass', minimal_test_class) end it { expect(MinimalTestClass.limit_name).to eq('test_classes') } @@ -37,25 +36,50 @@ RSpec.describe Limitable do instance.valid?(:create) end - context 'with custom relation' do - before do - MinimalTestClass.limit_relation = :custom_relation + context 'with custom relation and feature flags' do + using RSpec::Parameterized::TableSyntax + + where(:limit_feature_flag, :limit_feature_flag_value, :limit_feature_flag_for_override, :limit_feature_flag_override_value, :expect_limit_applied?) do + nil | nil | nil | nil | true + :some_feature_flag | false | nil | nil | false + :some_feature_flag | true | nil | nil | true + :some_feature_flag | true | :some_feature_flag_disable | false | true + :some_feature_flag | false | :some_feature_flag_disable | false | false + :some_feature_flag | false | :some_feature_flag_disable | true | false + :some_feature_flag | true | :some_feature_flag_disable | true | false end - it 'triggers custom limit_relation' do - instance = MinimalTestClass.new + with_them do + let(:instance) { MinimalTestClass.new } - def instance.project - @project ||= Object.new - end + before do + def instance.project + @project ||= stub_feature_flag_gate('CustomActor') + end + + stub_feature_flags("#{limit_feature_flag}": limit_feature_flag_value ? [instance.project] : false) if limit_feature_flag + stub_feature_flags("#{limit_feature_flag_for_override}": limit_feature_flag_override_value ? [instance.project] : false) if limit_feature_flag_for_override + skip_feature_flags_yaml_validation + skip_default_enabled_yaml_check - limits = Object.new - custom_relation = Object.new - expect(instance).to receive(:custom_relation).and_return(custom_relation) - expect(instance.project).to receive(:actual_limits).and_return(limits) - expect(limits).to receive(:exceeded?).with(instance.class.name.demodulize.tableize, custom_relation).and_return(false) + MinimalTestClass.limit_relation = :custom_relation + MinimalTestClass.limit_feature_flag = limit_feature_flag + MinimalTestClass.limit_feature_flag_for_override = limit_feature_flag_for_override + end - instance.valid?(:create) + it 'acts according to the feature flag settings' do + limits = Object.new + custom_relation = Object.new + if expect_limit_applied? + expect(instance).to receive(:custom_relation).and_return(custom_relation) + expect(instance.project).to receive(:actual_limits).and_return(limits) + expect(limits).to receive(:exceeded?).with(instance.class.name.demodulize.tableize, custom_relation).and_return(false) + else + expect(instance).not_to receive(:custom_relation) + end + + instance.valid?(:create) + end end end end diff --git a/spec/models/concerns/sortable_spec.rb b/spec/models/concerns/sortable_spec.rb index cfa00bab025..f1ae89f33af 100644 --- a/spec/models/concerns/sortable_spec.rb +++ b/spec/models/concerns/sortable_spec.rb @@ -70,8 +70,8 @@ RSpec.describe Sortable do it 'ascending' do expect(relation).to receive(:reorder).once.and_call_original - table = Regexp.escape(ActiveRecord::Base.connection.quote_table_name(:namespaces)) - column = Regexp.escape(ActiveRecord::Base.connection.quote_column_name(:name)) + table = Regexp.escape(ApplicationRecord.connection.quote_table_name(:namespaces)) + column = Regexp.escape(ApplicationRecord.connection.quote_column_name(:name)) sql = relation.order_by('name_asc').to_sql @@ -81,8 +81,8 @@ RSpec.describe Sortable do it 'descending' do expect(relation).to receive(:reorder).once.and_call_original - table = Regexp.escape(ActiveRecord::Base.connection.quote_table_name(:namespaces)) - column = Regexp.escape(ActiveRecord::Base.connection.quote_column_name(:name)) + table = Regexp.escape(ApplicationRecord.connection.quote_table_name(:namespaces)) + column = Regexp.escape(ApplicationRecord.connection.quote_column_name(:name)) sql = relation.order_by('name_desc').to_sql diff --git a/spec/models/concerns/spammable_spec.rb b/spec/models/concerns/spammable_spec.rb index 3c5f3b2d2ad..5edaab56e2d 100644 --- a/spec/models/concerns/spammable_spec.rb +++ b/spec/models/concerns/spammable_spec.rb @@ -28,11 +28,11 @@ RSpec.describe Spammable do it 'returns true for public project' do issue.project.update_attribute(:visibility_level, Gitlab::VisibilityLevel::PUBLIC) - expect(issue.check_for_spam?).to eq(true) + expect(issue.check_for_spam?(user: issue.author)).to eq(true) end it 'returns false for other visibility levels' do - expect(issue.check_for_spam?).to eq(false) + expect(issue.check_for_spam?(user: issue.author)).to eq(false) end end diff --git a/spec/models/concerns/strip_attribute_spec.rb b/spec/models/concerns/strip_attribute_spec.rb index 812f0a015f7..4357bc93361 100644 --- a/spec/models/concerns/strip_attribute_spec.rb +++ b/spec/models/concerns/strip_attribute_spec.rb @@ -5,12 +5,12 @@ require 'spec_helper' RSpec.describe StripAttribute do let(:milestone) { create(:milestone) } - describe ".strip_attributes" do - it { expect(Milestone).to respond_to(:strip_attributes) } + describe ".strip_attributes!" do + it { expect(Milestone).to respond_to(:strip_attributes!) } it { expect(Milestone.strip_attrs).to include(:title) } end - describe "#strip_attributes" do + describe "#strip_attributes!" do before do milestone.title = ' 8.3 ' milestone.valid? diff --git a/spec/models/concerns/vulnerability_finding_signature_helpers_spec.rb b/spec/models/concerns/vulnerability_finding_signature_helpers_spec.rb new file mode 100644 index 00000000000..0a71699971e --- /dev/null +++ b/spec/models/concerns/vulnerability_finding_signature_helpers_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe VulnerabilityFindingSignatureHelpers do + let(:cls) do + Class.new do + include VulnerabilityFindingSignatureHelpers + attr_accessor :algorithm_type + + def initialize(algorithm_type) + @algorithm_type = algorithm_type + end + end + end + + describe '#priority' do + it 'returns numeric values of the priority string' do + expect(cls.new('scope_offset').priority).to eq(3) + expect(cls.new('location').priority).to eq(2) + expect(cls.new('hash').priority).to eq(1) + end + end + + describe '#self.priority' do + it 'returns the numeric value of the provided string' do + expect(cls.priority('scope_offset')).to eq(3) + expect(cls.priority('location')).to eq(2) + expect(cls.priority('hash')).to eq(1) + end + end +end diff --git a/spec/models/concerns/where_composite_spec.rb b/spec/models/concerns/where_composite_spec.rb index fb23e6bfe1d..5e67f2f5b65 100644 --- a/spec/models/concerns/where_composite_spec.rb +++ b/spec/models/concerns/where_composite_spec.rb @@ -8,7 +8,7 @@ RSpec.describe WhereComposite do let(:model) do tbl_name = test_table_name - Class.new(ActiveRecord::Base) do + Class.new(ApplicationRecord) do self.table_name = tbl_name include WhereComposite @@ -16,7 +16,7 @@ RSpec.describe WhereComposite do end def connection - ActiveRecord::Base.connection + ApplicationRecord.connection end before_all do |