Gitlab::Utils - backport `.ensure_array_from_string` from EE
This commit is contained in:
parent
135ef03102
commit
f9d61717cf
|
@ -67,5 +67,13 @@ module Gitlab
|
||||||
|
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Used in EE
|
||||||
|
# Accepts either an Array or a String and returns an array
|
||||||
|
def ensure_array_from_string(string_or_array)
|
||||||
|
return string_or_array if string_or_array.is_a?(Array)
|
||||||
|
|
||||||
|
string_or_array.split(',').map(&:strip)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Gitlab::Utils do
|
describe Gitlab::Utils do
|
||||||
delegate :to_boolean, :boolean_to_yes_no, :slugify, :random_string, :which, to: :described_class
|
delegate :to_boolean, :boolean_to_yes_no, :slugify, :random_string, :which, :ensure_array_from_string, to: :described_class
|
||||||
|
|
||||||
describe '.slugify' do
|
describe '.slugify' do
|
||||||
{
|
{
|
||||||
|
@ -83,4 +83,18 @@ describe Gitlab::Utils do
|
||||||
expect(which('sh', 'PATH' => '/bin')).to eq('/bin/sh')
|
expect(which('sh', 'PATH' => '/bin')).to eq('/bin/sh')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.ensure_array_from_string' do
|
||||||
|
it 'returns the same array if given one' do
|
||||||
|
arr = ['a', 4, true, { test: 1 }]
|
||||||
|
|
||||||
|
expect(ensure_array_from_string(arr)).to eq(arr)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'turns comma-separated strings into arrays' do
|
||||||
|
str = 'seven, eight, 9, 10'
|
||||||
|
|
||||||
|
expect(ensure_array_from_string(str)).to eq(%w[seven eight 9 10])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue