diff options
Diffstat (limited to 'spec/lib/gitlab/tracking_spec.rb')
-rw-r--r-- | spec/lib/gitlab/tracking_spec.rb | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/spec/lib/gitlab/tracking_spec.rb b/spec/lib/gitlab/tracking_spec.rb index f3e27c72143..46213532071 100644 --- a/spec/lib/gitlab/tracking_spec.rb +++ b/spec/lib/gitlab/tracking_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' RSpec.describe Gitlab::Tracking, feature_category: :application_instrumentation do include StubENV + using RSpec::Parameterized::TableSyntax before do stub_application_setting(snowplow_enabled: true) @@ -17,6 +18,8 @@ RSpec.describe Gitlab::Tracking, feature_category: :application_instrumentation described_class.instance_variable_set(:@tracker, nil) end + it { is_expected.to delegate_method(:flush).to(:tracker) } + describe '.options' do shared_examples 'delegates to destination' do |klass| before do @@ -295,29 +298,57 @@ RSpec.describe Gitlab::Tracking, feature_category: :application_instrumentation end describe 'snowplow_micro_enabled?' do - before do - allow(Rails.env).to receive(:development?).and_return(true) + where(:development?, :micro_verification_enabled?, :snowplow_micro_enabled, :result) do + true | true | true | true + true | true | false | false + false | true | true | true + false | true | false | false + false | false | true | false + false | false | false | false + true | false | true | true + true | false | false | false end - it 'returns true when snowplow_micro is enabled' do - stub_config(snowplow_micro: { enabled: true }) - - expect(described_class).to be_snowplow_micro_enabled - end + with_them do + before do + allow(Rails.env).to receive(:development?).and_return(development?) + allow(described_class).to receive(:micro_verification_enabled?).and_return(micro_verification_enabled?) + stub_config(snowplow_micro: { enabled: snowplow_micro_enabled }) + end - it 'returns false when snowplow_micro is disabled' do - stub_config(snowplow_micro: { enabled: false }) + subject { described_class.snowplow_micro_enabled? } - expect(described_class).not_to be_snowplow_micro_enabled + it { is_expected.to be(result) } end it 'returns false when snowplow_micro is not configured' do + allow(Rails.env).to receive(:development?).and_return(true) allow(Gitlab.config).to receive(:snowplow_micro).and_raise(GitlabSettings::MissingSetting) expect(described_class).not_to be_snowplow_micro_enabled end end + describe '.micro_verification_enabled?' do + where(:verify_tracking, :result) do + nil | false + 'true' | true + 'false' | false + '0' | false + '1' | true + end + + with_them do + before do + stub_env('VERIFY_TRACKING', verify_tracking) + end + + subject { described_class.micro_verification_enabled? } + + it { is_expected.to be(result) } + end + end + describe 'tracker' do it 'returns a SnowPlowMicro instance in development' do allow(Rails.env).to receive(:development?).and_return(true) |