comparison test/unit/changeset_test.rb @ 1464:261b3d9a4903 redmine-2.4

Update to Redmine 2.4 branch rev 12663
author Chris Cannam
date Tue, 14 Jan 2014 14:37:42 +0000
parents 433d4f72a19b
children e248c7af89ec
comparison
equal deleted inserted replaced
1296:038ba2d95de8 1464:261b3d9a4903
1 # encoding: utf-8 1 # encoding: utf-8
2 # 2 #
3 # Redmine - project management software 3 # Redmine - project management software
4 # Copyright (C) 2006-2012 Jean-Philippe Lang 4 # Copyright (C) 2006-2013 Jean-Philippe Lang
5 # 5 #
6 # This program is free software; you can redistribute it and/or 6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License 7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2 8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version. 9 # of the License, or (at your option) any later version.
28 :users, :members, :member_roles, :trackers, 28 :users, :members, :member_roles, :trackers,
29 :enabled_modules, :roles 29 :enabled_modules, :roles
30 30
31 def test_ref_keywords_any 31 def test_ref_keywords_any
32 ActionMailer::Base.deliveries.clear 32 ActionMailer::Base.deliveries.clear
33 Setting.commit_fix_status_id = IssueStatus.find( 33 Setting.commit_ref_keywords = '*'
34 :first, :conditions => ["is_closed = ?", true]).id 34 Setting.commit_update_keywords = [{'keywords' => 'fixes , closes', 'status_id' => '5', 'done_ratio' => '90'}]
35 Setting.commit_fix_done_ratio = '90'
36 Setting.commit_ref_keywords = '*'
37 Setting.commit_fix_keywords = 'fixes , closes'
38 35
39 c = Changeset.new(:repository => Project.find(1).repository, 36 c = Changeset.new(:repository => Project.find(1).repository,
40 :committed_on => Time.now, 37 :committed_on => Time.now,
41 :comments => 'New commit (#2). Fixes #1', 38 :comments => 'New commit (#2). Fixes #1',
42 :revision => '12345') 39 :revision => '12345')
48 assert_equal 1, ActionMailer::Base.deliveries.size 45 assert_equal 1, ActionMailer::Base.deliveries.size
49 end 46 end
50 47
51 def test_ref_keywords 48 def test_ref_keywords
52 Setting.commit_ref_keywords = 'refs' 49 Setting.commit_ref_keywords = 'refs'
53 Setting.commit_fix_keywords = '' 50 Setting.commit_update_keywords = ''
54 c = Changeset.new(:repository => Project.find(1).repository, 51 c = Changeset.new(:repository => Project.find(1).repository,
55 :committed_on => Time.now, 52 :committed_on => Time.now,
56 :comments => 'Ignores #2. Refs #1', 53 :comments => 'Ignores #2. Refs #1',
57 :revision => '12345') 54 :revision => '12345')
58 assert c.save 55 assert c.save
59 assert_equal [1], c.issue_ids.sort 56 assert_equal [1], c.issue_ids.sort
60 end 57 end
61 58
62 def test_ref_keywords_any_only 59 def test_ref_keywords_any_only
63 Setting.commit_ref_keywords = '*' 60 Setting.commit_ref_keywords = '*'
64 Setting.commit_fix_keywords = '' 61 Setting.commit_update_keywords = ''
65 c = Changeset.new(:repository => Project.find(1).repository, 62 c = Changeset.new(:repository => Project.find(1).repository,
66 :committed_on => Time.now, 63 :committed_on => Time.now,
67 :comments => 'Ignores #2. Refs #1', 64 :comments => 'Ignores #2. Refs #1',
68 :revision => '12345') 65 :revision => '12345')
69 assert c.save 66 assert c.save
111 "r520 was expected in time_entry comments: #{time.comments}" 108 "r520 was expected in time_entry comments: #{time.comments}"
112 end 109 end
113 end 110 end
114 111
115 def test_ref_keywords_closing_with_timelog 112 def test_ref_keywords_closing_with_timelog
116 Setting.commit_fix_status_id = IssueStatus.find( 113 Setting.commit_ref_keywords = '*'
117 :first, :conditions => ["is_closed = ?", true]).id 114 Setting.commit_update_keywords = [{'keywords' => 'fixes , closes', 'status_id' => IssueStatus.where(:is_closed => true).first.id.to_s}]
118 Setting.commit_ref_keywords = '*'
119 Setting.commit_fix_keywords = 'fixes , closes'
120 Setting.commit_logtime_enabled = '1' 115 Setting.commit_logtime_enabled = '1'
121 116
122 c = Changeset.new(:repository => Project.find(1).repository, 117 c = Changeset.new(:repository => Project.find(1).repository,
123 :committed_on => Time.now, 118 :committed_on => Time.now,
124 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1', 119 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
163 :revision => '12345') 158 :revision => '12345')
164 assert c.save 159 assert c.save
165 assert_equal [1,2,3], c.issue_ids.sort 160 assert_equal [1,2,3], c.issue_ids.sort
166 end 161 end
167 162
163 def test_update_keywords_with_multiple_rules
164 with_settings :commit_update_keywords => [
165 {'keywords' => 'fixes, closes', 'status_id' => '5'},
166 {'keywords' => 'resolves', 'status_id' => '3'}
167 ] do
168
169 issue1 = Issue.generate!
170 issue2 = Issue.generate!
171 Changeset.generate!(:comments => "Closes ##{issue1.id}\nResolves ##{issue2.id}")
172 assert_equal 5, issue1.reload.status_id
173 assert_equal 3, issue2.reload.status_id
174 end
175 end
176
177 def test_update_keywords_with_multiple_rules_should_match_tracker
178 with_settings :commit_update_keywords => [
179 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
180 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => ''}
181 ] do
182
183 issue1 = Issue.generate!(:tracker_id => 2)
184 issue2 = Issue.generate!
185 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
186 assert_equal 5, issue1.reload.status_id
187 assert_equal 3, issue2.reload.status_id
188 end
189 end
190
191 def test_update_keywords_with_multiple_rules_and_no_match
192 with_settings :commit_update_keywords => [
193 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
194 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => '3'}
195 ] do
196
197 issue1 = Issue.generate!(:tracker_id => 2)
198 issue2 = Issue.generate!
199 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
200 assert_equal 5, issue1.reload.status_id
201 assert_equal 1, issue2.reload.status_id # no updates
202 end
203 end
204
168 def test_commit_referencing_a_subproject_issue 205 def test_commit_referencing_a_subproject_issue
169 c = Changeset.new(:repository => Project.find(1).repository, 206 c = Changeset.new(:repository => Project.find(1).repository,
170 :committed_on => Time.now, 207 :committed_on => Time.now,
171 :comments => 'refs #5, a subproject issue', 208 :comments => 'refs #5, a subproject issue',
172 :revision => '12345') 209 :revision => '12345')
174 assert_equal [5], c.issue_ids.sort 211 assert_equal [5], c.issue_ids.sort
175 assert c.issues.first.project != c.project 212 assert c.issues.first.project != c.project
176 end 213 end
177 214
178 def test_commit_closing_a_subproject_issue 215 def test_commit_closing_a_subproject_issue
179 with_settings :commit_fix_status_id => 5, :commit_fix_keywords => 'closes', 216 with_settings :commit_update_keywords => [{'keywords' => 'closes', 'status_id' => '5'}],
180 :default_language => 'en' do 217 :default_language => 'en' do
181 issue = Issue.find(5) 218 issue = Issue.find(5)
182 assert !issue.closed? 219 assert !issue.closed?
183 assert_difference 'Journal.count' do 220 assert_difference 'Journal.count' do
184 c = Changeset.new(:repository => Project.find(1).repository, 221 c = Changeset.new(:repository => Project.find(1).repository,
234 :comments => 'refs #4, an issue of a different project', 271 :comments => 'refs #4, an issue of a different project',
235 :revision => '12345') 272 :revision => '12345')
236 assert c.save 273 assert c.save
237 assert_equal [4], c.issue_ids 274 assert_equal [4], c.issue_ids
238 end 275 end
276 end
277
278 def test_old_commits_should_not_update_issues_nor_log_time
279 Setting.commit_ref_keywords = '*'
280 Setting.commit_update_keywords = {'fixes , closes' => {'status_id' => '5', 'done_ratio' => '90'}}
281 Setting.commit_logtime_enabled = '1'
282
283 repository = Project.find(1).repository
284 repository.created_on = Time.now
285 repository.save!
286
287 c = Changeset.new(:repository => repository,
288 :committed_on => 1.month.ago,
289 :comments => 'New commit (#2). Fixes #1 @1h',
290 :revision => '12345')
291 assert_no_difference 'TimeEntry.count' do
292 assert c.save
293 end
294 assert_equal [1, 2], c.issue_ids.sort
295 issue = Issue.find(1)
296 assert_equal 1, issue.status_id
297 assert_equal 0, issue.done_ratio
239 end 298 end
240 299
241 def test_text_tag_revision 300 def test_text_tag_revision
242 c = Changeset.new(:revision => '520') 301 c = Changeset.new(:revision => '520')
243 assert_equal 'r520', c.text_tag 302 assert_equal 'r520', c.text_tag