##// END OF EJS Templates
scm: code clean up test/unit/changeset_test.rb....
Toshi MARUYAMA -
r5246:1ef54041da9c
parent child
Show More
@@ -1,294 +1,299
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2010 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 require File.expand_path('../../test_helper', __FILE__)
21 21
22 22 class ChangesetTest < ActiveSupport::TestCase
23 fixtures :projects, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :users, :members, :member_roles, :trackers
23 fixtures :projects, :repositories, :issues, :issue_statuses,
24 :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :users, :members, :member_roles, :trackers
24 25
25 26 def setup
26 27 end
27 28
28 29 def test_ref_keywords_any
29 30 ActionMailer::Base.deliveries.clear
30 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
31 Setting.commit_fix_status_id = IssueStatus.find(
32 :first, :conditions => ["is_closed = ?", true]).id
31 33 Setting.commit_fix_done_ratio = '90'
32 34 Setting.commit_ref_keywords = '*'
33 35 Setting.commit_fix_keywords = 'fixes , closes'
34 36
35 37 c = Changeset.new(:repository => Project.find(1).repository,
36 38 :committed_on => Time.now,
37 39 :comments => 'New commit (#2). Fixes #1')
38 40 c.scan_comment_for_issue_ids
39 41
40 42 assert_equal [1, 2], c.issue_ids.sort
41 43 fixed = Issue.find(1)
42 44 assert fixed.closed?
43 45 assert_equal 90, fixed.done_ratio
44 46 assert_equal 1, ActionMailer::Base.deliveries.size
45 47 end
46 48
47 49 def test_ref_keywords
48 50 Setting.commit_ref_keywords = 'refs'
49 51 Setting.commit_fix_keywords = ''
50 52
51 53 c = Changeset.new(:repository => Project.find(1).repository,
52 54 :committed_on => Time.now,
53 55 :comments => 'Ignores #2. Refs #1')
54 56 c.scan_comment_for_issue_ids
55 57
56 58 assert_equal [1], c.issue_ids.sort
57 59 end
58 60
59 61 def test_ref_keywords_any_only
60 62 Setting.commit_ref_keywords = '*'
61 63 Setting.commit_fix_keywords = ''
62 64
63 65 c = Changeset.new(:repository => Project.find(1).repository,
64 66 :committed_on => Time.now,
65 67 :comments => 'Ignores #2. Refs #1')
66 68 c.scan_comment_for_issue_ids
67 69
68 70 assert_equal [1, 2], c.issue_ids.sort
69 71 end
70 72
71 73 def test_ref_keywords_any_with_timelog
72 74 Setting.commit_ref_keywords = '*'
73 75 Setting.commit_logtime_enabled = '1'
74 76
75 77 {
76 78 '2' => 2.0,
77 79 '2h' => 2.0,
78 80 '2hours' => 2.0,
79 81 '15m' => 0.25,
80 82 '15min' => 0.25,
81 83 '3h15' => 3.25,
82 84 '3h15m' => 3.25,
83 85 '3h15min' => 3.25,
84 86 '3:15' => 3.25,
85 87 '3.25' => 3.25,
86 88 '3.25h' => 3.25,
87 89 '3,25' => 3.25,
88 90 '3,25h' => 3.25,
89 91 }.each do |syntax, expected_hours|
90 92 c = Changeset.new(:repository => Project.find(1).repository,
91 93 :committed_on => 24.hours.ago,
92 94 :comments => "Worked on this issue #1 @#{syntax}",
93 95 :revision => '520',
94 96 :user => User.find(2))
95 97 assert_difference 'TimeEntry.count' do
96 98 c.scan_comment_for_issue_ids
97 99 end
98 100 assert_equal [1], c.issue_ids.sort
99 101
100 102 time = TimeEntry.first(:order => 'id desc')
101 103 assert_equal 1, time.issue_id
102 104 assert_equal 1, time.project_id
103 105 assert_equal 2, time.user_id
104 assert_equal expected_hours, time.hours, "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
106 assert_equal expected_hours, time.hours,
107 "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
105 108 assert_equal Date.yesterday, time.spent_on
106 109 assert time.activity.is_default?
107 assert time.comments.include?('r520'), "r520 was expected in time_entry comments: #{time.comments}"
110 assert time.comments.include?('r520'),
111 "r520 was expected in time_entry comments: #{time.comments}"
108 112 end
109 113 end
110 114
111 115 def test_ref_keywords_closing_with_timelog
112 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
116 Setting.commit_fix_status_id = IssueStatus.find(
117 :first, :conditions => ["is_closed = ?", true]).id
113 118 Setting.commit_ref_keywords = '*'
114 119 Setting.commit_fix_keywords = 'fixes , closes'
115 120 Setting.commit_logtime_enabled = '1'
116 121
117 122 c = Changeset.new(:repository => Project.find(1).repository,
118 123 :committed_on => Time.now,
119 124 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
120 125 :user => User.find(2))
121 126 assert_difference 'TimeEntry.count', 2 do
122 127 c.scan_comment_for_issue_ids
123 128 end
124 129
125 130 assert_equal [1, 2], c.issue_ids.sort
126 131 assert Issue.find(1).closed?
127 132 assert Issue.find(2).closed?
128 133
129 134 times = TimeEntry.all(:order => 'id desc', :limit => 2)
130 135 assert_equal [1, 2], times.collect(&:issue_id).sort
131 136 end
132 137
133 138 def test_ref_keywords_any_line_start
134 139 Setting.commit_ref_keywords = '*'
135 140
136 141 c = Changeset.new(:repository => Project.find(1).repository,
137 142 :committed_on => Time.now,
138 143 :comments => '#1 is the reason of this commit')
139 144 c.scan_comment_for_issue_ids
140 145
141 146 assert_equal [1], c.issue_ids.sort
142 147 end
143 148
144 149 def test_ref_keywords_allow_brackets_around_a_issue_number
145 150 Setting.commit_ref_keywords = '*'
146 151
147 152 c = Changeset.new(:repository => Project.find(1).repository,
148 153 :committed_on => Time.now,
149 154 :comments => '[#1] Worked on this issue')
150 155 c.scan_comment_for_issue_ids
151 156
152 157 assert_equal [1], c.issue_ids.sort
153 158 end
154 159
155 160 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
156 161 Setting.commit_ref_keywords = '*'
157 162
158 163 c = Changeset.new(:repository => Project.find(1).repository,
159 164 :committed_on => Time.now,
160 165 :comments => '[#1 #2, #3] Worked on these')
161 166 c.scan_comment_for_issue_ids
162 167
163 168 assert_equal [1,2,3], c.issue_ids.sort
164 169 end
165 170
166 171 def test_commit_referencing_a_subproject_issue
167 172 c = Changeset.new(:repository => Project.find(1).repository,
168 173 :committed_on => Time.now,
169 174 :comments => 'refs #5, a subproject issue')
170 175 c.scan_comment_for_issue_ids
171 176
172 177 assert_equal [5], c.issue_ids.sort
173 178 assert c.issues.first.project != c.project
174 179 end
175 180
176 181 def test_commit_referencing_a_parent_project_issue
177 182 # repository of child project
178 183 r = Repository::Subversion.create!(
179 184 :project => Project.find(3),
180 185 :url => 'svn://localhost/test')
181 186
182 187 c = Changeset.new(:repository => r,
183 188 :committed_on => Time.now,
184 189 :comments => 'refs #2, an issue of a parent project')
185 190 c.scan_comment_for_issue_ids
186 191
187 192 assert_equal [2], c.issue_ids.sort
188 193 assert c.issues.first.project != c.project
189 194 end
190 195
191 196 def test_text_tag_revision
192 197 c = Changeset.new(:revision => '520')
193 198 assert_equal 'r520', c.text_tag
194 199 end
195 200
196 201 def test_text_tag_hash
197 202 c = Changeset.new(
198 203 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
199 204 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
200 205 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
201 206 end
202 207
203 208 def test_text_tag_hash_all_number
204 209 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
205 210 assert_equal 'commit:0123456789', c.text_tag
206 211 end
207 212
208 213 def test_previous
209 214 changeset = Changeset.find_by_revision('3')
210 215 assert_equal Changeset.find_by_revision('2'), changeset.previous
211 216 end
212 217
213 218 def test_previous_nil
214 219 changeset = Changeset.find_by_revision('1')
215 220 assert_nil changeset.previous
216 221 end
217 222
218 223 def test_next
219 224 changeset = Changeset.find_by_revision('2')
220 225 assert_equal Changeset.find_by_revision('3'), changeset.next
221 226 end
222 227
223 228 def test_next_nil
224 229 changeset = Changeset.find_by_revision('10')
225 230 assert_nil changeset.next
226 231 end
227 232
228 233 def test_comments_should_be_converted_to_utf8
229 234 proj = Project.find(3)
230 235 str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
231 236 r = Repository::Bazaar.create!(
232 237 :project => proj, :url => '/tmp/test/bazaar',
233 238 :log_encoding => 'ISO-8859-1' )
234 239 assert r
235 240 c = Changeset.new(:repository => r,
236 241 :committed_on => Time.now,
237 242 :revision => '123',
238 243 :scmid => '12345',
239 244 :comments => str)
240 245 assert( c.save )
241 246 assert_equal "Texte encodΓ© en ISO-8859-1.", c.comments
242 247 end
243 248
244 249 def test_invalid_utf8_sequences_in_comments_should_be_stripped
245 250 proj = Project.find(3)
246 251 str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
247 252 r = Repository::Bazaar.create!(
248 253 :project => proj, :url => '/tmp/test/bazaar',
249 254 :log_encoding => 'UTF-8' )
250 255 assert r
251 256 c = Changeset.new(:repository => r,
252 257 :committed_on => Time.now,
253 258 :revision => '123',
254 259 :scmid => '12345',
255 260 :comments => str)
256 261 assert( c.save )
257 262 if str.respond_to?(:force_encoding)
258 263 assert_equal "Texte encod? en ISO-8859-1.", c.comments
259 264 else
260 265 assert_equal "Texte encod en ISO-8859-1.", c.comments
261 266 end
262 267 end
263 268
264 269 def test_comments_should_be_converted_all_latin1_to_utf8
265 270 s1 = "\xC2\x80"
266 271 s2 = "\xc3\x82\xc2\x80"
267 272 if s1.respond_to?(:force_encoding)
268 273 s3 = s1.dup
269 274 s4 = s2.dup
270 275 s1.force_encoding('ASCII-8BIT')
271 276 s2.force_encoding('ASCII-8BIT')
272 277 s3.force_encoding('ISO-8859-1')
273 278 s4.force_encoding('UTF-8')
274 279 assert_equal s3.encode('UTF-8'), s4
275 280 end
276 281 proj = Project.find(3)
277 282 r = Repository::Bazaar.create!(
278 283 :project => proj, :url => '/tmp/test/bazaar',
279 284 :log_encoding => 'ISO-8859-1' )
280 285 assert r
281 286 c = Changeset.new(:repository => r,
282 287 :committed_on => Time.now,
283 288 :revision => '123',
284 289 :scmid => '12345',
285 290 :comments => s1)
286 291 assert( c.save )
287 292 assert_equal s2, c.comments
288 293 end
289 294
290 295 def test_identifier
291 296 c = Changeset.find_by_revision('1')
292 297 assert_equal c.revision, c.identifier
293 298 end
294 299 end
General Comments 0
You need to be logged in to leave comments. Login now