diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-06 12:09:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-06 12:09:33 +0300 |
commit | 95de7177f2d5844e4aa399fea9a59d4ba6b4b1f1 (patch) | |
tree | b368e310fa60abd9841d2f25b116faedc6af90d2 /spec | |
parent | c77b780ee080b978bd5a63f642f741e8892383dc (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/audit/auditor_spec.rb | 33 | ||||
-rw-r--r-- | spec/lib/gitlab/counters/buffered_counter_spec.rb | 75 | ||||
-rw-r--r-- | spec/models/project_statistics_spec.rb | 16 | ||||
-rw-r--r-- | spec/rubocop/cop/migration/schema_addition_methods_no_post_spec.rb | 8 |
4 files changed, 41 insertions, 91 deletions
diff --git a/spec/lib/gitlab/audit/auditor_spec.rb b/spec/lib/gitlab/audit/auditor_spec.rb index 2b3c8506440..386d4157e90 100644 --- a/spec/lib/gitlab/audit/auditor_spec.rb +++ b/spec/lib/gitlab/audit/auditor_spec.rb @@ -18,12 +18,45 @@ RSpec.describe Gitlab::Audit::Auditor, feature_category: :audit_events do end let(:logger) { instance_spy(Gitlab::AuditJsonLogger) } + let(:app_logger) { instance_spy(Gitlab::AppLogger) } subject(:auditor) { described_class } describe '.audit' do let(:audit!) { auditor.audit(context) } + context 'when yaml definition is not defined' do + before do + allow(Gitlab::Audit::Type::Definition).to receive(:defined?).and_return(false) + allow(Gitlab::AppLogger).to receive(:warn).and_return(app_logger) + end + + it 'logs a warning when YAML is not defined' do + expected_warning = { + message: 'Logging audit events without an event type definition will be deprecated soon ' \ + '(https://docs.gitlab.com/ee/development/audit_event_guide/#event-type-definitions)', + event_type: name + } + + audit! + + expect(Gitlab::AppLogger).to have_received(:warn).with(expected_warning) + end + end + + context 'when yaml definition is defined' do + before do + allow(Gitlab::Audit::Type::Definition).to receive(:defined?).and_return(true) + allow(Gitlab::AppLogger).to receive(:warn).and_return(app_logger) + end + + it 'does not log a warning when YAML is defined' do + audit! + + expect(Gitlab::AppLogger).not_to have_received(:warn) + end + end + context 'when authentication event' do it 'creates an authentication event' do expect(AuthenticationEvent).to receive(:new).with( diff --git a/spec/lib/gitlab/counters/buffered_counter_spec.rb b/spec/lib/gitlab/counters/buffered_counter_spec.rb index 2d5209161d9..4fd152eb805 100644 --- a/spec/lib/gitlab/counters/buffered_counter_spec.rb +++ b/spec/lib/gitlab/counters/buffered_counter_spec.rb @@ -244,43 +244,6 @@ RSpec.describe Gitlab::Counters::BufferedCounter, :clean_gitlab_redis_shared_sta end end end - - context 'when feature flag is disabled' do - before do - stub_feature_flags(project_statistics_bulk_increment: false) - end - - context 'when the counter is not undergoing refresh' do - it 'sets a new key by the given value' do - counter.increment(increment) - - expect(counter.get).to eq(increment.amount) - end - - it 'increments an existing key by the given value' do - counter.increment(other_increment) - counter.increment(increment) - - expect(counter.get).to eq(other_increment.amount + increment.amount) - end - end - - context 'when the counter is undergoing refresh' do - before do - counter.initiate_refresh! - end - - context 'when it is a decrement (negative amount)' do - let(:decrement) { Gitlab::Counters::Increment.new(amount: -123, ref: 3) } - - it 'immediately decrements the counter key to negative' do - counter.increment(decrement) - - expect(counter.get).to eq(decrement.amount) - end - end - end - end end describe '#bulk_increment' do @@ -416,44 +379,6 @@ RSpec.describe Gitlab::Counters::BufferedCounter, :clean_gitlab_redis_shared_sta end end end - - context 'when feature flag is disabled' do - before do - stub_feature_flags(project_statistics_bulk_increment: false) - end - - context 'when the counter is not undergoing refresh' do - it 'sets a new key by the given value' do - counter.bulk_increment(increments) - - expect(counter.get).to eq(increments.sum(&:amount)) - end - - it 'increments an existing key by the given value' do - counter.increment(other_increment) - - result = counter.bulk_increment(increments) - - expect(result).to eq(other_increment.amount + increments.sum(&:amount)) - end - end - - context 'when the counter is undergoing refresh' do - before do - counter.initiate_refresh! - end - - context 'when it is a decrement (negative amount)' do - let(:decrement) { Gitlab::Counters::Increment.new(amount: -123, ref: 3) } - - it 'immediately decrements the counter key to negative' do - counter.bulk_increment([decrement]) - - expect(counter.get).to eq(decrement.amount) - end - end - end - end end describe '#initiate_refresh!' do diff --git a/spec/models/project_statistics_spec.rb b/spec/models/project_statistics_spec.rb index ef53de6ad82..a24903f8b4e 100644 --- a/spec/models/project_statistics_spec.rb +++ b/spec/models/project_statistics_spec.rb @@ -635,22 +635,6 @@ RSpec.describe ProjectStatistics do let(:stat) { :build_artifacts_size } it_behaves_like 'a statistic that increases storage_size asynchronously' - - context 'when :project_statistics_bulk_increment flag is disabled' do - before do - stub_feature_flags(project_statistics_bulk_increment: false) - end - - it 'calls increment_statistic on once with the sum of the increments' do - total_amount = increments.sum(&:amount) - expect(statistics) - .to receive(:increment_statistic).with(stat, have_attributes(amount: total_amount)).and_call_original - - described_class.bulk_increment_statistic(project, stat, increments) - end - - it_behaves_like 'a statistic that increases storage_size asynchronously' - end end context 'when adjusting :pipeline_artifacts_size' do diff --git a/spec/rubocop/cop/migration/schema_addition_methods_no_post_spec.rb b/spec/rubocop/cop/migration/schema_addition_methods_no_post_spec.rb index 94c0638cf1b..92e714d7a02 100644 --- a/spec/rubocop/cop/migration/schema_addition_methods_no_post_spec.rb +++ b/spec/rubocop/cop/migration/schema_addition_methods_no_post_spec.rb @@ -42,5 +42,13 @@ RSpec.describe RuboCop::Cop::Migration::SchemaAdditionMethodsNoPost, feature_cat end CODE end + + it "allows forbidden method to be called within nested statement" do + expect_no_offenses(<<~CODE) + def down + add_column(:table, :column, :boolean) unless column_exists?(:table, :column) + end + CODE + end end end |