Commit 075ee478 authored by Stan Hu's avatar Stan Hu

Fix selection of existing project key by default

parent aa5821e5
......@@ -9,6 +9,7 @@ module NamespacesHelper
.includes(:route)
.order('routes.path')
users = [current_user.namespace]
selected_id = current_user.namespace.id
unless extra_group.nil? || extra_group.is_a?(Group)
extra_group = Group.find(extra_group) if Namespace.find(extra_group).kind == 'group'
......@@ -23,11 +24,11 @@ module NamespacesHelper
end
if Ability.allowed?(current_user, :read_group, extra_group)
selected = extra_group.id if selected == :extra_group
# Assign the value to an invalid primary ID so that the select box works
extra_group.id = -1 if !extra_group.persisted?
selected_id = extra_group.id if selected == :extra_group
groups |= [extra_group]
end
selected ||= :current_user
end
options = []
......@@ -37,11 +38,11 @@ module NamespacesHelper
options << options_for_group(users, display_path: display_path, type: 'user')
if selected == :current_user && current_user.namespace
selected = current_user.namespace.id
selected_id = current_user.namespace.id
end
end
grouped_options_for_select(options, selected)
grouped_options_for_select(options, selected_id)
end
def namespace_icon(namespace, size = 40)
......
......@@ -40,7 +40,7 @@ describe NamespacesHelper do
expect(options).to include(admin_group.name)
end
it 'selects extra_group' do
it 'selects existing group' do
allow(helper).to receive(:current_user).and_return(admin)
options = helper.namespaces_options(:extra_group, display_path: true, extra_group: user_group)
......@@ -49,6 +49,16 @@ describe NamespacesHelper do
expect(options).to include(admin_group.name)
end
it 'selects the new group by default' do
allow(helper).to receive(:current_user).and_return(user)
options = helper.namespaces_options(:extra_group, display_path: true, extra_group: build(:group, name: 'new-group'))
expect(options).to include(user_group.name)
expect(options).not_to include(admin_group.name)
expect(options).to include("selected=\"selected\" value=\"-1\"")
end
it 'falls back to current user selection' do
allow(helper).to receive(:current_user).and_return(user)
......
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