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