From 8d22ff8c21ea55d2af19c5f61426c7460aef2847 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 31 Jul 2018 21:31:59 -0700 Subject: [PATCH] Fix failing spec in ./spec/features/projects/new_project_spec.rb --- app/helpers/namespaces_helper.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb index 1503aea4aa2..f3670b24c3e 100644 --- a/app/helpers/namespaces_helper.rb +++ b/app/helpers/namespaces_helper.rb @@ -9,20 +9,22 @@ module NamespacesHelper .includes(:route) .order('routes.path') users = [current_user.namespace] - selected_option = nil unless extra_group.nil? || extra_group.is_a?(Group) extra_group = Group.find(extra_group) if Namespace.find(extra_group).kind == 'group' end if extra_group && extra_group.is_a?(Group) - # Avoid duplicate groups if one already exists by that name - existing_group = Group.find_by(name: extra_group.name) - extra_group = existing_group if existing_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 + end if Ability.allowed?(current_user, :read_group, extra_group) + selected = extra_group.id if selected == :extra_group groups |= [extra_group] - selected_option = extra_group.id if selected == :extra_group end end @@ -32,12 +34,12 @@ module NamespacesHelper unless groups_only options << options_for_group(users, display_path: display_path, type: 'user') - if (selected == :current_user || selected_option.nil?) && current_user.namespace - selected_option = current_user.namespace.id + if selected == :current_user && current_user.namespace + selected = current_user.namespace.id end end - grouped_options_for_select(options, selected_option) + grouped_options_for_select(options, selected) end def namespace_icon(namespace, size = 40)