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