Fix spec failures with app/helpers/namespaces_helper.rb
This commit is contained in:
parent
883d1dabbf
commit
ab12b379f0
1 changed files with 14 additions and 6 deletions
|
@ -16,18 +16,15 @@ module NamespacesHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
if extra_group && extra_group.is_a?(Group)
|
if extra_group && extra_group.is_a?(Group)
|
||||||
# Many importers create a temporary Group, so use the real
|
extra_group = dedup_extra_group(extra_group)
|
||||||
# group if one exists by that name to prevent duplicates.
|
|
||||||
unless extra_group.persisted?
|
|
||||||
existing_group = Group.find_by(name: extra_group.name)
|
|
||||||
extra_group = existing_group if existing_group&.persisted?
|
|
||||||
end
|
|
||||||
|
|
||||||
if Ability.allowed?(current_user, :read_group, extra_group)
|
if Ability.allowed?(current_user, :read_group, extra_group)
|
||||||
# Assign the value to an invalid primary ID so that the select box works
|
# Assign the value to an invalid primary ID so that the select box works
|
||||||
extra_group.id = -1 unless extra_group.persisted?
|
extra_group.id = -1 unless extra_group.persisted?
|
||||||
selected_id = extra_group.id if selected == :extra_group
|
selected_id = extra_group.id if selected == :extra_group
|
||||||
groups |= [extra_group]
|
groups |= [extra_group]
|
||||||
|
else
|
||||||
|
selected_id = current_user.namespace.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,6 +52,17 @@ module NamespacesHelper
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# Many importers create a temporary Group, so use the real
|
||||||
|
# group if one exists by that name to prevent duplicates.
|
||||||
|
def dedup_extra_group(extra_group)
|
||||||
|
unless extra_group.persisted?
|
||||||
|
existing_group = Group.find_by(name: extra_group.name)
|
||||||
|
extra_group = existing_group if existing_group&.persisted?
|
||||||
|
end
|
||||||
|
|
||||||
|
extra_group
|
||||||
|
end
|
||||||
|
|
||||||
def options_for_group(namespaces, display_path:, type:)
|
def options_for_group(namespaces, display_path:, type:)
|
||||||
group_label = type.pluralize
|
group_label = type.pluralize
|
||||||
elements = namespaces.sort_by(&:human_name).map! do |n|
|
elements = namespaces.sort_by(&:human_name).map! do |n|
|
||||||
|
|
Loading…
Reference in a new issue