debian-mirror-gitlab/spec/services/projects/update_service_spec.rb

102 lines
3.5 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
2015-12-23 02:04:40 +05:30
describe Projects::UpdateService, services: true do
2017-08-17 22:00:37 +05:30
let(:user) { create(:user) }
let(:admin) { create(:admin) }
let(:project) { create(:empty_project, creator_id: user.id, namespace: user.namespace) }
2014-09-02 18:07:02 +05:30
2017-08-17 22:00:37 +05:30
describe 'update_by_user' do
context 'when visibility_level is INTERNAL' do
it 'updates the project to internal' do
result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::INTERNAL)
2014-09-02 18:07:02 +05:30
2017-08-17 22:00:37 +05:30
expect(result).to eq({ status: :success })
expect(project).to be_internal
2014-09-02 18:07:02 +05:30
end
end
2017-08-17 22:00:37 +05:30
context 'when visibility_level is PUBLIC' do
it 'updates the project to public' do
result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::PUBLIC)
expect(result).to eq({ status: :success })
expect(project).to be_public
2014-09-02 18:07:02 +05:30
end
end
2017-08-17 22:00:37 +05:30
context 'when visibility levels are restricted to PUBLIC only' do
2014-09-02 18:07:02 +05:30
before do
2015-09-11 14:41:01 +05:30
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
context 'when visibility_level is INTERNAL' do
it 'updates the project to internal' do
result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::INTERNAL)
expect(result).to eq({ status: :success })
expect(project).to be_internal
2014-09-02 18:07:02 +05:30
end
end
2017-08-17 22:00:37 +05:30
context 'when visibility_level is PUBLIC' do
it 'does not update the project to public' do
result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::PUBLIC)
2014-09-02 18:07:02 +05:30
2017-08-17 22:00:37 +05:30
expect(result).to eq({ status: :error, message: 'Visibility level unallowed' })
expect(project).to be_private
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
context 'when updated by an admin' do
it 'updates the project to public' do
result = update_project(project, admin, visibility_level: Gitlab::VisibilityLevel::PUBLIC)
expect(result).to eq({ status: :success })
expect(project).to be_public
end
2014-09-02 18:07:02 +05:30
end
end
end
end
2017-08-17 22:00:37 +05:30
describe 'visibility_level' do
let(:project) { create(:empty_project, :internal) }
2016-06-02 11:05:42 +05:30
let(:forked_project) { create(:forked_project_with_submodules, :internal) }
before do
forked_project.build_forked_project_link(forked_to_project_id: forked_project.id, forked_from_project_id: project.id)
forked_project.save
end
2017-08-17 22:00:37 +05:30
it 'updates forks visibility level when parent set to more restrictive' do
opts = { visibility_level: Gitlab::VisibilityLevel::PRIVATE }
expect(project).to be_internal
expect(forked_project).to be_internal
2017-08-17 22:00:37 +05:30
expect(update_project(project, admin, opts)).to eq({ status: :success })
expect(project).to be_private
expect(forked_project.reload).to be_private
end
2017-08-17 22:00:37 +05:30
it 'does not update forks visibility level when parent set to less restrictive' do
opts = { visibility_level: Gitlab::VisibilityLevel::PUBLIC }
expect(project).to be_internal
expect(forked_project).to be_internal
2017-08-17 22:00:37 +05:30
expect(update_project(project, admin, opts)).to eq({ status: :success })
expect(project).to be_public
expect(forked_project.reload).to be_internal
end
end
2017-08-17 22:00:37 +05:30
it 'returns an error result when record cannot be updated' do
result = update_project(project, admin, { name: 'foo&bar' })
expect(result).to eq({ status: :error, message: 'Project could not be updated' })
end
2014-09-02 18:07:02 +05:30
def update_project(project, user, opts)
2017-08-17 22:00:37 +05:30
described_class.new(project, user, opts).execute
2014-09-02 18:07:02 +05:30
end
end