@@ -1,127 +1,131 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Changeset < ActiveRecord::Base |
|
19 | 19 | belongs_to :repository |
|
20 | 20 | has_many :changes, :dependent => :delete_all |
|
21 | 21 | has_and_belongs_to_many :issues |
|
22 | 22 | |
|
23 | 23 | acts_as_event :title => Proc.new {|o| "#{l(:label_revision)} #{o.revision}" + (o.comments.blank? ? '' : (': ' + o.comments))}, |
|
24 | 24 | :description => :comments, |
|
25 | 25 | :datetime => :committed_on, |
|
26 | 26 | :author => :committer, |
|
27 | 27 | :url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project_id, :rev => o.revision}} |
|
28 | 28 | |
|
29 | 29 | acts_as_searchable :columns => 'comments', |
|
30 | 30 | :include => :repository, |
|
31 | 31 | :project_key => "#{Repository.table_name}.project_id", |
|
32 | 32 | :date_column => 'committed_on' |
|
33 | 33 | |
|
34 | 34 | validates_presence_of :repository_id, :revision, :committed_on, :commit_date |
|
35 | 35 | validates_uniqueness_of :revision, :scope => :repository_id |
|
36 | 36 | validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true |
|
37 | 37 | |
|
38 | def revision=(r) | |
|
39 | write_attribute :revision, (r.nil? ? nil : r.to_s) | |
|
40 | end | |
|
41 | ||
|
38 | 42 | def comments=(comment) |
|
39 | 43 | write_attribute(:comments, comment.strip) |
|
40 | 44 | end |
|
41 | 45 | |
|
42 | 46 | def committed_on=(date) |
|
43 | 47 | self.commit_date = date |
|
44 | 48 | super |
|
45 | 49 | end |
|
46 | 50 | |
|
47 | 51 | def project |
|
48 | 52 | repository.project |
|
49 | 53 | end |
|
50 | 54 | |
|
51 | 55 | def after_create |
|
52 | 56 | scan_comment_for_issue_ids |
|
53 | 57 | end |
|
54 | 58 | require 'pp' |
|
55 | 59 | |
|
56 | 60 | def scan_comment_for_issue_ids |
|
57 | 61 | return if comments.blank? |
|
58 | 62 | # keywords used to reference issues |
|
59 | 63 | ref_keywords = Setting.commit_ref_keywords.downcase.split(",").collect(&:strip) |
|
60 | 64 | # keywords used to fix issues |
|
61 | 65 | fix_keywords = Setting.commit_fix_keywords.downcase.split(",").collect(&:strip) |
|
62 | 66 | # status and optional done ratio applied |
|
63 | 67 | fix_status = IssueStatus.find_by_id(Setting.commit_fix_status_id) |
|
64 | 68 | done_ratio = Setting.commit_fix_done_ratio.blank? ? nil : Setting.commit_fix_done_ratio.to_i |
|
65 | 69 | |
|
66 | 70 | kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|") |
|
67 | 71 | return if kw_regexp.blank? |
|
68 | 72 | |
|
69 | 73 | referenced_issues = [] |
|
70 | 74 | |
|
71 | 75 | if ref_keywords.delete('*') |
|
72 | 76 | # find any issue ID in the comments |
|
73 | 77 | target_issue_ids = [] |
|
74 | 78 | comments.scan(%r{([\s\(,-^])#(\d+)(?=[[:punct:]]|\s|<|$)}).each { |m| target_issue_ids << m[1] } |
|
75 | 79 | referenced_issues += repository.project.issues.find_all_by_id(target_issue_ids) |
|
76 | 80 | end |
|
77 | 81 | |
|
78 | 82 | comments.scan(Regexp.new("(#{kw_regexp})[\s:]+(([\s,;&]*#?\\d+)+)", Regexp::IGNORECASE)).each do |match| |
|
79 | 83 | action = match[0] |
|
80 | 84 | target_issue_ids = match[1].scan(/\d+/) |
|
81 | 85 | target_issues = repository.project.issues.find_all_by_id(target_issue_ids) |
|
82 | 86 | if fix_status && fix_keywords.include?(action.downcase) |
|
83 | 87 | # update status of issues |
|
84 | 88 | logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug? |
|
85 | 89 | target_issues.each do |issue| |
|
86 | 90 | # the issue may have been updated by the closure of another one (eg. duplicate) |
|
87 | 91 | issue.reload |
|
88 | 92 | # don't change the status is the issue is closed |
|
89 | 93 | next if issue.status.is_closed? |
|
90 | 94 | user = committer_user || User.anonymous |
|
91 | 95 | csettext = "r#{self.revision}" |
|
92 | 96 | if self.scmid && (! (csettext =~ /^r[0-9]+$/)) |
|
93 | 97 | csettext = "commit:\"#{self.scmid}\"" |
|
94 | 98 | end |
|
95 | 99 | journal = issue.init_journal(user, l(:text_status_changed_by_changeset, csettext)) |
|
96 | 100 | issue.status = fix_status |
|
97 | 101 | issue.done_ratio = done_ratio if done_ratio |
|
98 | 102 | issue.save |
|
99 | 103 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') |
|
100 | 104 | end |
|
101 | 105 | end |
|
102 | 106 | referenced_issues += target_issues |
|
103 | 107 | end |
|
104 | 108 | |
|
105 | 109 | self.issues = referenced_issues.uniq |
|
106 | 110 | end |
|
107 | 111 | |
|
108 | 112 | # Returns the Redmine User corresponding to the committer |
|
109 | 113 | def committer_user |
|
110 | 114 | if committer && committer.strip =~ /^([^<]+)(<(.*)>)?$/ |
|
111 | 115 | username, email = $1.strip, $3 |
|
112 | 116 | u = User.find_by_login(username) |
|
113 | 117 | u ||= User.find_by_mail(email) unless email.blank? |
|
114 | 118 | u |
|
115 | 119 | end |
|
116 | 120 | end |
|
117 | 121 | |
|
118 | 122 | # Returns the previous changeset |
|
119 | 123 | def previous |
|
120 | 124 | @previous ||= Changeset.find(:first, :conditions => ['id < ? AND repository_id = ?', self.id, self.repository_id], :order => 'id DESC') |
|
121 | 125 | end |
|
122 | 126 | |
|
123 | 127 | # Returns the next changeset |
|
124 | 128 | def next |
|
125 | 129 | @next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC') |
|
126 | 130 | end |
|
127 | 131 | end |
@@ -1,62 +1,62 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | |
|
20 | 20 | class ChangesetTest < Test::Unit::TestCase |
|
21 | 21 | fixtures :projects, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :users, :members, :trackers |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | def test_ref_keywords_any |
|
27 | 27 | Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id |
|
28 | 28 | Setting.commit_fix_done_ratio = '90' |
|
29 | 29 | Setting.commit_ref_keywords = '*' |
|
30 | 30 | Setting.commit_fix_keywords = 'fixes , closes' |
|
31 | 31 | |
|
32 | 32 | c = Changeset.new(:repository => Project.find(1).repository, |
|
33 | 33 | :committed_on => Time.now, |
|
34 | 34 | :comments => 'New commit (#2). Fixes #1') |
|
35 | 35 | c.scan_comment_for_issue_ids |
|
36 | 36 | |
|
37 | 37 | assert_equal [1, 2], c.issue_ids.sort |
|
38 | 38 | fixed = Issue.find(1) |
|
39 | 39 | assert fixed.closed? |
|
40 | 40 | assert_equal 90, fixed.done_ratio |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | def test_previous |
|
44 | changeset = Changeset.find_by_revision(3) | |
|
45 | assert_equal Changeset.find_by_revision(2), changeset.previous | |
|
44 | changeset = Changeset.find_by_revision('3') | |
|
45 | assert_equal Changeset.find_by_revision('2'), changeset.previous | |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | def test_previous_nil |
|
49 | changeset = Changeset.find_by_revision(1) | |
|
49 | changeset = Changeset.find_by_revision('1') | |
|
50 | 50 | assert_nil changeset.previous |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def test_next |
|
54 | changeset = Changeset.find_by_revision(2) | |
|
55 | assert_equal Changeset.find_by_revision(3), changeset.next | |
|
54 | changeset = Changeset.find_by_revision('2') | |
|
55 | assert_equal Changeset.find_by_revision('3'), changeset.next | |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | def test_next_nil |
|
59 | changeset = Changeset.find_by_revision(4) | |
|
59 | changeset = Changeset.find_by_revision('4') | |
|
60 | 60 | assert_nil changeset.next |
|
61 | 61 | end |
|
62 | 62 | end |
@@ -1,88 +1,88 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | |
|
20 | 20 | class RepositoryBazaarTest < Test::Unit::TestCase |
|
21 | 21 | fixtures :projects |
|
22 | 22 | |
|
23 | 23 | # No '..' in the repository path |
|
24 | 24 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/bazaar_repository' |
|
25 | 25 | REPOSITORY_PATH.gsub!(/\/+/, '/') |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | @project = Project.find(1) |
|
29 | 29 | assert @repository = Repository::Bazaar.create(:project => @project, :url => "file:///#{REPOSITORY_PATH}") |
|
30 | 30 | end |
|
31 | 31 | |
|
32 | 32 | if File.directory?(REPOSITORY_PATH) |
|
33 | 33 | def test_fetch_changesets_from_scratch |
|
34 | 34 | @repository.fetch_changesets |
|
35 | 35 | @repository.reload |
|
36 | 36 | |
|
37 | 37 | assert_equal 4, @repository.changesets.count |
|
38 | 38 | assert_equal 9, @repository.changes.count |
|
39 | assert_equal 'Initial import', @repository.changesets.find_by_revision(1).comments | |
|
39 | assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments | |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def test_fetch_changesets_incremental |
|
43 | 43 | @repository.fetch_changesets |
|
44 | 44 | # Remove changesets with revision > 5 |
|
45 |
@repository.changesets.find(:all |
|
|
45 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} | |
|
46 | 46 | @repository.reload |
|
47 | 47 | assert_equal 2, @repository.changesets.count |
|
48 | 48 | |
|
49 | 49 | @repository.fetch_changesets |
|
50 | 50 | assert_equal 4, @repository.changesets.count |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def test_entries |
|
54 | 54 | entries = @repository.entries |
|
55 | 55 | assert_equal 2, entries.size |
|
56 | 56 | |
|
57 | 57 | assert_equal 'dir', entries[0].kind |
|
58 | 58 | assert_equal 'directory', entries[0].name |
|
59 | 59 | |
|
60 | 60 | assert_equal 'file', entries[1].kind |
|
61 | 61 | assert_equal 'doc-mkdir.txt', entries[1].name |
|
62 | 62 | end |
|
63 | 63 | |
|
64 | 64 | def test_entries_in_subdirectory |
|
65 | 65 | entries = @repository.entries('directory') |
|
66 | 66 | assert_equal 3, entries.size |
|
67 | 67 | |
|
68 | 68 | assert_equal 'file', entries.last.kind |
|
69 | 69 | assert_equal 'edit.png', entries.last.name |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | 72 | def test_cat |
|
73 | 73 | cat = @repository.scm.cat('directory/document.txt') |
|
74 | 74 | assert cat =~ /Write the contents of a file as of a given revision to standard output/ |
|
75 | 75 | end |
|
76 | 76 | |
|
77 | 77 | def test_annotate |
|
78 | 78 | annotate = @repository.scm.annotate('doc-mkdir.txt') |
|
79 | 79 | assert_equal 17, annotate.lines.size |
|
80 | 80 | assert_equal 1, annotate.revisions[0].identifier |
|
81 | 81 | assert_equal 'jsmith@', annotate.revisions[0].author |
|
82 | 82 | assert_equal 'mkdir', annotate.lines[0] |
|
83 | 83 | end |
|
84 | 84 | else |
|
85 | 85 | puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!" |
|
86 | 86 | def test_fake; assert true end |
|
87 | 87 | end |
|
88 | 88 | end |
@@ -1,55 +1,55 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | |
|
20 | 20 | class RepositoryDarcsTest < Test::Unit::TestCase |
|
21 | 21 | fixtures :projects |
|
22 | 22 | |
|
23 | 23 | # No '..' in the repository path |
|
24 | 24 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/darcs_repository' |
|
25 | 25 | |
|
26 | 26 | def setup |
|
27 | 27 | @project = Project.find(1) |
|
28 | 28 | assert @repository = Repository::Darcs.create(:project => @project, :url => REPOSITORY_PATH) |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | if File.directory?(REPOSITORY_PATH) |
|
32 | 32 | def test_fetch_changesets_from_scratch |
|
33 | 33 | @repository.fetch_changesets |
|
34 | 34 | @repository.reload |
|
35 | 35 | |
|
36 | 36 | assert_equal 6, @repository.changesets.count |
|
37 | 37 | assert_equal 13, @repository.changes.count |
|
38 | assert_equal "Initial commit.", @repository.changesets.find_by_revision(1).comments | |
|
38 | assert_equal "Initial commit.", @repository.changesets.find_by_revision('1').comments | |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def test_fetch_changesets_incremental |
|
42 | 42 | @repository.fetch_changesets |
|
43 | 43 | # Remove changesets with revision > 3 |
|
44 |
@repository.changesets.find(:all |
|
|
44 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3} | |
|
45 | 45 | @repository.reload |
|
46 | 46 | assert_equal 3, @repository.changesets.count |
|
47 | 47 | |
|
48 | 48 | @repository.fetch_changesets |
|
49 | 49 | assert_equal 6, @repository.changesets.count |
|
50 | 50 | end |
|
51 | 51 | else |
|
52 | 52 | puts "Darcs test repository NOT FOUND. Skipping unit tests !!!" |
|
53 | 53 | def test_fake; assert true end |
|
54 | 54 | end |
|
55 | 55 | end |
@@ -1,55 +1,55 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | |
|
20 | 20 | class RepositoryMercurialTest < Test::Unit::TestCase |
|
21 | 21 | fixtures :projects |
|
22 | 22 | |
|
23 | 23 | # No '..' in the repository path |
|
24 | 24 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' |
|
25 | 25 | |
|
26 | 26 | def setup |
|
27 | 27 | @project = Project.find(1) |
|
28 | 28 | assert @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH) |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | if File.directory?(REPOSITORY_PATH) |
|
32 | 32 | def test_fetch_changesets_from_scratch |
|
33 | 33 | @repository.fetch_changesets |
|
34 | 34 | @repository.reload |
|
35 | 35 | |
|
36 | 36 | assert_equal 6, @repository.changesets.count |
|
37 | 37 | assert_equal 11, @repository.changes.count |
|
38 | assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision(0).comments | |
|
38 | assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0').comments | |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def test_fetch_changesets_incremental |
|
42 | 42 | @repository.fetch_changesets |
|
43 | 43 | # Remove changesets with revision > 2 |
|
44 |
@repository.changesets.find(:all |
|
|
44 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} | |
|
45 | 45 | @repository.reload |
|
46 | 46 | assert_equal 3, @repository.changesets.count |
|
47 | 47 | |
|
48 | 48 | @repository.fetch_changesets |
|
49 | 49 | assert_equal 6, @repository.changesets.count |
|
50 | 50 | end |
|
51 | 51 | else |
|
52 | 52 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
53 | 53 | def test_fake; assert true end |
|
54 | 54 | end |
|
55 | 55 | end |
@@ -1,55 +1,55 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | |
|
20 | 20 | class RepositorySubversionTest < Test::Unit::TestCase |
|
21 | 21 | fixtures :projects |
|
22 | 22 | |
|
23 | 23 | # No '..' in the repository path for svn |
|
24 | 24 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/subversion_repository' |
|
25 | 25 | |
|
26 | 26 | def setup |
|
27 | 27 | @project = Project.find(1) |
|
28 | 28 | assert @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{REPOSITORY_PATH}") |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | if File.directory?(REPOSITORY_PATH) |
|
32 | 32 | def test_fetch_changesets_from_scratch |
|
33 | 33 | @repository.fetch_changesets |
|
34 | 34 | @repository.reload |
|
35 | 35 | |
|
36 | 36 | assert_equal 8, @repository.changesets.count |
|
37 | 37 | assert_equal 16, @repository.changes.count |
|
38 | assert_equal 'Initial import.', @repository.changesets.find_by_revision(1).comments | |
|
38 | assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments | |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def test_fetch_changesets_incremental |
|
42 | 42 | @repository.fetch_changesets |
|
43 | 43 | # Remove changesets with revision > 5 |
|
44 |
@repository.changesets.find(:all |
|
|
44 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5} | |
|
45 | 45 | @repository.reload |
|
46 | 46 | assert_equal 5, @repository.changesets.count |
|
47 | 47 | |
|
48 | 48 | @repository.fetch_changesets |
|
49 | 49 | assert_equal 8, @repository.changesets.count |
|
50 | 50 | end |
|
51 | 51 | else |
|
52 | 52 | puts "Subversion test repository NOT FOUND. Skipping unit tests !!!" |
|
53 | 53 | def test_fake; assert true end |
|
54 | 54 | end |
|
55 | 55 | end |
General Comments 0
You need to be logged in to leave comments.
Login now