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.
171 lines
6.5 KiB
171 lines
6.5 KiB
13 years ago
|
#-- encoding: UTF-8
|
||
14 years ago
|
#-- copyright
|
||
12 years ago
|
# OpenProject is a project management system.
|
||
10 years ago
|
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||
14 years ago
|
#
|
||
18 years ago
|
# This program is free software; you can redistribute it and/or
|
||
12 years ago
|
# modify it under the terms of the GNU General Public License version 3.
|
||
14 years ago
|
#
|
||
11 years ago
|
# 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.
|
||
|
#
|
||
14 years ago
|
# See doc/COPYRIGHT.rdoc for more details.
|
||
|
#++
|
||
10 years ago
|
require 'legacy_spec_helper'
|
||
18 years ago
|
|
||
11 years ago
|
describe Repository, type: :model do
|
||
12 years ago
|
fixtures :all
|
||
14 years ago
|
|
||
11 years ago
|
before do
|
||
18 years ago
|
@repository = Project.find(1).repository
|
||
|
end
|
||
14 years ago
|
|
||
10 years ago
|
around do |example|
|
||
9 years ago
|
with_settings enabled_scm: %w(subversion) do
|
||
10 years ago
|
example.run
|
||
|
end
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should create' do
|
||
9 years ago
|
repository = Repository::Subversion.new(project: Project.find(3), scm_type: 'existing')
|
||
18 years ago
|
assert !repository.save
|
||
14 years ago
|
|
||
10 years ago
|
repository.url = 'svn://localhost'
|
||
18 years ago
|
assert repository.save
|
||
|
repository.reload
|
||
14 years ago
|
|
||
17 years ago
|
project = Project.find(3)
|
||
15 years ago
|
assert_equal repository, project.repository
|
||
18 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should destroy' do
|
||
12 years ago
|
changesets = Changeset.where('repository_id = 10').size
|
||
9 years ago
|
changes = Change.includes(:changeset)
|
||
|
.where("#{Changeset.table_name}.repository_id = 10")
|
||
|
.references(:changesets)
|
||
|
.size
|
||
17 years ago
|
assert_difference 'Changeset.count', -changesets do
|
||
|
assert_difference 'Change.count', -changes do
|
||
|
Repository.find(10).destroy
|
||
|
end
|
||
|
end
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should not create with disabled scm' do
|
||
12 years ago
|
Setting.enabled_scm = ['Git'] # disable Subversion
|
||
9 years ago
|
repository = Repository::Subversion.new(project: Project.find(3), scm_type: 'existing', url: 'svn://localhost')
|
||
17 years ago
|
assert !repository.save
|
||
9 years ago
|
assert_includes repository.errors[:type], I18n.translate('activerecord.errors.models.repository.not_available')
|
||
17 years ago
|
# re-enable Subversion for following tests
|
||
|
Setting.delete_all
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should scan changesets for work package ids' do
|
||
10 years ago
|
WorkPackage.all.each(&:recreate_initial_journal!)
|
||
11 years ago
|
|
||
16 years ago
|
Setting.default_language = 'en'
|
||
10 years ago
|
Setting.notified_events = ['work_package_added', 'work_package_updated']
|
||
14 years ago
|
|
||
18 years ago
|
# choosing a status to apply to fix issues
|
||
9 years ago
|
Setting.commit_fix_status_id = Status.where(['is_closed = ?', true]).first.id
|
||
10 years ago
|
Setting.commit_fix_done_ratio = '90'
|
||
17 years ago
|
Setting.commit_ref_keywords = 'refs , references, IssueID'
|
||
|
Setting.commit_fix_keywords = 'fixes , closes'
|
||
17 years ago
|
Setting.default_language = 'en'
|
||
14 years ago
|
|
||
11 years ago
|
# make sure work package 1 is not already closed
|
||
|
fixed_work_package = WorkPackage.find(1)
|
||
|
assert !fixed_work_package.status.is_closed?
|
||
|
old_status = fixed_work_package.status
|
||
14 years ago
|
|
||
11 years ago
|
Repository.scan_changesets_for_work_package_ids
|
||
|
assert_equal [101, 102], WorkPackage.find(3).changeset_ids
|
||
14 years ago
|
|
||
18 years ago
|
# fixed issues
|
||
11 years ago
|
fixed_work_package.reload
|
||
|
assert fixed_work_package.status.is_closed?
|
||
|
assert_equal 90, fixed_work_package.done_ratio
|
||
|
assert_equal [101], fixed_work_package.changeset_ids
|
||
14 years ago
|
|
||
17 years ago
|
# issue change
|
||
11 years ago
|
journal = fixed_work_package.journals.last
|
||
10 years ago
|
assert_equal User.find_by_login('dlopper'), journal.user
|
||
17 years ago
|
assert_equal 'Applied in changeset r2.', journal.notes
|
||
11 years ago
|
|
||
14 years ago
|
# 2 email notifications to 5 users
|
||
|
assert_equal 5, ActionMailer::Base.deliveries.size
|
||
17 years ago
|
mail = ActionMailer::Base.deliveries.first
|
||
12 years ago
|
assert_kind_of Mail::Message, mail
|
||
11 years ago
|
assert mail.subject.starts_with?("[#{fixed_work_package.project.name} - #{fixed_work_package.type.name} ##{fixed_work_package.id}]")
|
||
11 years ago
|
assert mail.body.encoded.include?("Status changed from #{old_status} to #{fixed_work_package.status}")
|
||
14 years ago
|
|
||
18 years ago
|
# ignoring commits referencing an issue of another project
|
||
11 years ago
|
assert_equal [], WorkPackage.find(4).changesets
|
||
18 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should for changeset comments strip' do
|
||
9 years ago
|
repository = Repository::Subversion.create(
|
||
|
project: Project.find(4),
|
||
|
scm_type: 'existing',
|
||
|
url: 'svn://:login:password@host:/path/to/the/repository'
|
||
|
)
|
||
10 years ago
|
comment = 'This is a looooooooooooooong comment' + (' ' * 80 + "\n") * 5
|
||
17 years ago
|
changeset = Changeset.new(
|
||
10 years ago
|
comments: comment, commit_date: Time.now, revision: 0, scmid: 'f39b7922fb3c',
|
||
10 years ago
|
committer: 'foo <foo@example.com>', committed_on: Time.now, repository: repository)
|
||
|
assert(changeset.save)
|
||
9 years ago
|
refute_equal(comment, changeset.comments)
|
||
10 years ago
|
assert_equal('This is a looooooooooooooong comment', changeset.comments)
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should for urls strip' do
|
||
12 years ago
|
repository = Repository::Subversion.create(
|
||
11 years ago
|
project: Project.find(4),
|
||
|
url: ' svn://:login:password@host:/path/to/the/repository',
|
||
9 years ago
|
scm_type: 'existing',
|
||
11 years ago
|
log_encoding: 'UTF-8')
|
||
12 years ago
|
repository.root_url = 'foo ' # can't mass-assign this attr
|
||
17 years ago
|
assert repository.save
|
||
|
repository.reload
|
||
12 years ago
|
assert_equal 'svn://:login:password@host:/path/to/the/repository', repository.url
|
||
17 years ago
|
assert_equal 'foo', repository.root_url
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should manual user mapping' do
|
||
9 years ago
|
assert_no_difference "Changeset.where('user_id <> 2').count" do
|
||
10 years ago
|
c = Changeset.create!(repository: @repository, committer: 'foo', committed_on: Time.now, revision: 100, comments: 'Committed by foo.')
|
||
16 years ago
|
assert_nil c.user
|
||
10 years ago
|
@repository.committer_ids = { 'foo' => '2' }
|
||
16 years ago
|
assert_equal User.find(2), c.reload.user
|
||
|
# committer is now mapped
|
||
10 years ago
|
c = Changeset.create!(repository: @repository, committer: 'foo', committed_on: Time.now, revision: 101, comments: 'Another commit by foo.')
|
||
16 years ago
|
assert_equal User.find(2), c.user
|
||
|
end
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should auto user mapping by username' do
|
||
10 years ago
|
c = Changeset.create!(repository: @repository, committer: 'jsmith', committed_on: Time.now, revision: 100, comments: 'Committed by john.')
|
||
16 years ago
|
assert_equal User.find(2), c.user
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should auto user mapping by email' do
|
||
10 years ago
|
c = Changeset.create!(repository: @repository, committer: 'john <jsmith@somenet.foo>', committed_on: Time.now, revision: 100, comments: 'Committed by john.')
|
||
16 years ago
|
assert_equal User.find(2), c.user
|
||
|
end
|
||
18 years ago
|
end
|