From 6a67148ed3543ee5073ab49dc4e825f3d87cc8b5 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Fri, 2 Jun 2017 15:25:54 +0200 Subject: [PATCH] Make production settings fixture use Gitlab::CurrentSettings.current_application_settings small code formatting changes --- db/fixtures/production/010_settings.rb | 25 ++++++++----------- spec/db/production/settings_spec.rb | 4 +-- .../prometheus_text_format_spec.rb | 14 ++++------- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/db/fixtures/production/010_settings.rb b/db/fixtures/production/010_settings.rb index ed0718e7fa9..a81782d16ff 100644 --- a/db/fixtures/production/010_settings.rb +++ b/db/fixtures/production/010_settings.rb @@ -12,18 +12,15 @@ def save(settings, topic) end end -envs = %w{ GITLAB_PROMETHEUS_METRICS_ENABLED GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN } - -if envs.any? {|env_name| ENV[env_name].present? } - settings = ApplicationSetting.current || ApplicationSetting.create_from_defaults - if ENV['GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN'].present? - settings.set_runners_registration_token(ENV['GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN']) - save(settings, 'Runner Registration Token') - end - - if ENV['GITLAB_PROMETHEUS_METRICS_ENABLED'].present? - value = Gitlab::Utils.to_boolean(ENV['GITLAB_PROMETHEUS_METRICS_ENABLED']) - settings.prometheus_metrics_enabled = value - save(settings, 'Prometheus metrics enabled flag') - end +if ENV['GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN'].present? + settings = Gitlab::CurrentSettings.current_application_settings + settings.set_runners_registration_token(ENV['GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN']) + save(settings, 'Runner Registration Token') +end + +if ENV['GITLAB_PROMETHEUS_METRICS_ENABLED'].present? + settings = Gitlab::CurrentSettings.current_application_settings + value = Gitlab::Utils.to_boolean(ENV['GITLAB_PROMETHEUS_METRICS_ENABLED']) + settings.prometheus_metrics_enabled = value + save(settings, 'Prometheus metrics enabled flag') end diff --git a/spec/db/production/settings_spec.rb b/spec/db/production/settings_spec.rb index c6b772f4e93..00c631b866e 100644 --- a/spec/db/production/settings_spec.rb +++ b/spec/db/production/settings_spec.rb @@ -3,8 +3,8 @@ require 'rainbow/ext/string' describe 'seed production settings', lib: true do include StubENV - let(:settings_file) { File.join(__dir__, '../../../db/fixtures/production/010_settings.rb') } - let(:settings) { ApplicationSetting.current || ApplicationSetting.create_from_defaults } + let(:settings_file) { Rails.root.join('db/fixtures/production/010_settings.rb') } + let(:settings) { Gitlab::CurrentSettings.current_application_settings } context 'GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN is set in the environment' do before do diff --git a/spec/lib/gitlab/health_checks/prometheus_text_format_spec.rb b/spec/lib/gitlab/health_checks/prometheus_text_format_spec.rb index b07f95443ee..7573792789a 100644 --- a/spec/lib/gitlab/health_checks/prometheus_text_format_spec.rb +++ b/spec/lib/gitlab/health_checks/prometheus_text_format_spec.rb @@ -4,10 +4,8 @@ describe Gitlab::HealthChecks::PrometheusTextFormat do describe '#marshal' do let(:sample_metrics) do - [ - metric_class.new('metric1', 1), - metric_class.new('metric2', 2) - ] + [metric_class.new('metric1', 1), + metric_class.new('metric2', 2)] end it 'marshal to text with non repeating type definition' do @@ -23,11 +21,9 @@ describe Gitlab::HealthChecks::PrometheusTextFormat do context 'metrics where name repeats' do let(:sample_metrics) do - [ - metric_class.new('metric1', 1), - metric_class.new('metric1', 2), - metric_class.new('metric2', 3) - ] + [metric_class.new('metric1', 1), + metric_class.new('metric1', 2), + metric_class.new('metric2', 3)] end it 'marshal to text with non repeating type definition' do