2013-11-06 10:13:21 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:49 -05:00
|
|
|
describe Projects::UpdateService, services: true do
|
2013-11-06 10:13:21 -05:00
|
|
|
describe :update_by_user do
|
|
|
|
before do
|
|
|
|
@user = create :user
|
|
|
|
@admin = create :user, admin: true
|
|
|
|
@project = create :project, creator_id: @user.id, namespace: @user.namespace
|
2014-06-26 17:28:32 -04:00
|
|
|
@opts = {}
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be private when updated to private' do
|
|
|
|
before do
|
2015-06-23 01:25:40 -04:00
|
|
|
@created_private = @project.private?
|
2013-11-06 10:13:21 -05:00
|
|
|
|
2015-06-23 01:25:40 -04:00
|
|
|
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
|
|
|
|
update_project(@project, @user, @opts)
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@created_private).to be_truthy }
|
|
|
|
it { expect(@project.private?).to be_truthy }
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be internal when updated to internal' do
|
|
|
|
before do
|
|
|
|
@created_private = @project.private?
|
|
|
|
|
2014-06-26 17:28:32 -04:00
|
|
|
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
|
2013-11-06 10:13:21 -05:00
|
|
|
update_project(@project, @user, @opts)
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@created_private).to be_truthy }
|
|
|
|
it { expect(@project.internal?).to be_truthy }
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be public when updated to public' do
|
|
|
|
before do
|
|
|
|
@created_private = @project.private?
|
|
|
|
|
2014-06-26 17:28:32 -04:00
|
|
|
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
2013-11-06 10:13:21 -05:00
|
|
|
update_project(@project, @user, @opts)
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@created_private).to be_truthy }
|
|
|
|
it { expect(@project.public?).to be_truthy }
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'respect configured visibility restrictions setting' do
|
|
|
|
before(:each) do
|
2015-07-01 17:21:51 -04:00
|
|
|
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be private when updated to private' do
|
|
|
|
before do
|
|
|
|
@created_private = @project.private?
|
|
|
|
|
2014-06-26 17:28:32 -04:00
|
|
|
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
|
2013-11-06 10:13:21 -05:00
|
|
|
update_project(@project, @user, @opts)
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@created_private).to be_truthy }
|
|
|
|
it { expect(@project.private?).to be_truthy }
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be internal when updated to internal' do
|
|
|
|
before do
|
|
|
|
@created_private = @project.private?
|
|
|
|
|
2014-06-26 17:28:32 -04:00
|
|
|
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
|
2013-11-06 10:13:21 -05:00
|
|
|
update_project(@project, @user, @opts)
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@created_private).to be_truthy }
|
|
|
|
it { expect(@project.internal?).to be_truthy }
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be private when updated to public' do
|
|
|
|
before do
|
|
|
|
@created_private = @project.private?
|
|
|
|
|
2014-06-26 17:28:32 -04:00
|
|
|
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
2013-11-06 10:13:21 -05:00
|
|
|
update_project(@project, @user, @opts)
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@created_private).to be_truthy }
|
|
|
|
it { expect(@project.private?).to be_truthy }
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be public when updated to public by admin' do
|
|
|
|
before do
|
|
|
|
@created_private = @project.private?
|
|
|
|
|
2014-06-26 17:28:32 -04:00
|
|
|
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
2013-11-06 10:13:21 -05:00
|
|
|
update_project(@project, @admin, @opts)
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@created_private).to be_truthy }
|
|
|
|
it { expect(@project.public?).to be_truthy }
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-24 04:33:26 -05:00
|
|
|
describe :visibility_level do
|
|
|
|
let(:user) { create :user, admin: true }
|
2016-03-08 16:40:45 -05:00
|
|
|
let(:project) { create(:project, :internal) }
|
|
|
|
let(:forked_project) { create(:forked_project_with_submodules, :internal) }
|
2015-12-24 04:33:26 -05:00
|
|
|
let(:opts) { {} }
|
|
|
|
|
|
|
|
before do
|
|
|
|
forked_project.build_forked_project_link(forked_to_project_id: forked_project.id, forked_from_project_id: project.id)
|
|
|
|
forked_project.save
|
|
|
|
|
|
|
|
@created_internal = project.internal?
|
|
|
|
@fork_created_internal = forked_project.internal?
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'should update forks visibility level when parent set to more restrictive' do
|
|
|
|
before do
|
|
|
|
opts.merge!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
|
|
|
|
update_project(project, user, opts).inspect
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(@created_internal).to be_truthy }
|
|
|
|
it { expect(@fork_created_internal).to be_truthy }
|
|
|
|
it { expect(project.private?).to be_truthy }
|
|
|
|
it { expect(project.forks.first.private?).to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'should not update forks visibility level when parent set to less restrictive' do
|
|
|
|
before do
|
|
|
|
opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
update_project(project, user, opts).inspect
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(@created_internal).to be_truthy }
|
|
|
|
it { expect(@fork_created_internal).to be_truthy }
|
|
|
|
it { expect(project.public?).to be_truthy }
|
|
|
|
it { expect(project.forks.first.internal?).to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-06 10:13:21 -05:00
|
|
|
def update_project(project, user, opts)
|
2014-01-16 13:29:18 -05:00
|
|
|
Projects::UpdateService.new(project, user, opts).execute
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
2014-01-16 13:29:18 -05:00
|
|
|
end
|