diff options
Diffstat (limited to 'spec/models/concerns')
-rw-r--r-- | spec/models/concerns/approvable_spec.rb (renamed from spec/models/concerns/approvable_base_spec.rb) | 2 | ||||
-rw-r--r-- | spec/models/concerns/ci/artifactable_spec.rb | 24 | ||||
-rw-r--r-- | spec/models/concerns/ci/has_deployment_name_spec.rb | 34 | ||||
-rw-r--r-- | spec/models/concerns/ci/track_environment_usage_spec.rb | 61 | ||||
-rw-r--r-- | spec/models/concerns/counter_attribute_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/concerns/from_set_operator_spec.rb | 51 | ||||
-rw-r--r-- | spec/models/concerns/pg_full_text_searchable_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/concerns/project_features_compatibility_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/concerns/reactive_caching_spec.rb | 6 |
9 files changed, 128 insertions, 62 deletions
diff --git a/spec/models/concerns/approvable_base_spec.rb b/spec/models/concerns/approvable_spec.rb index 2bf6a98a64d..1ddd9b3edca 100644 --- a/spec/models/concerns/approvable_base_spec.rb +++ b/spec/models/concerns/approvable_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ApprovableBase do +RSpec.describe Approvable do let(:merge_request) { create(:merge_request) } let(:user) { create(:user) } diff --git a/spec/models/concerns/ci/artifactable_spec.rb b/spec/models/concerns/ci/artifactable_spec.rb index 64691165e21..6af244a5a0f 100644 --- a/spec/models/concerns/ci/artifactable_spec.rb +++ b/spec/models/concerns/ci/artifactable_spec.rb @@ -46,30 +46,8 @@ RSpec.describe Ci::Artifactable do end end - context 'when file format is zip' do - context 'when artifact contains one file' do - let(:artifact) { build(:ci_job_artifact, :zip_with_single_file) } - - it 'iterates blob once' do - expect { |b| artifact.each_blob(&b) }.to yield_control.once - end - end - - context 'when artifact contains two files' do - let(:artifact) { build(:ci_job_artifact, :zip_with_multiple_files) } - - it 'iterates blob two times' do - expect { |b| artifact.each_blob(&b) }.to yield_control.exactly(2).times - end - end - end - context 'when there are no adapters for the file format' do - let(:artifact) { build(:ci_job_artifact, :junit) } - - before do - allow(artifact).to receive(:file_format).and_return(:unknown) - end + let(:artifact) { build(:ci_job_artifact, :junit, file_format: :zip) } it 'raises an error' do expect { |b| artifact.each_blob(&b) }.to raise_error(described_class::NotSupportedAdapterError) diff --git a/spec/models/concerns/ci/has_deployment_name_spec.rb b/spec/models/concerns/ci/has_deployment_name_spec.rb deleted file mode 100644 index 8c7338638b1..00000000000 --- a/spec/models/concerns/ci/has_deployment_name_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Ci::HasDeploymentName do - describe 'deployment_name?' do - let(:build) { create(:ci_build) } - - subject { build.branch? } - - it 'does detect deployment names' do - build.name = 'deployment' - - expect(build.deployment_name?).to be_truthy - end - - it 'does detect partial deployment names' do - build.name = 'do a really cool deploy' - - expect(build.deployment_name?).to be_truthy - end - - it 'does not detect non-deployment names' do - build.name = 'testing' - - expect(build.deployment_name?).to be_falsy - end - - it 'is case insensitive' do - build.name = 'DEPLOY' - expect(build.deployment_name?).to be_truthy - end - end -end diff --git a/spec/models/concerns/ci/track_environment_usage_spec.rb b/spec/models/concerns/ci/track_environment_usage_spec.rb new file mode 100644 index 00000000000..d75972c49b5 --- /dev/null +++ b/spec/models/concerns/ci/track_environment_usage_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::TrackEnvironmentUsage do + describe '#verifies_environment?' do + subject { build.verifies_environment? } + + context 'when build is the verify action for the environment' do + let(:build) do + build_stubbed(:ci_build, + ref: 'master', + environment: 'staging', + options: { environment: { action: 'verify' } }) + end + + it { is_expected.to be_truthy } + end + + context 'when build is not the verify action for the environment' do + let(:build) do + build_stubbed(:ci_build, + ref: 'master', + environment: 'staging', + options: { environment: { action: 'start' } }) + end + + it { is_expected.to be_falsey } + end + end + + describe 'deployment_name?' do + let(:build) { create(:ci_build) } + + subject { build.branch? } + + it 'does detect deployment names' do + build.name = 'deployment' + + expect(build).to be_deployment_name + end + + it 'does detect partial deployment names' do + build.name = 'do a really cool deploy' + + expect(build).to be_deployment_name + end + + it 'does not detect non-deployment names' do + build.name = 'testing' + + expect(build).not_to be_deployment_name + end + + it 'is case insensitive' do + build.name = 'DEPLOY' + + expect(build).to be_deployment_name + end + end +end diff --git a/spec/models/concerns/counter_attribute_spec.rb b/spec/models/concerns/counter_attribute_spec.rb index 8d32ef14f47..2dd70188740 100644 --- a/spec/models/concerns/counter_attribute_spec.rb +++ b/spec/models/concerns/counter_attribute_spec.rb @@ -79,4 +79,14 @@ RSpec.describe CounterAttribute, :counter_attribute, :clean_gitlab_redis_shared_ end end end + + describe '.counter_attribute_enabled?' do + it 'is true when counter attribute is defined' do + expect(CounterAttributeModel.counter_attribute_enabled?(:build_artifacts_size)).to be_truthy + end + + it 'is false when counter attribute is not defined' do + expect(CounterAttributeModel.counter_attribute_enabled?(:nope)).to be_falsey + end + end end diff --git a/spec/models/concerns/from_set_operator_spec.rb b/spec/models/concerns/from_set_operator_spec.rb index 8ebbb5550c9..1ef0d1adb08 100644 --- a/spec/models/concerns/from_set_operator_spec.rb +++ b/spec/models/concerns/from_set_operator_spec.rb @@ -3,7 +3,22 @@ require 'spec_helper' RSpec.describe FromSetOperator do - describe 'when set operator method already exists' do + let_it_be(:from_set_operator) do + Class.new do + extend FromSetOperator + define_set_operator Gitlab::SQL::Union + + def table_name + 'groups' + end + + def from(*args) + '' + end + end + end + + context 'when set operator method already exists' do let(:redefine_method) do Class.new do def self.from_union @@ -17,4 +32,38 @@ RSpec.describe FromSetOperator do it { expect { redefine_method }.to raise_exception(RuntimeError) } end + + context 'with members' do + let_it_be(:group1) { create :group } + let_it_be(:group2) { create :group } + let_it_be(:groups) do + [ + Group.where(id: group1), + Group.where(id: group2) + ] + end + + shared_examples 'set operator called with correct members' do + it do + expect(Gitlab::SQL::Union).to receive(:new).with(groups, anything).and_call_original + subject + end + end + + context 'as array' do + subject { from_set_operator.new.from_union(groups) } + + it_behaves_like 'set operator called with correct members' + + it { expect { subject }.not_to make_queries } + end + + context 'as multiple parameters' do + subject { from_set_operator.new.from_union(*groups) } + + it_behaves_like 'set operator called with correct members' + + it { expect { subject }.not_to make_queries } + end + end end diff --git a/spec/models/concerns/pg_full_text_searchable_spec.rb b/spec/models/concerns/pg_full_text_searchable_spec.rb index 55e3caf3c4c..3e42a3504ac 100644 --- a/spec/models/concerns/pg_full_text_searchable_spec.rb +++ b/spec/models/concerns/pg_full_text_searchable_spec.rb @@ -96,6 +96,7 @@ RSpec.describe PgFullTextSearchable do it 'ignores accents' do expect(model_class.pg_full_text_search('jurgen')).to contain_exactly(with_accent) + expect(model_class.pg_full_text_search('Jürgen')).to contain_exactly(with_accent) end it 'does not support searching by non-Latin characters' do diff --git a/spec/models/concerns/project_features_compatibility_spec.rb b/spec/models/concerns/project_features_compatibility_spec.rb index b49b9ce8a2a..89f34834aa4 100644 --- a/spec/models/concerns/project_features_compatibility_spec.rb +++ b/spec/models/concerns/project_features_compatibility_spec.rb @@ -8,6 +8,7 @@ RSpec.describe ProjectFeaturesCompatibility do let(:features) do features_enabled + %w( repository pages operations container_registry package_registry environments feature_flags releases + monitor ) end diff --git a/spec/models/concerns/reactive_caching_spec.rb b/spec/models/concerns/reactive_caching_spec.rb index cb9bb676ede..039b9e574fe 100644 --- a/spec/models/concerns/reactive_caching_spec.rb +++ b/spec/models/concerns/reactive_caching_spec.rb @@ -281,7 +281,7 @@ RSpec.describe ReactiveCaching, :use_clean_rails_memory_store_caching do end it 'does not delete the value key' do - expect(Rails.cache).to receive(:delete).with(cache_key).never + expect(Rails.cache).not_to receive(:delete).with(cache_key) go! end @@ -338,7 +338,7 @@ RSpec.describe ReactiveCaching, :use_clean_rails_memory_store_caching do context 'when lifetime is exceeded' do it 'skips the calculation' do - expect(instance).to receive(:calculate_reactive_cache).never + expect(instance).not_to receive(:calculate_reactive_cache) go! end @@ -354,7 +354,7 @@ RSpec.describe ReactiveCaching, :use_clean_rails_memory_store_caching do it 'skips the calculation' do stub_exclusive_lease_taken(cache_key) - expect(instance).to receive(:calculate_reactive_cache).never + expect(instance).not_to receive(:calculate_reactive_cache) go! end |