Mercurial > hg > soundsoftware-site
comparison test/unit/repository_test.rb @ 524:1248a47e81b3 feature_36
Merge from branch "luisf"
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Mon, 25 Jul 2011 14:39:38 +0100 |
parents | cbce1fd3b1b7 |
children | cbb26bc654de |
comparison
equal
deleted
inserted
replaced
519:3be6bc3c2a17 | 524:1248a47e81b3 |
---|---|
1 # redMine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2007 Jean-Philippe Lang | 2 # Copyright (C) 2006-2011 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.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", |
56 :include => :changeset) | |
51 assert_difference 'Changeset.count', -changesets do | 57 assert_difference 'Changeset.count', -changesets do |
52 assert_difference 'Change.count', -changes do | 58 assert_difference 'Change.count', -changes do |
53 Repository.find(10).destroy | 59 Repository.find(10).destroy |
54 end | 60 end |
55 end | 61 end |
56 end | 62 end |
57 | 63 |
58 def test_should_not_create_with_disabled_scm | 64 def test_should_not_create_with_disabled_scm |
59 # disable Subversion | 65 # disable Subversion |
60 Setting.enabled_scm = ['Darcs', 'Git'] | 66 with_settings :enabled_scm => ['Darcs', 'Git'] do |
61 repository = Repository::Subversion.new(:project => Project.find(3), :url => "svn://localhost") | 67 repository = Repository::Subversion.new( |
62 assert !repository.save | 68 :project => Project.find(3), :url => "svn://localhost") |
63 assert_equal I18n.translate('activerecord.errors.messages.invalid'), repository.errors.on(:type) | 69 assert !repository.save |
64 # re-enable Subversion for following tests | 70 assert_equal I18n.translate('activerecord.errors.messages.invalid'), |
65 Setting.delete_all | 71 repository.errors.on(:type) |
66 end | 72 end |
67 | 73 end |
74 | |
68 def test_scan_changesets_for_issue_ids | 75 def test_scan_changesets_for_issue_ids |
69 Setting.default_language = 'en' | 76 Setting.default_language = 'en' |
70 Setting.notified_events = ['issue_added','issue_updated'] | 77 Setting.notified_events = ['issue_added','issue_updated'] |
71 | 78 |
72 # choosing a status to apply to fix issues | 79 # choosing a status to apply to fix issues |
73 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id | 80 Setting.commit_fix_status_id = IssueStatus.find( |
81 :first, | |
82 :conditions => ["is_closed = ?", true]).id | |
74 Setting.commit_fix_done_ratio = "90" | 83 Setting.commit_fix_done_ratio = "90" |
75 Setting.commit_ref_keywords = 'refs , references, IssueID' | 84 Setting.commit_ref_keywords = 'refs , references, IssueID' |
76 Setting.commit_fix_keywords = 'fixes , closes' | 85 Setting.commit_fix_keywords = 'fixes , closes' |
77 Setting.default_language = 'en' | 86 Setting.default_language = 'en' |
78 ActionMailer::Base.deliveries.clear | 87 ActionMailer::Base.deliveries.clear |
79 | 88 |
80 # make sure issue 1 is not already closed | 89 # make sure issue 1 is not already closed |
81 fixed_issue = Issue.find(1) | 90 fixed_issue = Issue.find(1) |
82 assert !fixed_issue.status.is_closed? | 91 assert !fixed_issue.status.is_closed? |
83 old_status = fixed_issue.status | 92 old_status = fixed_issue.status |
84 | 93 |
85 Repository.scan_changesets_for_issue_ids | 94 Repository.scan_changesets_for_issue_ids |
86 assert_equal [101, 102], Issue.find(3).changeset_ids | 95 assert_equal [101, 102], Issue.find(3).changeset_ids |
87 | 96 |
88 # fixed issues | 97 # fixed issues |
89 fixed_issue.reload | 98 fixed_issue.reload |
90 assert fixed_issue.status.is_closed? | 99 assert fixed_issue.status.is_closed? |
91 assert_equal 90, fixed_issue.done_ratio | 100 assert_equal 90, fixed_issue.done_ratio |
92 assert_equal [101], fixed_issue.changeset_ids | 101 assert_equal [101], fixed_issue.changeset_ids |
93 | 102 |
94 # issue change | 103 # issue change |
95 journal = fixed_issue.journals.find(:first, :order => 'created_on desc') | 104 journal = fixed_issue.journals.find(:first, :order => 'created_on desc') |
96 assert_equal User.find_by_login('dlopper'), journal.user | 105 assert_equal User.find_by_login('dlopper'), journal.user |
97 assert_equal 'Applied in changeset r2.', journal.notes | 106 assert_equal 'Applied in changeset r2.', journal.notes |
98 | 107 |
99 # 2 email notifications | 108 # 2 email notifications |
100 assert_equal 2, ActionMailer::Base.deliveries.size | 109 assert_equal 2, ActionMailer::Base.deliveries.size |
101 mail = ActionMailer::Base.deliveries.first | 110 mail = ActionMailer::Base.deliveries.first |
102 assert_kind_of TMail::Mail, mail | 111 assert_kind_of TMail::Mail, mail |
103 assert mail.subject.starts_with?("[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]") | 112 assert mail.subject.starts_with?( |
104 assert mail.body.include?("Status changed from #{old_status} to #{fixed_issue.status}") | 113 "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]") |
105 | 114 assert mail.body.include?( |
115 "Status changed from #{old_status} to #{fixed_issue.status}") | |
116 | |
106 # ignoring commits referencing an issue of another project | 117 # ignoring commits referencing an issue of another project |
107 assert_equal [], Issue.find(4).changesets | 118 assert_equal [], Issue.find(4).changesets |
108 end | 119 end |
109 | 120 |
110 def test_for_changeset_comments_strip | 121 def test_for_changeset_comments_strip |
111 repository = Repository::Mercurial.create( :project => Project.find( 4 ), :url => '/foo/bar/baz' ) | 122 repository = Repository::Mercurial.create( |
123 :project => Project.find( 4 ), | |
124 :url => '/foo/bar/baz' ) | |
112 comment = <<-COMMENT | 125 comment = <<-COMMENT |
113 This is a loooooooooooooooooooooooooooong comment | 126 This is a loooooooooooooooooooooooooooong comment |
114 | 127 |
115 | 128 |
116 COMMENT | 129 COMMENT |
117 changeset = Changeset.new( | 130 changeset = Changeset.new( |
118 :comments => comment, :commit_date => Time.now, :revision => 0, :scmid => 'f39b7922fb3c', | 131 :comments => comment, :commit_date => Time.now, |
119 :committer => 'foo <foo@example.com>', :committed_on => Time.now, :repository => repository ) | 132 :revision => 0, :scmid => 'f39b7922fb3c', |
133 :committer => 'foo <foo@example.com>', | |
134 :committed_on => Time.now, :repository => repository ) | |
120 assert( changeset.save ) | 135 assert( changeset.save ) |
121 assert_not_equal( comment, changeset.comments ) | 136 assert_not_equal( comment, changeset.comments ) |
122 assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments ) | 137 assert_equal( 'This is a loooooooooooooooooooooooooooong comment', |
123 end | 138 changeset.comments ) |
124 | 139 end |
140 | |
125 def test_for_urls_strip | 141 def test_for_urls_strip |
126 repository = Repository::Cvs.create(:project => Project.find(4), :url => ' :pserver:login:password@host:/path/to/the/repository', | 142 repository = Repository::Cvs.create( |
127 :root_url => 'foo ') | 143 :project => Project.find(4), |
144 :url => ' :pserver:login:password@host:/path/to/the/repository', | |
145 :root_url => 'foo ', | |
146 :log_encoding => 'UTF-8') | |
128 assert repository.save | 147 assert repository.save |
129 repository.reload | 148 repository.reload |
130 assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url | 149 assert_equal ':pserver:login:password@host:/path/to/the/repository', |
150 repository.url | |
131 assert_equal 'foo', repository.root_url | 151 assert_equal 'foo', repository.root_url |
132 end | 152 end |
133 | 153 |
134 def test_manual_user_mapping | 154 def test_manual_user_mapping |
135 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do | 155 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.') | 156 c = Changeset.create!( |
157 :repository => @repository, | |
158 :committer => 'foo', | |
159 :committed_on => Time.now, | |
160 :revision => 100, | |
161 :comments => 'Committed by foo.' | |
162 ) | |
137 assert_nil c.user | 163 assert_nil c.user |
138 @repository.committer_ids = {'foo' => '2'} | 164 @repository.committer_ids = {'foo' => '2'} |
139 assert_equal User.find(2), c.reload.user | 165 assert_equal User.find(2), c.reload.user |
140 # committer is now mapped | 166 # committer is now mapped |
141 c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 101, :comments => 'Another commit by foo.') | 167 c = Changeset.create!( |
168 :repository => @repository, | |
169 :committer => 'foo', | |
170 :committed_on => Time.now, | |
171 :revision => 101, | |
172 :comments => 'Another commit by foo.' | |
173 ) | |
142 assert_equal User.find(2), c.user | 174 assert_equal User.find(2), c.user |
143 end | 175 end |
144 end | 176 end |
145 | 177 |
146 def test_auto_user_mapping_by_username | 178 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.') | 179 c = Changeset.create!( |
180 :repository => @repository, | |
181 :committer => 'jsmith', | |
182 :committed_on => Time.now, | |
183 :revision => 100, | |
184 :comments => 'Committed by john.' | |
185 ) | |
148 assert_equal User.find(2), c.user | 186 assert_equal User.find(2), c.user |
149 end | 187 end |
150 | 188 |
151 def test_auto_user_mapping_by_email | 189 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.') | 190 c = Changeset.create!( |
191 :repository => @repository, | |
192 :committer => 'john <jsmith@somenet.foo>', | |
193 :committed_on => Time.now, | |
194 :revision => 100, | |
195 :comments => 'Committed by john.' | |
196 ) | |
153 assert_equal User.find(2), c.user | 197 assert_equal User.find(2), c.user |
154 end | 198 end |
199 | |
200 def test_filesystem_avaialbe | |
201 klass = Repository::Filesystem | |
202 assert klass.scm_adapter_class | |
203 assert_equal true, klass.scm_available | |
204 end | |
205 | |
206 def test_merge_extra_info | |
207 repo = Repository::Subversion.new(:project => Project.find(3)) | |
208 assert !repo.save | |
209 repo.url = "svn://localhost" | |
210 assert repo.save | |
211 repo.reload | |
212 project = Project.find(3) | |
213 assert_equal repo, project.repository | |
214 assert_nil repo.extra_info | |
215 h1 = {"test_1" => {"test_11" => "test_value_11"}} | |
216 repo.merge_extra_info(h1) | |
217 assert_equal h1, repo.extra_info | |
218 h2 = {"test_2" => { | |
219 "test_21" => "test_value_21", | |
220 "test_22" => "test_value_22", | |
221 }} | |
222 repo.merge_extra_info(h2) | |
223 assert_equal (h = {"test_11" => "test_value_11"}), | |
224 repo.extra_info["test_1"] | |
225 assert_equal "test_value_21", | |
226 repo.extra_info["test_2"]["test_21"] | |
227 h3 = {"test_2" => { | |
228 "test_23" => "test_value_23", | |
229 "test_24" => "test_value_24", | |
230 }} | |
231 repo.merge_extra_info(h3) | |
232 assert_equal (h = {"test_11" => "test_value_11"}), | |
233 repo.extra_info["test_1"] | |
234 assert_nil repo.extra_info["test_2"]["test_21"] | |
235 assert_equal "test_value_23", | |
236 repo.extra_info["test_2"]["test_23"] | |
237 end | |
155 end | 238 end |