Commit 4158f43b authored by Stan Hu's avatar Stan Hu

Merge branch 'xanf-introduce-import-namespaces-controller' into 'master'

Add import/namespaces controller

See merge request gitlab-org/gitlab!38786
parents 7f02a473 8c535095
# frozen_string_literal: true
class Import::AvailableNamespacesController < ApplicationController
def index
render json: NamespaceSerializer.new.represent(current_user.manageable_groups_with_routes)
end
end
......@@ -8,6 +8,8 @@ Devise.omniauth_providers.map(&:downcase).each do |provider|
end
namespace :import do
resources :available_namespaces, only: [:index], controller: :available_namespaces
resource :github, only: [:create, :new], controller: :github do
post :personal_access_token
get :status
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Import::AvailableNamespacesController do
let_it_be(:user) { create(:user) }
let_it_be(:manageable_groups) { [create(:group), create(:group)] }
before do
sign_in(user)
manageable_groups.each { |group| group.add_maintainer(user) }
end
describe "GET index" do
it "returns list of available namespaces" do
unrelated_group = create(:group)
get :index
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_kind_of(Array)
response_ids = json_response.map { |n| n["id"] }
expect(response_ids).not_to include(unrelated_group.id)
expect(response_ids).to contain_exactly(*manageable_groups.map(&:id))
end
context "with an anonymous user" do
before do
sign_out(user)
end
it "redirects to sign-in page" do
get :index
expect(response).to redirect_to(new_user_session_path)
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