OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/spec/app/services/scm/checkout_instructions_servi...

192 lines
5.8 KiB

#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
require 'spec_helper'
describe Scm::CheckoutInstructionsService do
let(:user) { FactoryGirl.build(:user) }
let(:project) { FactoryGirl.build(:project) }
let(:url) { 'file:///tmp/some/svn/repo' }
let(:repository) {
FactoryGirl.build(:repository_subversion,
url: url,
project: project)
}
let(:base_url) { 'http://example.org/svn/' }
let(:text) { 'foo' }
let(:checkout_hash) {
{
'git' => { 'enabled' => '0' },
'subversion' => { 'enabled' => '1',
'text' => text,
'base_url' => base_url
}
}
}
subject(:service) { Scm::CheckoutInstructionsService.new(repository, user) }
before do
allow(Setting).to receive(:repository_checkout_data).and_return(checkout_hash)
end
describe '#checkout_url' do
shared_examples 'builds the correct URL' do
it 'builds the correct URL' do
expect(service.checkout_url)
.to eq(URI("http://example.org/svn/#{project.identifier}"))
end
it 'builds a subpath' do
expect(service.checkout_url('foo/bar'))
.to eq(URI("http://example.org/svn/#{project.identifier}/foo/bar"))
end
end
it_behaves_like 'builds the correct URL'
context 'with missing trailing slash' do
it_behaves_like 'builds the correct URL'
end
end
describe '#checkout_command' do
it 'returns the SCM vendor command' do
expect(service.checkout_command).to eq('svn checkout')
end
end
describe '#instructions' do
it 'returns the setting when defined' do
expect(service.instructions).to eq('foo')
end
context 'no setting defined' do
let(:text) { nil }
it 'returns the default translated instructions' do
expect(service.instructions)
.to eq(I18n.t("repositories.checkout.default_instructions.subversion"))
end
end
end
describe '#settings' do
it 'svn is available for checkout' do
expect(service.available?).to be true
expect(service.checkout_enabled?).to be true
end
it 'has the correct settings' do
expect(Setting.repository_checkout_data['subversion']['enabled']).to eq('1')
expect(service.instructions).to eq('foo')
expect(service.checkout_base_url).to eq(base_url)
end
context 'missing checkout base URL' do
let(:base_url) { '' }
it 'is not available for checkout even when enabled' do
expect(service.checkout_base_url).to eq(base_url)
expect(service.checkout_enabled?).to be true
expect(service.available?).to be false
end
end
context 'disabled repository' do
let(:repository) { FactoryGirl.build(:repository_git) }
it 'git is not available for checkout' do
expect(service.available?).to be false
expect(service.checkout_enabled?).to be false
end
end
end
describe '#permission' do
context 'with no managed repository' do
it 'is not applicable' do
expect(service.manages_permissions?).to be false
end
end
context 'with managed repository' do
before do
allow(repository).to receive(:managed?).and_return(true)
end
it 'is applicable' do
expect(service.manages_permissions?).to be true
end
it 'returns the correct permissions' do
expect(user)
.to receive(:allowed_to?).with(:commit_access, any_args)
.and_return(true, false, false)
expect(user)
.to receive(:allowed_to?).with(:browse_repository, any_args)
.and_return(true, false)
expect(service.permission).to eq(:readwrite)
expect(service.permission).to eq(:read)
expect(service.permission).to eq(:none)
end
it 'returns the correct permissions for commit access' do
allow(user)
.to receive(:allowed_to?).with(:commit_access, any_args)
.and_return(true)
expect(service.may_commit?).to be true
expect(service.may_checkout?).to be true
end
it 'returns the correct permissions for read access' do
allow(user)
.to receive(:allowed_to?).with(:commit_access, any_args)
.and_return(false)
allow(user)
.to receive(:allowed_to?).with(:browse_repository, any_args)
.and_return(true)
expect(service.may_commit?).to be false
expect(service.may_checkout?).to be true
end
it 'returns the correct permissions for no access' do
allow(user).to receive(:allowed_to?).and_return(false)
expect(service.may_commit?).to be false
expect(service.may_checkout?).to be false
end
end
end
end