Commit a63ad4e4 authored by Manoj M J's avatar Manoj M J

Fix translation of visibility levels

Fix translation of visibility levels
parent dc6f5e98
......@@ -35,9 +35,7 @@ module VisibilityLevelHelper
end
def visibility_level_label(level)
# The visibility level can be:
# 'VisibilityLevel|Private', 'VisibilityLevel|Internal', 'VisibilityLevel|Public'
s_(Project.visibility_levels.key(level))
Project.visibility_levels.key(level)
end
def restricted_visibility_levels(show_all = false)
......
......@@ -44,9 +44,9 @@ module Gitlab
def options
{
N_('VisibilityLevel|Private') => PRIVATE,
N_('VisibilityLevel|Internal') => INTERNAL,
N_('VisibilityLevel|Public') => PUBLIC
s_('VisibilityLevel|Private') => PRIVATE,
s_('VisibilityLevel|Internal') => INTERNAL,
s_('VisibilityLevel|Public') => PUBLIC
}
end
......@@ -104,12 +104,7 @@ module Gitlab
end
def level_name(level)
level_name = N_('VisibilityLevel|Unknown')
options.each do |name, lvl|
level_name = name if lvl == level.to_i
end
s_(level_name)
options.key(level.to_i) || s_('VisibilityLevel|Unknown')
end
def level_value(level)
......
......@@ -86,7 +86,7 @@ RSpec.describe 'New project', :js do
visit new_project_path
find('[data-qa-selector="blank_project_link"]').click
choose(s_(key))
choose(key)
click_button('Create project')
page.within('#blank-project-pane') do
expect(find_field("project_visibility_level_#{level}")).to be_checked
......
......@@ -33,6 +33,22 @@ RSpec.describe VisibilityLevelHelper do
end
end
describe 'visibility_level_label' do
using RSpec::Parameterized::TableSyntax
where(:level_value, :level_name) do
Gitlab::VisibilityLevel::PRIVATE | 'Private'
Gitlab::VisibilityLevel::INTERNAL | 'Internal'
Gitlab::VisibilityLevel::PUBLIC | 'Public'
end
with_them do
it 'returns the name of the visibility level' do
expect(visibility_level_label(level_value)).to eq(level_name)
end
end
end
describe 'visibility_level_description' do
context 'used with a Project' do
let(:descriptions) do
......
......@@ -131,4 +131,29 @@ RSpec.describe Gitlab::VisibilityLevel do
end
end
end
describe '.options' do
context 'keys' do
it 'returns the allowed visibility levels' do
expect(described_class.options.keys).to contain_exactly('Private', 'Internal', 'Public')
end
end
end
describe '.level_name' do
using RSpec::Parameterized::TableSyntax
where(:level_value, :level_name) do
described_class::PRIVATE | 'Private'
described_class::INTERNAL | 'Internal'
described_class::PUBLIC | 'Public'
non_existing_record_access_level | 'Unknown'
end
with_them do
it 'returns the name of the visibility level' do
expect(described_class.level_name(level_value)).to eq(level_name)
end
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