debian-mirror-gitlab/spec/lib/product_analytics/settings_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
2.7 KiB
Ruby
Raw Normal View History

2023-06-20 00:43:36 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProductAnalytics::Settings, feature_category: :product_analytics do
2023-07-09 08:55:56 +05:30
let_it_be(:project) { create(:project) }
subject { described_class.for_project(project) }
2023-06-20 00:43:36 +05:30
describe 'config settings' do
context 'when configured' do
before do
mock_settings('test')
end
it 'will be configured' do
2023-07-09 08:55:56 +05:30
expect(subject.configured?).to be_truthy
2023-06-20 00:43:36 +05:30
end
end
context 'when not configured' do
before do
mock_settings('')
end
it 'will not be configured' do
2023-07-09 08:55:56 +05:30
expect(subject.configured?).to be_falsey
2023-06-20 00:43:36 +05:30
end
end
context 'when one configuration setting is missing' do
before do
missing_key = ProductAnalytics::Settings::CONFIG_KEYS.last
mock_settings('test', ProductAnalytics::Settings::CONFIG_KEYS - [missing_key])
allow(::Gitlab::CurrentSettings).to receive(missing_key).and_return('')
end
it 'will not be configured' do
2023-07-09 08:55:56 +05:30
expect(subject.configured?).to be_falsey
2023-06-20 00:43:36 +05:30
end
end
ProductAnalytics::Settings::CONFIG_KEYS.each do |key|
it "can read #{key}" do
expect(::Gitlab::CurrentSettings).to receive(key).and_return('test')
2023-07-09 08:55:56 +05:30
expect(subject.send(key)).to eq('test')
end
context 'with project' do
it "will override when provided a project #{key}" do
expect(::Gitlab::CurrentSettings).not_to receive(key)
expect(project.project_setting).to receive(key).and_return('test')
expect(subject.send(key)).to eq('test')
end
it "will will not override when provided a blank project #{key}" do
expect(::Gitlab::CurrentSettings).to receive(key).and_return('test')
expect(project.project_setting).to receive(key).and_return('')
expect(subject.send(key)).to eq('test')
end
2023-06-20 00:43:36 +05:30
end
end
end
describe '.enabled?' do
before do
2023-07-09 08:55:56 +05:30
allow(subject).to receive(:configured?).and_return(true)
2023-06-20 00:43:36 +05:30
end
context 'when enabled' do
before do
allow(::Gitlab::CurrentSettings).to receive(:product_analytics_enabled?).and_return(true)
end
it 'will be enabled' do
2023-07-09 08:55:56 +05:30
expect(subject.enabled?).to be_truthy
2023-06-20 00:43:36 +05:30
end
end
context 'when disabled' do
before do
allow(::Gitlab::CurrentSettings).to receive(:product_analytics_enabled?).and_return(false)
end
it 'will be enabled' do
2023-07-09 08:55:56 +05:30
expect(subject.enabled?).to be_falsey
2023-06-20 00:43:36 +05:30
end
end
end
private
def mock_settings(setting, keys = ProductAnalytics::Settings::CONFIG_KEYS)
keys.each do |key|
allow(::Gitlab::CurrentSettings).to receive(key).and_return(setting)
end
end
end