diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 23:02:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 23:02:30 +0300 |
commit | 41fe97390ceddf945f3d967b8fdb3de4c66b7dea (patch) | |
tree | 9c8d89a8624828992f06d892cd2f43818ff5dcc8 /spec/support/shared_examples/lib/gitlab | |
parent | 0804d2dc31052fb45a1efecedc8e06ce9bc32862 (diff) |
Add latest changes from gitlab-org/gitlab@14-9-stable-eev14.9.0-rc42
Diffstat (limited to 'spec/support/shared_examples/lib/gitlab')
2 files changed, 42 insertions, 2 deletions
diff --git a/spec/support/shared_examples/lib/gitlab/database/background_migration_job_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/database/background_migration_job_shared_examples.rb index 213f084be17..771ab89972c 100644 --- a/spec/support/shared_examples/lib/gitlab/database/background_migration_job_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/database/background_migration_job_shared_examples.rb @@ -2,7 +2,7 @@ RSpec.shared_examples 'marks background migration job records' do it 'marks each job record as succeeded after processing' do - create(:background_migration_job, class_name: "::#{described_class.name}", + create(:background_migration_job, class_name: "::#{described_class.name.demodulize}", arguments: arguments) expect(::Gitlab::Database::BackgroundMigrationJob).to receive(:mark_all_as_succeeded).and_call_original @@ -13,7 +13,7 @@ RSpec.shared_examples 'marks background migration job records' do end it 'returns the number of job records marked as succeeded' do - create(:background_migration_job, class_name: "::#{described_class.name}", + create(:background_migration_job, class_name: "::#{described_class.name.demodulize}", arguments: arguments) jobs_updated = subject.perform(*arguments) diff --git a/spec/support/shared_examples/lib/gitlab/usage_data_counters/usage_counter_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/usage_data_counters/usage_counter_shared_examples.rb new file mode 100644 index 00000000000..848437577d7 --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/usage_data_counters/usage_counter_shared_examples.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'a usage counter' do + describe '.increment' do + let(:project_id) { 12 } + + it 'intializes and increments the counter for the project by 1' do + expect do + described_class.increment(project_id) + end.to change { described_class.usage_totals[project_id] }.from(nil).to(1) + end + end + + describe '.usage_totals' do + let(:usage_totals) { described_class.usage_totals } + + context 'when the feature has not been used' do + it 'returns the total counts and counts per project' do + expect(usage_totals.keys).to eq([:total]) + expect(usage_totals[:total]).to eq(0) + end + end + + context 'when the feature has been used in multiple projects' do + let(:project1_id) { 12 } + let(:project2_id) { 16 } + + before do + described_class.increment(project1_id) + described_class.increment(project2_id) + end + + it 'returns the total counts and counts per project' do + expect(usage_totals[project1_id]).to eq(1) + expect(usage_totals[project2_id]).to eq(1) + expect(usage_totals[:total]).to eq(2) + end + end + end +end |