diff options
Diffstat (limited to 'spec/support/shared_examples/models/concerns')
2 files changed, 63 insertions, 3 deletions
diff --git a/spec/support/shared_examples/models/concerns/counter_attribute_shared_examples.rb b/spec/support/shared_examples/models/concerns/counter_attribute_shared_examples.rb index f92ed3d7396..f4d5ab3d5c6 100644 --- a/spec/support/shared_examples/models/concerns/counter_attribute_shared_examples.rb +++ b/spec/support/shared_examples/models/concerns/counter_attribute_shared_examples.rb @@ -2,6 +2,10 @@ require 'spec_helper' RSpec.shared_examples_for CounterAttribute do |counter_attributes| + before do + Gitlab::ApplicationContext.push(feature_category: 'test', caller_id: 'caller') + end + it 'defines a Redis counter_key' do expect(model.counter_key(:counter_name)) .to eq("project:{#{model.project_id}}:counters:CounterAttributeModel:#{model.id}:counter_name") @@ -22,7 +26,21 @@ RSpec.shared_examples_for CounterAttribute do |counter_attributes| where(:increment) { [10, -3] } with_them do - it 'increments the counter in Redis' do + it 'increments the counter in Redis and logs it' do + expect(Gitlab::AppLogger).to receive(:info).with( + hash_including( + message: 'Increment counter attribute', + attribute: attribute, + project_id: model.project_id, + increment: increment, + new_counter_value: 0 + increment, + current_db_value: model.read_attribute(attribute), + 'correlation_id' => an_instance_of(String), + 'meta.feature_category' => 'test', + 'meta.caller_id' => 'caller' + ) + ) + subject Gitlab::Redis::SharedState.with do |redis| @@ -86,7 +104,21 @@ RSpec.shared_examples_for CounterAttribute do |counter_attributes| model.delayed_increment_counter(incremented_attribute, -3) end - it 'updates the record' do + it 'updates the record and logs it' do + expect(Gitlab::AppLogger).to receive(:info).with( + hash_including( + message: 'Flush counter attribute to database', + attribute: incremented_attribute, + project_id: model.project_id, + increment: 7, + previous_db_value: 0, + new_db_value: 7, + 'correlation_id' => an_instance_of(String), + 'meta.feature_category' => 'test', + 'meta.caller_id' => 'caller' + ) + ) + expect { subject }.to change { model.reset.read_attribute(incremented_attribute) }.by(7) end @@ -153,4 +185,32 @@ RSpec.shared_examples_for CounterAttribute do |counter_attributes| end end end + + describe '#clear_counter!' do + let(:attribute) { counter_attributes.first } + + before do + model.increment_counter(attribute, 10) + end + + it 'deletes the counter key for the given attribute and logs it' do + expect(Gitlab::AppLogger).to receive(:info).with( + hash_including( + message: 'Clear counter attribute', + attribute: attribute, + project_id: model.project_id, + 'correlation_id' => an_instance_of(String), + 'meta.feature_category' => 'test', + 'meta.caller_id' => 'caller' + ) + ) + + model.clear_counter!(attribute) + + Gitlab::Redis::SharedState.with do |redis| + key_exists = redis.exists(model.counter_key(attribute)) + expect(key_exists).to be_falsey + end + end + end end diff --git a/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb b/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb index d80be5be3b3..7512a9f2855 100644 --- a/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb +++ b/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb @@ -13,7 +13,6 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |integration_name describe "Associations" do it { is_expected.to belong_to :project } - it { is_expected.to have_one :service_hook } end describe 'Validations' do @@ -23,6 +22,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |integration_name end it { is_expected.to validate_presence_of(:webhook) } + it_behaves_like 'issue tracker integration URL attribute', :webhook end |