2019-01-03 21:17:44 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 09:08:32 +00:00
|
|
|
RSpec.describe ApplicationSettingsHelper do
|
2019-01-03 21:17:44 +00:00
|
|
|
context 'when all protocols in use' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(enabled_git_access_protocol: '')
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(all_protocols_enabled?).to be_truthy }
|
|
|
|
it { expect(http_enabled?).to be_truthy }
|
|
|
|
it { expect(ssh_enabled?).to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when SSH is only in use' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(enabled_git_access_protocol: 'ssh')
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(all_protocols_enabled?).to be_falsey }
|
|
|
|
it { expect(http_enabled?).to be_falsey }
|
|
|
|
it { expect(ssh_enabled?).to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'when HTTP protocol is in use' do |protocol|
|
|
|
|
before do
|
|
|
|
allow(Gitlab.config.gitlab).to receive(:protocol).and_return(protocol)
|
|
|
|
stub_application_setting(enabled_git_access_protocol: 'http')
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(all_protocols_enabled?).to be_falsey }
|
|
|
|
it { expect(http_enabled?).to be_truthy }
|
|
|
|
it { expect(ssh_enabled?).to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'when HTTP protocol is in use', 'https'
|
|
|
|
it_behaves_like 'when HTTP protocol is in use', 'http'
|
2019-10-22 21:06:42 +00:00
|
|
|
|
|
|
|
context 'with tracking parameters' do
|
2019-11-08 21:06:38 +00:00
|
|
|
it { expect(visible_attributes).to include(*%i(snowplow_collector_hostname snowplow_cookie_domain snowplow_enabled snowplow_app_id)) }
|
2019-11-04 06:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.integration_expanded?' do
|
|
|
|
let(:application_setting) { build(:application_setting) }
|
|
|
|
|
|
|
|
it 'is expanded' do
|
|
|
|
application_setting.plantuml_enabled = true
|
|
|
|
application_setting.valid?
|
|
|
|
helper.instance_variable_set(:@application_setting, application_setting)
|
|
|
|
|
|
|
|
expect(helper.integration_expanded?('plantuml_')).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not expanded' do
|
|
|
|
application_setting.valid?
|
|
|
|
helper.instance_variable_set(:@application_setting, application_setting)
|
|
|
|
|
|
|
|
expect(helper.integration_expanded?('plantuml_')).to be_falsey
|
|
|
|
end
|
2019-10-22 21:06:42 +00:00
|
|
|
end
|
2020-01-08 09:07:53 +00:00
|
|
|
|
|
|
|
describe '.self_monitoring_project_data' do
|
|
|
|
context 'when self monitoring project does not exist' do
|
|
|
|
it 'returns create_self_monitoring_project_path' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
|
|
|
'create_self_monitoring_project_path' =>
|
|
|
|
create_self_monitoring_project_admin_application_settings_path
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns status_create_self_monitoring_project_path' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
|
|
|
'status_create_self_monitoring_project_path' =>
|
|
|
|
status_create_self_monitoring_project_admin_application_settings_path
|
2020-01-13 15:07:53 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns delete_self_monitoring_project_path' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
|
|
|
'delete_self_monitoring_project_path' =>
|
|
|
|
delete_self_monitoring_project_admin_application_settings_path
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns status_delete_self_monitoring_project_path' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
|
|
|
'status_delete_self_monitoring_project_path' =>
|
|
|
|
status_delete_self_monitoring_project_admin_application_settings_path
|
2020-01-08 09:07:53 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns self_monitoring_project_exists false' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
2020-01-16 06:08:30 +00:00
|
|
|
'self_monitoring_project_exists' => "false"
|
2020-01-08 09:07:53 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for project full_path' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
|
|
|
'self_monitoring_project_full_path' => nil
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when self monitoring project exists' do
|
|
|
|
let(:project) { build(:project) }
|
|
|
|
|
|
|
|
before do
|
2020-01-28 15:08:36 +00:00
|
|
|
stub_application_setting(self_monitoring_project: project)
|
2020-01-08 09:07:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns self_monitoring_project_exists true' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
2020-01-16 06:08:30 +00:00
|
|
|
'self_monitoring_project_exists' => "true"
|
2020-01-08 09:07:53 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns project full_path' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
|
|
|
'self_monitoring_project_full_path' => project.full_path
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-16 12:09:00 +00:00
|
|
|
|
|
|
|
describe '.storage_weights' do
|
|
|
|
let(:application_setting) { build(:application_setting) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
helper.instance_variable_set(:@application_setting, application_setting)
|
|
|
|
stub_storage_settings({ 'default': {}, 'storage_1': {}, 'storage_2': {} })
|
|
|
|
allow(ApplicationSetting).to receive(:repository_storages_weighted_attributes).and_return(
|
|
|
|
[:repository_storages_weighted_default,
|
|
|
|
:repository_storages_weighted_storage_1,
|
|
|
|
:repository_storages_weighted_storage_2])
|
|
|
|
|
|
|
|
stub_application_setting(repository_storages_weighted: { 'default' => 100, 'storage_1' => 50, 'storage_2' => nil })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns storages correctly' do
|
|
|
|
expect(helper.storage_weights).to eq([
|
|
|
|
{ name: :repository_storages_weighted_default, label: 'default', value: 100 },
|
|
|
|
{ name: :repository_storages_weighted_storage_1, label: 'storage_1', value: 50 },
|
|
|
|
{ name: :repository_storages_weighted_storage_2, label: 'storage_2', value: 0 }
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
2019-01-03 21:17:44 +00:00
|
|
|
end
|