debian-mirror-gitlab/spec/controllers/groups/shared_projects_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
1.9 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Groups::SharedProjectsController do
2018-11-08 19:23:39 +05:30
def get_shared_projects(params = {})
2019-02-15 15:39:39 +05:30
get :index, params: params.reverse_merge(format: :json, group_id: group.full_path)
2018-11-08 19:23:39 +05:30
end
def share_project(project)
2019-03-13 22:55:13 +05:30
group.add_developer(user)
2018-11-08 19:23:39 +05:30
Projects::GroupLinks::CreateService.new(
project,
2022-07-16 23:28:13 +05:30
group,
2018-11-08 19:23:39 +05:30
user,
2020-04-22 19:07:51 +05:30
link_group_access: Gitlab::Access::DEVELOPER
2022-07-16 23:28:13 +05:30
).execute
2018-11-08 19:23:39 +05:30
end
2020-10-24 23:57:45 +05:30
let!(:group) { create(:group) }
let!(:user) { create(:user) }
let!(:shared_project) do
2018-11-08 19:23:39 +05:30
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
it 'allows filtering shared projects' do
project = create(:project, namespace: user.namespace, name: "Searching for")
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
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
end
end