@@ -1,155 +1,160 | |||||
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.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class RepositoryTest < ActiveSupport::TestCase |
|
20 | class RepositoryTest < ActiveSupport::TestCase | |
21 | fixtures :projects, |
|
21 | fixtures :projects, | |
22 | :trackers, |
|
22 | :trackers, | |
23 | :projects_trackers, |
|
23 | :projects_trackers, | |
|
24 | :enabled_modules, | |||
24 | :repositories, |
|
25 | :repositories, | |
25 | :issues, |
|
26 | :issues, | |
26 | :issue_statuses, |
|
27 | :issue_statuses, | |
|
28 | :issue_categories, | |||
27 | :changesets, |
|
29 | :changesets, | |
28 | :changes, |
|
30 | :changes, | |
29 | :users, |
|
31 | :users, | |
|
32 | :members, | |||
|
33 | :member_roles, | |||
|
34 | :roles, | |||
30 | :enumerations |
|
35 | :enumerations | |
31 |
|
36 | |||
32 | def setup |
|
37 | def setup | |
33 | @repository = Project.find(1).repository |
|
38 | @repository = Project.find(1).repository | |
34 | end |
|
39 | end | |
35 |
|
40 | |||
36 | def test_create |
|
41 | def test_create | |
37 | repository = Repository::Subversion.new(:project => Project.find(3)) |
|
42 | repository = Repository::Subversion.new(:project => Project.find(3)) | |
38 | assert !repository.save |
|
43 | assert !repository.save | |
39 |
|
44 | |||
40 | repository.url = "svn://localhost" |
|
45 | repository.url = "svn://localhost" | |
41 | assert repository.save |
|
46 | assert repository.save | |
42 | repository.reload |
|
47 | repository.reload | |
43 |
|
48 | |||
44 | project = Project.find(3) |
|
49 | project = Project.find(3) | |
45 | assert_equal repository, project.repository |
|
50 | assert_equal repository, project.repository | |
46 | end |
|
51 | end | |
47 |
|
52 | |||
48 | def test_destroy |
|
53 | def test_destroy | |
49 | changesets = Changeset.count(:all, :conditions => "repository_id = 10") |
|
54 | changesets = Changeset.count(:all, :conditions => "repository_id = 10") | |
50 | changes = Change.count(:all, :conditions => "repository_id = 10", :include => :changeset) |
|
55 | changes = Change.count(:all, :conditions => "repository_id = 10", :include => :changeset) | |
51 | assert_difference 'Changeset.count', -changesets do |
|
56 | assert_difference 'Changeset.count', -changesets do | |
52 | assert_difference 'Change.count', -changes do |
|
57 | assert_difference 'Change.count', -changes do | |
53 | Repository.find(10).destroy |
|
58 | Repository.find(10).destroy | |
54 | end |
|
59 | end | |
55 | end |
|
60 | end | |
56 | end |
|
61 | end | |
57 |
|
62 | |||
58 | def test_should_not_create_with_disabled_scm |
|
63 | def test_should_not_create_with_disabled_scm | |
59 | # disable Subversion |
|
64 | # disable Subversion | |
60 | Setting.enabled_scm = ['Darcs', 'Git'] |
|
65 | Setting.enabled_scm = ['Darcs', 'Git'] | |
61 | repository = Repository::Subversion.new(:project => Project.find(3), :url => "svn://localhost") |
|
66 | repository = Repository::Subversion.new(:project => Project.find(3), :url => "svn://localhost") | |
62 | assert !repository.save |
|
67 | assert !repository.save | |
63 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), repository.errors.on(:type) |
|
68 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), repository.errors.on(:type) | |
64 | # re-enable Subversion for following tests |
|
69 | # re-enable Subversion for following tests | |
65 | Setting.delete_all |
|
70 | Setting.delete_all | |
66 | end |
|
71 | end | |
67 |
|
72 | |||
68 | def test_scan_changesets_for_issue_ids |
|
73 | def test_scan_changesets_for_issue_ids | |
69 | Setting.default_language = 'en' |
|
74 | Setting.default_language = 'en' | |
70 | Setting.notified_events = ['issue_added','issue_updated'] |
|
75 | Setting.notified_events = ['issue_added','issue_updated'] | |
71 |
|
76 | |||
72 | # choosing a status to apply to fix issues |
|
77 | # choosing a status to apply to fix issues | |
73 | Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id |
|
78 | Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id | |
74 | Setting.commit_fix_done_ratio = "90" |
|
79 | Setting.commit_fix_done_ratio = "90" | |
75 | Setting.commit_ref_keywords = 'refs , references, IssueID' |
|
80 | Setting.commit_ref_keywords = 'refs , references, IssueID' | |
76 | Setting.commit_fix_keywords = 'fixes , closes' |
|
81 | Setting.commit_fix_keywords = 'fixes , closes' | |
77 | Setting.default_language = 'en' |
|
82 | Setting.default_language = 'en' | |
78 | ActionMailer::Base.deliveries.clear |
|
83 | ActionMailer::Base.deliveries.clear | |
79 |
|
84 | |||
80 | # make sure issue 1 is not already closed |
|
85 | # make sure issue 1 is not already closed | |
81 | fixed_issue = Issue.find(1) |
|
86 | fixed_issue = Issue.find(1) | |
82 | assert !fixed_issue.status.is_closed? |
|
87 | assert !fixed_issue.status.is_closed? | |
83 | old_status = fixed_issue.status |
|
88 | old_status = fixed_issue.status | |
84 |
|
89 | |||
85 | Repository.scan_changesets_for_issue_ids |
|
90 | Repository.scan_changesets_for_issue_ids | |
86 | assert_equal [101, 102], Issue.find(3).changeset_ids |
|
91 | assert_equal [101, 102], Issue.find(3).changeset_ids | |
87 |
|
92 | |||
88 | # fixed issues |
|
93 | # fixed issues | |
89 | fixed_issue.reload |
|
94 | fixed_issue.reload | |
90 | assert fixed_issue.status.is_closed? |
|
95 | assert fixed_issue.status.is_closed? | |
91 | assert_equal 90, fixed_issue.done_ratio |
|
96 | assert_equal 90, fixed_issue.done_ratio | |
92 | assert_equal [101], fixed_issue.changeset_ids |
|
97 | assert_equal [101], fixed_issue.changeset_ids | |
93 |
|
98 | |||
94 | # issue change |
|
99 | # issue change | |
95 | journal = fixed_issue.journals.find(:first, :order => 'created_on desc') |
|
100 | journal = fixed_issue.journals.find(:first, :order => 'created_on desc') | |
96 | assert_equal User.find_by_login('dlopper'), journal.user |
|
101 | assert_equal User.find_by_login('dlopper'), journal.user | |
97 | assert_equal 'Applied in changeset r2.', journal.notes |
|
102 | assert_equal 'Applied in changeset r2.', journal.notes | |
98 |
|
103 | |||
99 | # 2 email notifications |
|
104 | # 2 email notifications | |
100 | assert_equal 2, ActionMailer::Base.deliveries.size |
|
105 | assert_equal 2, ActionMailer::Base.deliveries.size | |
101 | mail = ActionMailer::Base.deliveries.first |
|
106 | mail = ActionMailer::Base.deliveries.first | |
102 | assert_kind_of TMail::Mail, mail |
|
107 | assert_kind_of TMail::Mail, mail | |
103 | assert mail.subject.starts_with?("[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]") |
|
108 | assert mail.subject.starts_with?("[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]") | |
104 | assert mail.body.include?("Status changed from #{old_status} to #{fixed_issue.status}") |
|
109 | assert mail.body.include?("Status changed from #{old_status} to #{fixed_issue.status}") | |
105 |
|
110 | |||
106 | # ignoring commits referencing an issue of another project |
|
111 | # ignoring commits referencing an issue of another project | |
107 | assert_equal [], Issue.find(4).changesets |
|
112 | assert_equal [], Issue.find(4).changesets | |
108 | end |
|
113 | end | |
109 |
|
114 | |||
110 | def test_for_changeset_comments_strip |
|
115 | def test_for_changeset_comments_strip | |
111 | repository = Repository::Mercurial.create( :project => Project.find( 4 ), :url => '/foo/bar/baz' ) |
|
116 | repository = Repository::Mercurial.create( :project => Project.find( 4 ), :url => '/foo/bar/baz' ) | |
112 | comment = <<-COMMENT |
|
117 | comment = <<-COMMENT | |
113 | This is a loooooooooooooooooooooooooooong comment |
|
118 | This is a loooooooooooooooooooooooooooong comment | |
114 |
|
119 | |||
115 |
|
120 | |||
116 | COMMENT |
|
121 | COMMENT | |
117 | changeset = Changeset.new( |
|
122 | changeset = Changeset.new( | |
118 | :comments => comment, :commit_date => Time.now, :revision => 0, :scmid => 'f39b7922fb3c', |
|
123 | :comments => comment, :commit_date => Time.now, :revision => 0, :scmid => 'f39b7922fb3c', | |
119 | :committer => 'foo <foo@example.com>', :committed_on => Time.now, :repository => repository ) |
|
124 | :committer => 'foo <foo@example.com>', :committed_on => Time.now, :repository => repository ) | |
120 | assert( changeset.save ) |
|
125 | assert( changeset.save ) | |
121 | assert_not_equal( comment, changeset.comments ) |
|
126 | assert_not_equal( comment, changeset.comments ) | |
122 | assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments ) |
|
127 | assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments ) | |
123 | end |
|
128 | end | |
124 |
|
129 | |||
125 | def test_for_urls_strip |
|
130 | def test_for_urls_strip | |
126 | repository = Repository::Cvs.create(:project => Project.find(4), :url => ' :pserver:login:password@host:/path/to/the/repository', |
|
131 | repository = Repository::Cvs.create(:project => Project.find(4), :url => ' :pserver:login:password@host:/path/to/the/repository', | |
127 | :root_url => 'foo ') |
|
132 | :root_url => 'foo ') | |
128 | assert repository.save |
|
133 | assert repository.save | |
129 | repository.reload |
|
134 | repository.reload | |
130 | assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url |
|
135 | assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url | |
131 | assert_equal 'foo', repository.root_url |
|
136 | assert_equal 'foo', repository.root_url | |
132 | end |
|
137 | end | |
133 |
|
138 | |||
134 | def test_manual_user_mapping |
|
139 | def test_manual_user_mapping | |
135 | assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do |
|
140 | assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do | |
136 | c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.') |
|
141 | c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.') | |
137 | assert_nil c.user |
|
142 | assert_nil c.user | |
138 | @repository.committer_ids = {'foo' => '2'} |
|
143 | @repository.committer_ids = {'foo' => '2'} | |
139 | assert_equal User.find(2), c.reload.user |
|
144 | assert_equal User.find(2), c.reload.user | |
140 | # committer is now mapped |
|
145 | # committer is now mapped | |
141 | c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 101, :comments => 'Another commit by foo.') |
|
146 | c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 101, :comments => 'Another commit by foo.') | |
142 | assert_equal User.find(2), c.user |
|
147 | assert_equal User.find(2), c.user | |
143 | end |
|
148 | end | |
144 | end |
|
149 | end | |
145 |
|
150 | |||
146 | def test_auto_user_mapping_by_username |
|
151 | def test_auto_user_mapping_by_username | |
147 | c = Changeset.create!(:repository => @repository, :committer => 'jsmith', :committed_on => Time.now, :revision => 100, :comments => 'Committed by john.') |
|
152 | c = Changeset.create!(:repository => @repository, :committer => 'jsmith', :committed_on => Time.now, :revision => 100, :comments => 'Committed by john.') | |
148 | assert_equal User.find(2), c.user |
|
153 | assert_equal User.find(2), c.user | |
149 | end |
|
154 | end | |
150 |
|
155 | |||
151 | def test_auto_user_mapping_by_email |
|
156 | def test_auto_user_mapping_by_email | |
152 | c = Changeset.create!(:repository => @repository, :committer => 'john <jsmith@somenet.foo>', :committed_on => Time.now, :revision => 100, :comments => 'Committed by john.') |
|
157 | c = Changeset.create!(:repository => @repository, :committer => 'john <jsmith@somenet.foo>', :committed_on => Time.now, :revision => 100, :comments => 'Committed by john.') | |
153 | assert_equal User.find(2), c.user |
|
158 | assert_equal User.find(2), c.user | |
154 | end |
|
159 | end | |
155 | end |
|
160 | end |
General Comments 0
You need to be logged in to leave comments.
Login now