Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Cai <jcai@gitlab.com>2019-07-01 23:49:10 +0300
committerJohn Cai <jcai@gitlab.com>2019-07-02 18:47:58 +0300
commit60a2d3f16ee80c50e2819a9122c703a42f6a8d45 (patch)
tree4aec46da7096467d8e960b9e3f7ddaa3fe6920c7
parent8817418fbac65e4945bba32de83f5896530b6408 (diff)
Use guard in fetch_legacy_config
-rw-r--r--changelogs/unreleased/jc-fix-gitlab-config-legacy-config.yml5
-rw-r--r--ruby/gitlab-shell/lib/gitlab_config.rb2
-rw-r--r--ruby/gitlab-shell/spec/gitlab_config_spec.rb21
3 files changed, 27 insertions, 1 deletions
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 000000000..e25501408
--- /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 086ef2fad..19f03c346 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 af6f1358f..6de0cd08e 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