2014-09-02 18:07:02 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::UpdateService do
|
|
|
|
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
|
|
|
|
@opts = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be private when updated to private' do
|
|
|
|
before do
|
2015-09-11 14:41:01 +05:30
|
|
|
@created_private = @project.private?
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
|
|
|
|
update_project(@project, @user, @opts)
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(@created_private).to be_truthy }
|
|
|
|
it { expect(@project.private?).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be internal when updated to internal' do
|
|
|
|
before do
|
|
|
|
@created_private = @project.private?
|
|
|
|
|
|
|
|
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
|
|
|
|
update_project(@project, @user, @opts)
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(@created_private).to be_truthy }
|
|
|
|
it { expect(@project.internal?).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be public when updated to public' do
|
|
|
|
before do
|
|
|
|
@created_private = @project.private?
|
|
|
|
|
|
|
|
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
update_project(@project, @user, @opts)
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(@created_private).to be_truthy }
|
|
|
|
it { expect(@project.public?).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'respect configured visibility restrictions setting' do
|
|
|
|
before(:each) 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
|
|
|
|
|
|
|
|
context 'should be private when updated to private' do
|
|
|
|
before do
|
|
|
|
@created_private = @project.private?
|
|
|
|
|
|
|
|
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
|
|
|
|
update_project(@project, @user, @opts)
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(@created_private).to be_truthy }
|
|
|
|
it { expect(@project.private?).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be internal when updated to internal' do
|
|
|
|
before do
|
|
|
|
@created_private = @project.private?
|
|
|
|
|
|
|
|
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
|
|
|
|
update_project(@project, @user, @opts)
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(@created_private).to be_truthy }
|
|
|
|
it { expect(@project.internal?).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be private when updated to public' do
|
|
|
|
before do
|
|
|
|
@created_private = @project.private?
|
|
|
|
|
|
|
|
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
update_project(@project, @user, @opts)
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(@created_private).to be_truthy }
|
|
|
|
it { expect(@project.private?).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be public when updated to public by admin' do
|
|
|
|
before do
|
|
|
|
@created_private = @project.private?
|
|
|
|
|
|
|
|
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
update_project(@project, @admin, @opts)
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(@created_private).to be_truthy }
|
|
|
|
it { expect(@project.public?).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_project(project, user, opts)
|
|
|
|
Projects::UpdateService.new(project, user, opts).execute
|
|
|
|
end
|
|
|
|
end
|