2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-24 10:58:48 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Groups::SharedProjectsController do
|
|
|
|
def get_shared_projects(params = {})
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: params.reverse_merge(format: :json, group_id: group.full_path)
|
2018-05-24 10:58:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def share_project(project)
|
2019-02-12 07:29:47 -05:00
|
|
|
group.add_developer(user)
|
|
|
|
|
2018-05-24 10:58:48 -04:00
|
|
|
Projects::GroupLinks::CreateService.new(
|
|
|
|
project,
|
|
|
|
user,
|
|
|
|
link_group_access: ProjectGroupLink::DEVELOPER
|
|
|
|
).execute(group)
|
|
|
|
end
|
|
|
|
|
2018-05-29 05:44:58 -04:00
|
|
|
set(:group) { create(:group) }
|
|
|
|
set(:user) { create(:user) }
|
|
|
|
set(:shared_project) do
|
2018-05-24 10:58:48 -04:00
|
|
|
shared_project = create(:project, namespace: user.namespace)
|
|
|
|
share_project(shared_project)
|
|
|
|
|
|
|
|
shared_project
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:json_project_ids) { json_response.map { |project_info| project_info['id'] } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
it 'returns only projects shared with the group' do
|
|
|
|
create(:project, namespace: group)
|
|
|
|
|
|
|
|
get_shared_projects
|
|
|
|
|
|
|
|
expect(json_project_ids).to contain_exactly(shared_project.id)
|
|
|
|
end
|
|
|
|
|
2018-05-29 05:44:58 -04:00
|
|
|
it 'allows filtering shared projects' do
|
2018-06-04 04:41:56 -04:00
|
|
|
project = create(:project, namespace: user.namespace, name: "Searching for")
|
2018-05-24 10:58:48 -04:00
|
|
|
share_project(project)
|
|
|
|
|
|
|
|
get_shared_projects(filter: 'search')
|
|
|
|
|
|
|
|
expect(json_project_ids).to contain_exactly(project.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows sorting projects' do
|
|
|
|
shared_project.update!(name: 'bbb')
|
|
|
|
second_project = create(:project, namespace: user.namespace, name: 'aaaa')
|
|
|
|
share_project(second_project)
|
|
|
|
|
|
|
|
get_shared_projects(sort: 'name_asc')
|
|
|
|
|
|
|
|
expect(json_project_ids).to eq([second_project.id, shared_project.id])
|
|
|
|
end
|
2018-06-04 04:41:56 -04:00
|
|
|
|
|
|
|
it 'does not include archived projects' do
|
|
|
|
archived_project = create(:project, :archived, namespace: user.namespace)
|
|
|
|
share_project(archived_project)
|
|
|
|
|
|
|
|
get_shared_projects
|
|
|
|
|
|
|
|
expect(json_project_ids).to contain_exactly(shared_project.id)
|
|
|
|
end
|
2018-05-24 10:58:48 -04:00
|
|
|
end
|
|
|
|
end
|