Commit 71306f14 authored by Toon Claes's avatar Toon Claes

Make level_value accept string integers

When a VisibilityLevel is an integer formatted as a string, convert it
to an integer, instead of looking it up in the hash map.

When the value is not recognized, default to PRIVATE.
parent dd3d62b6
......@@ -96,8 +96,8 @@ module Gitlab
end
def level_value(level)
return string_options[level] if level.is_a? String
level
return level.to_i if level.to_i.to_s == level.to_s && string_options.key(level.to_i)
string_options[level] || PRIVATE
end
def string_level(level)
......
require 'spec_helper'
describe Gitlab::VisibilityLevel, lib: true do
describe '.level_value' do
it 'converts "public" to integer value' do
expect(described_class.level_value('public')).to eq(Gitlab::VisibilityLevel::PUBLIC)
end
it 'converts string integer to integer value' do
expect(described_class.level_value('20')).to eq(20)
end
it 'defaults to PRIVATE when string value is not valid' do
expect(described_class.level_value('invalid')).to eq(Gitlab::VisibilityLevel::PRIVATE)
end
it 'defaults to PRIVATE when integer value is not valid' do
expect(described_class.level_value(100)).to eq(Gitlab::VisibilityLevel::PRIVATE)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment