diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /spec/support/gitlab/usage/metrics_instrumentation_shared_examples.rb | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/support/gitlab/usage/metrics_instrumentation_shared_examples.rb')
-rw-r--r-- | spec/support/gitlab/usage/metrics_instrumentation_shared_examples.rb | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/spec/support/gitlab/usage/metrics_instrumentation_shared_examples.rb b/spec/support/gitlab/usage/metrics_instrumentation_shared_examples.rb index c9ff566e94c..de9735df546 100644 --- a/spec/support/gitlab/usage/metrics_instrumentation_shared_examples.rb +++ b/spec/support/gitlab/usage/metrics_instrumentation_shared_examples.rb @@ -1,13 +1,38 @@ # frozen_string_literal: true -RSpec.shared_examples 'a correct instrumented metric value' do |options, expected_value| - let(:time_frame) { options[:time_frame] } +RSpec.shared_examples 'a correct instrumented metric value' do |params| + let(:time_frame) { params[:time_frame] } + let(:options) { params[:options] } + let(:metric) { described_class.new(time_frame: time_frame, options: options) } before do allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false) end it 'has correct value' do - expect(described_class.new(time_frame: time_frame).value).to eq(expected_value) + expect(metric.value).to eq(expected_value) end end + +RSpec.shared_examples 'a correct instrumented metric query' do |params| + let(:time_frame) { params[:time_frame] } + let(:options) { params[:options] } + let(:metric) { described_class.new(time_frame: time_frame, options: options) } + + around do |example| + freeze_time { example.run } + end + + before do + allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false) + end + + it 'has correct generate query' do + expect(metric.to_sql).to eq(expected_query) + end +end + +RSpec.shared_examples 'a correct instrumented metric value and query' do |params| + it_behaves_like 'a correct instrumented metric value', params + it_behaves_like 'a correct instrumented metric query', params +end |