Commit f9263890 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Address minor backend comments

Moves a common test to a shared example
block for re-use
parent e130b170
...@@ -39,7 +39,7 @@ export default () => { ...@@ -39,7 +39,7 @@ export default () => {
}, },
on: { on: {
selectNamespace: (id) => { selectNamespace: (id) => {
if (targetHiddenInputId && document.getElementById(targetHiddenInputId)?.value) { if (targetHiddenInputId && document.getElementById(targetHiddenInputId)) {
document.getElementById(targetHiddenInputId).value = id; document.getElementById(targetHiddenInputId).value = id;
} }
}, },
......
...@@ -90,7 +90,7 @@ module NamespacesHelper ...@@ -90,7 +90,7 @@ module NamespacesHelper
def namespaces_as_json(selected = :current_user) def namespaces_as_json(selected = :current_user)
{ {
group: formatted_namespaces(current_user.manageable_groups_with_routes), group: formatted_namespaces(current_user.manageable_groups_with_routes(include_groups_with_developer_maintainer_access: true)),
user: formatted_namespaces([current_user.namespace]) user: formatted_namespaces([current_user.namespace])
}.to_json }.to_json
end end
......
...@@ -904,24 +904,7 @@ RSpec.describe ProjectsController do ...@@ -904,24 +904,7 @@ RSpec.describe ProjectsController do
let_it_be(:admin) { create(:admin) } let_it_be(:admin) { create(:admin) }
let_it_be(:new_namespace) { create(:namespace) } let_it_be(:new_namespace) { create(:namespace) }
it 'updates namespace' do shared_examples 'project namespace is not changed' do |flash_message|
sign_in(admin)
put :transfer,
params: {
namespace_id: project.namespace.path,
new_namespace_id: new_namespace.id,
id: project.path
},
format: :js
project.reload
expect(project.namespace).to eq(new_namespace)
expect(response).to have_gitlab_http_status(:ok)
end
context 'when new namespace is empty' do
it 'project namespace is not changed' do it 'project namespace is not changed' do
controller.instance_variable_set(:@project, project) controller.instance_variable_set(:@project, project)
sign_in(admin) sign_in(admin)
...@@ -931,7 +914,7 @@ RSpec.describe ProjectsController do ...@@ -931,7 +914,7 @@ RSpec.describe ProjectsController do
put :transfer, put :transfer,
params: { params: {
namespace_id: old_namespace.path, namespace_id: old_namespace.path,
new_namespace_id: nil, new_namespace_id: new_namespace_id,
id: project.path id: project.path
}, },
format: :js format: :js
...@@ -940,31 +923,37 @@ RSpec.describe ProjectsController do ...@@ -940,31 +923,37 @@ RSpec.describe ProjectsController do
expect(project.namespace).to eq(old_namespace) expect(project.namespace).to eq(old_namespace)
expect(response).to redirect_to(edit_project_path(project)) expect(response).to redirect_to(edit_project_path(project))
expect(flash[:alert]).to eq s_('TransferProject|Please select a new namespace for your project.') expect(flash[:alert]).to eq flash_message
end end
end end
context 'when new namespace is the same as the current namespace' do it 'updates namespace' do
it 'project namespace is not changed' do sign_in(admin)
controller.instance_variable_set(:@project, project)
sign_in(admin)
old_namespace = project.namespace put :transfer,
params: {
namespace_id: project.namespace.path,
new_namespace_id: new_namespace.id,
id: project.path
},
format: :js
put :transfer, project.reload
params: {
namespace_id: project.namespace.path,
new_namespace_id: old_namespace.id,
id: project.path
},
format: :js
project.reload expect(project.namespace).to eq(new_namespace)
expect(response).to have_gitlab_http_status(:ok)
end
expect(project.namespace).to eq(old_namespace) context 'when new namespace is empty' do
expect(response).to redirect_to(edit_project_path(project)) let(:new_namespace_id) { nil }
expect(flash[:alert]).to eq s_('TransferProject|Project is already in this namespace.')
end it_behaves_like 'project namespace is not changed', s_('TransferProject|Please select a new namespace for your project.')
end
context 'when new namespace is the same as the current namespace' do
let(:new_namespace_id) { project.namespace.id }
it_behaves_like 'project namespace is not changed', s_('TransferProject|Project is already in this namespace.')
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