summaryrefslogtreecommitdiff
path: root/app/helpers/namespaces_helper.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-08-01 13:19:20 -0700
committerStan Hu <stanhu@gmail.com>2018-08-01 13:19:20 -0700
commitab12b379f0276dcadc7e452571cc46ab9500f262 (patch)
tree04d042fd06efb7a4e1dd4ed09abc444743d919bb /app/helpers/namespaces_helper.rb
parent883d1dabbf27ca4a4e87d93c2675b25de60d9b50 (diff)
downloadgitlab-ce-ab12b379f0276dcadc7e452571cc46ab9500f262.tar.gz
Fix spec failures with app/helpers/namespaces_helper.rb
Diffstat (limited to 'app/helpers/namespaces_helper.rb')
-rw-r--r--app/helpers/namespaces_helper.rb20
1 files changed, 14 insertions, 6 deletions
diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb
index 834b902ff36..66aaf055cf2 100644
--- a/app/helpers/namespaces_helper.rb
+++ b/app/helpers/namespaces_helper.rb
@@ -16,18 +16,15 @@ module NamespacesHelper
end
if extra_group && extra_group.is_a?(Group)
- # Many importers create a temporary Group, so use the real
- # 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
+ extra_group = dedup_extra_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
extra_group.id = -1 unless extra_group.persisted?
selected_id = extra_group.id if selected == :extra_group
groups |= [extra_group]
+ else
+ selected_id = current_user.namespace.id
end
end
@@ -55,6 +52,17 @@ module NamespacesHelper
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:)
group_label = type.pluralize
elements = namespaces.sort_by(&:human_name).map! do |n|