kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
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.
320 lines
10 KiB
320 lines
10 KiB
#-- 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 Repository::Subversion, type: :model do
|
|
let(:instance) { FactoryGirl.build(:repository_subversion) }
|
|
let(:adapter) { instance.scm }
|
|
let(:config) { {} }
|
|
let(:enabled_scm) { %w[subversion] }
|
|
|
|
before do
|
|
allow(Setting).to receive(:enabled_scm).and_return(enabled_scm)
|
|
allow(instance).to receive(:scm).and_return(adapter)
|
|
allow(instance.class).to receive(:scm_config).and_return(config)
|
|
end
|
|
|
|
describe 'when disabled' do
|
|
let(:enabled_scm) { [] }
|
|
|
|
it 'does not allow creating a repository' do
|
|
expect { instance.save! }.to raise_error ActiveRecord::RecordInvalid
|
|
end
|
|
end
|
|
|
|
describe 'default Subversion' do
|
|
it 'is not manageable' do
|
|
expect(instance.manageable?).to be false
|
|
end
|
|
|
|
it 'has one available type' do
|
|
expect(instance.class.available_types).to eq [:existing]
|
|
end
|
|
|
|
context 'with disabled types' do
|
|
let(:config) { { disabled_types: [:existing, :managed] } }
|
|
|
|
it 'does not have any types' do
|
|
expect(instance.class.available_types).to be_empty
|
|
end
|
|
end
|
|
|
|
context 'with mixed disabled types' do
|
|
let(:config) { { disabled_types: ['existing', :managed] } }
|
|
|
|
it 'does not have any types' do
|
|
expect(instance.class.available_types).to be_empty
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'managed Subversion' do
|
|
let(:managed_path) { '/tmp/managed_svn' }
|
|
it 'is not manageable unless configured explicitly' do
|
|
expect(instance.manageable?).to be false
|
|
end
|
|
|
|
context 'with managed config' do
|
|
let(:config) { { manages: managed_path } }
|
|
let(:project) { FactoryGirl.build :project }
|
|
|
|
it 'is manageable' do
|
|
expect(instance.manageable?).to be true
|
|
expect(instance.class.available_types).to eq([:existing, :managed])
|
|
end
|
|
|
|
context 'with disabled managed typed' do
|
|
let(:config) { { disabled_types: [:managed] } }
|
|
|
|
it 'is no longer manageable' do
|
|
expect(instance.class.available_types).to eq([:existing])
|
|
expect(instance.manageable?).to be false
|
|
end
|
|
end
|
|
|
|
context 'and associated project' do
|
|
before do
|
|
instance.project = project
|
|
end
|
|
|
|
it 'outputs valid managed paths' do
|
|
path = File.join(managed_path, project.identifier)
|
|
expect(instance.managed_repository_path).to eq(path)
|
|
expect(instance.managed_repository_url).to eq("file://#{path}")
|
|
end
|
|
end
|
|
|
|
context 'and associated project with parent' do
|
|
let(:parent) { FactoryGirl.build :project }
|
|
let(:project) { FactoryGirl.build :project, parent: parent }
|
|
|
|
before do
|
|
instance.project = project
|
|
end
|
|
|
|
it 'outputs the correct hierarchy path' do
|
|
expect(instance.managed_repository_path)
|
|
.to eq(File.join(managed_path, project.identifier))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'with a remote repository' do
|
|
let(:instance) {
|
|
FactoryGirl.build(:repository_subversion,
|
|
url: 'https://somewhere.example.org/svn/foo'
|
|
)
|
|
}
|
|
|
|
it_behaves_like 'is not a countable repository' do
|
|
let(:repository) { instance }
|
|
end
|
|
end
|
|
|
|
describe 'with an actual repository' do
|
|
with_subversion_repository do |repo_dir|
|
|
let(:url) { "file://#{repo_dir}" }
|
|
let(:instance) { FactoryGirl.create(:repository_subversion, url: url, root_url: url) }
|
|
|
|
it 'should be available' do
|
|
expect(instance.scm).to be_available
|
|
end
|
|
|
|
it 'should fetch changesets from scratch' do
|
|
instance.fetch_changesets
|
|
instance.reload
|
|
|
|
expect(instance.changesets.count).to eq(12)
|
|
expect(instance.file_changes.count).to eq(21)
|
|
expect(instance.changesets.find_by(revision: '1').comments).to eq('Initial import.')
|
|
end
|
|
|
|
it 'should fetch changesets incremental' do
|
|
instance.fetch_changesets
|
|
|
|
# Remove changesets with revision > 5
|
|
instance.changesets.each do |c| c.destroy if c.revision.to_i > 5 end
|
|
instance.reload
|
|
expect(instance.changesets.count).to eq(5)
|
|
|
|
instance.fetch_changesets
|
|
expect(instance.changesets.count).to eq(12)
|
|
end
|
|
|
|
it 'should latest changesets' do
|
|
instance.fetch_changesets
|
|
|
|
# with limit
|
|
changesets = instance.latest_changesets('', nil, 2)
|
|
assert_equal 2, changesets.size
|
|
assert_equal instance.latest_changesets('', nil).slice(0, 2), changesets
|
|
|
|
# with path
|
|
changesets = instance.latest_changesets('subversion_test/folder', nil)
|
|
expect(changesets.map(&:revision)).to eq %w[10 9 7 6 5 2]
|
|
|
|
# with path and revision
|
|
changesets = instance.latest_changesets('subversion_test/folder', 8)
|
|
expect(changesets.map(&:revision)).to eq %w[7 6 5 2]
|
|
end
|
|
|
|
it 'should directory listing with square brackets in path' do
|
|
instance.fetch_changesets
|
|
instance.reload
|
|
|
|
entries = instance.entries('subversion_test/[folder_with_brackets]')
|
|
expect(entries).to_not be_nil
|
|
expect(entries.size).to eq(1)
|
|
expect(entries.first.name).to eq('README.txt')
|
|
end
|
|
|
|
context 'with square brackets in base' do
|
|
let(:url) { "file://#{repo_dir}/subversion_test/[folder_with_brackets]" }
|
|
|
|
it 'should directory listing with square brackets in base' do
|
|
instance.fetch_changesets
|
|
instance.reload
|
|
|
|
expect(instance.changesets.count).to eq(1)
|
|
expect(instance.file_changes.count).to eq(2)
|
|
|
|
entries = instance.entries('')
|
|
expect(entries).to_not be_nil
|
|
expect(entries.size).to eq(1)
|
|
expect(entries.first.name).to eq('README.txt')
|
|
end
|
|
end
|
|
|
|
it 'should show the identifier' do
|
|
instance.fetch_changesets
|
|
instance.reload
|
|
c = instance.changesets.find_by(revision: '1')
|
|
expect(c.revision).to eq(c.identifier)
|
|
end
|
|
|
|
it 'should find changeset by empty name' do
|
|
instance.fetch_changesets
|
|
instance.reload
|
|
['', ' ', nil].each do |r|
|
|
expect(instance.find_changeset_by_name(r)).to be_nil
|
|
end
|
|
end
|
|
|
|
it 'should identifier nine digit' do
|
|
c = Changeset.new(repository: instance, committed_on: Time.now,
|
|
revision: '123456789', comments: 'test')
|
|
expect(c.identifier).to eq(c.revision)
|
|
end
|
|
|
|
it 'should format identifier' do
|
|
instance.fetch_changesets
|
|
instance.reload
|
|
c = instance.changesets.find_by(revision: '1')
|
|
expect(c.format_identifier).to eq(c.revision)
|
|
end
|
|
|
|
it 'should format identifier nine digit' do
|
|
c = Changeset.new(repository: instance, committed_on: Time.now,
|
|
revision: '123456789', comments: 'test')
|
|
expect(c.format_identifier).to eq(c.revision)
|
|
end
|
|
|
|
it 'should log encoding ignore setting' do
|
|
with_settings commit_logs_encoding: 'windows-1252' do
|
|
s1 = "\xC2\x80"
|
|
s2 = "\xc3\x82\xc2\x80"
|
|
if s1.respond_to?(:force_encoding)
|
|
s1.force_encoding('ISO-8859-1')
|
|
s2.force_encoding('UTF-8')
|
|
assert_equal s1.encode('UTF-8'), s2
|
|
end
|
|
c = Changeset.new(repository: instance,
|
|
comments: s2,
|
|
revision: '123',
|
|
committed_on: Time.now)
|
|
expect(c.save).to be true
|
|
expect(c.comments).to eq(s2)
|
|
end
|
|
end
|
|
|
|
it 'should load previous and next changeset' do
|
|
instance.fetch_changesets
|
|
instance.reload
|
|
changeset2 = instance.find_changeset_by_name('2')
|
|
changeset3 = instance.find_changeset_by_name('3')
|
|
expect(changeset3.previous).to eq(changeset2)
|
|
expect(changeset2.next).to eq(changeset3)
|
|
end
|
|
|
|
it 'should return nil for no previous or next changeset' do
|
|
instance.fetch_changesets
|
|
instance.reload
|
|
changeset = instance.find_changeset_by_name('1')
|
|
expect(changeset.previous).to be_nil
|
|
|
|
changeset = instance.find_changeset_by_name('12')
|
|
expect(changeset.next).to be_nil
|
|
end
|
|
|
|
context 'with an admin browsing activity' do
|
|
let(:user) { FactoryGirl.create(:admin) }
|
|
let(:project) { FactoryGirl.create(:project) }
|
|
|
|
def find_events(user, options = {})
|
|
fetcher = Redmine::Activity::Fetcher.new(user, options)
|
|
fetcher.scope = ['changesets']
|
|
fetcher.events(Date.today - 30, Date.today + 1)
|
|
end
|
|
|
|
it 'should find events' do
|
|
Changeset.create(repository: instance, committed_on: Time.now,
|
|
revision: '1', comments: 'test')
|
|
event = find_events(user).first
|
|
expect(event.event_title).to include('1:')
|
|
expect(event.event_path).to match(/\?rev=1$/)
|
|
end
|
|
|
|
it 'should find events with larger numbers' do
|
|
Changeset.create(repository: instance, committed_on: Time.now,
|
|
revision: '123456789', comments: 'test')
|
|
event = find_events(user).first
|
|
expect(event.event_title).to include('123456789:')
|
|
expect(event.event_path).to match(/\?rev=123456789$/)
|
|
end
|
|
end
|
|
|
|
it_behaves_like 'is a countable repository' do
|
|
let(:repository) { instance }
|
|
end
|
|
end
|
|
end
|
|
|
|
it_behaves_like 'repository can be relocated', :subversion
|
|
end
|
|
|