From 60a2d3f16ee80c50e2819a9122c703a42f6a8d45 Mon Sep 17 00:00:00 2001 From: John Cai Date: Mon, 1 Jul 2019 13:49:10 -0700 Subject: [PATCH] Use guard in fetch_legacy_config --- .../jc-fix-gitlab-config-legacy-config.yml | 5 +++++ ruby/gitlab-shell/lib/gitlab_config.rb | 2 +- ruby/gitlab-shell/spec/gitlab_config_spec.rb | 21 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/jc-fix-gitlab-config-legacy-config.yml diff --git a/changelogs/unreleased/jc-fix-gitlab-config-legacy-config.yml b/changelogs/unreleased/jc-fix-gitlab-config-legacy-config.yml new file mode 100644 index 0000000000..e255014086 --- /dev/null +++ b/changelogs/unreleased/jc-fix-gitlab-config-legacy-config.yml @@ -0,0 +1,5 @@ +--- +title: Use guard in fetch_legacy_config +merge_request: 1345 +author: +type: fixed diff --git a/ruby/gitlab-shell/lib/gitlab_config.rb b/ruby/gitlab-shell/lib/gitlab_config.rb index 086ef2fad0..19f03c346d 100644 --- a/ruby/gitlab-shell/lib/gitlab_config.rb +++ b/ruby/gitlab-shell/lib/gitlab_config.rb @@ -56,7 +56,7 @@ class GitlabConfig end def fetch_from_legacy_config(key, default) - legacy_config.fetch(key, default) + legacy_config[key] || default end private diff --git a/ruby/gitlab-shell/spec/gitlab_config_spec.rb b/ruby/gitlab-shell/spec/gitlab_config_spec.rb index af6f1358f5..6de0cd08e2 100644 --- a/ruby/gitlab-shell/spec/gitlab_config_spec.rb +++ b/ruby/gitlab-shell/spec/gitlab_config_spec.rb @@ -31,4 +31,25 @@ describe GitlabConfig do is_expected.to eq('text') end end + + describe '#fetch_from_legacy_config' do + let(:key) { 'yaml_key' } + + where(:yaml_value, :default, :expected_value) do + [ + ['a', 'b', 'a'], + [nil, 'b', 'b'], + ['a', nil, 'a'], + [nil, {}, {}] + ] + end + + with_them do + it 'returns the correct value' do + config_data[key] = yaml_value + + expect(config.fetch_from_legacy_config(key, default)).to eq(expected_value) + end + end + end end -- GitLab