##// END OF EJS Templates
code format cleanup ChangesetTest...
Toshi MARUYAMA -
r12268:09884154c9b6
parent child
Show More
@@ -1,532 +1,533
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2013 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.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 require File.expand_path('../../test_helper', __FILE__)
20 require File.expand_path('../../test_helper', __FILE__)
21
21
22 class ChangesetTest < ActiveSupport::TestCase
22 class ChangesetTest < ActiveSupport::TestCase
23 fixtures :projects, :repositories,
23 fixtures :projects, :repositories,
24 :issues, :issue_statuses, :issue_categories,
24 :issues, :issue_statuses, :issue_categories,
25 :changesets, :changes,
25 :changesets, :changes,
26 :enumerations,
26 :enumerations,
27 :custom_fields, :custom_values,
27 :custom_fields, :custom_values,
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_ref_keywords = '*'
33 Setting.commit_ref_keywords = '*'
34 Setting.commit_update_keywords = [{'keywords' => 'fixes , closes', 'status_id' => '5', 'done_ratio' => '90'}]
34 Setting.commit_update_keywords = [{'keywords' => 'fixes , closes', 'status_id' => '5', 'done_ratio' => '90'}]
35
35
36 c = Changeset.new(:repository => Project.find(1).repository,
36 c = Changeset.new(:repository => Project.find(1).repository,
37 :committed_on => Time.now,
37 :committed_on => Time.now,
38 :comments => 'New commit (#2). Fixes #1',
38 :comments => 'New commit (#2). Fixes #1',
39 :revision => '12345')
39 :revision => '12345')
40 assert c.save
40 assert c.save
41 assert_equal [1, 2], c.issue_ids.sort
41 assert_equal [1, 2], c.issue_ids.sort
42 fixed = Issue.find(1)
42 fixed = Issue.find(1)
43 assert fixed.closed?
43 assert fixed.closed?
44 assert_equal 90, fixed.done_ratio
44 assert_equal 90, fixed.done_ratio
45 assert_equal 1, ActionMailer::Base.deliveries.size
45 assert_equal 1, ActionMailer::Base.deliveries.size
46 end
46 end
47
47
48 def test_ref_keywords
48 def test_ref_keywords
49 Setting.commit_ref_keywords = 'refs'
49 Setting.commit_ref_keywords = 'refs'
50 Setting.commit_update_keywords = ''
50 Setting.commit_update_keywords = ''
51 c = Changeset.new(:repository => Project.find(1).repository,
51 c = Changeset.new(:repository => Project.find(1).repository,
52 :committed_on => Time.now,
52 :committed_on => Time.now,
53 :comments => 'Ignores #2. Refs #1',
53 :comments => 'Ignores #2. Refs #1',
54 :revision => '12345')
54 :revision => '12345')
55 assert c.save
55 assert c.save
56 assert_equal [1], c.issue_ids.sort
56 assert_equal [1], c.issue_ids.sort
57 end
57 end
58
58
59 def test_ref_keywords_any_only
59 def test_ref_keywords_any_only
60 Setting.commit_ref_keywords = '*'
60 Setting.commit_ref_keywords = '*'
61 Setting.commit_update_keywords = ''
61 Setting.commit_update_keywords = ''
62 c = Changeset.new(:repository => Project.find(1).repository,
62 c = Changeset.new(:repository => Project.find(1).repository,
63 :committed_on => Time.now,
63 :committed_on => Time.now,
64 :comments => 'Ignores #2. Refs #1',
64 :comments => 'Ignores #2. Refs #1',
65 :revision => '12345')
65 :revision => '12345')
66 assert c.save
66 assert c.save
67 assert_equal [1, 2], c.issue_ids.sort
67 assert_equal [1, 2], c.issue_ids.sort
68 end
68 end
69
69
70 def test_ref_keywords_any_with_timelog
70 def test_ref_keywords_any_with_timelog
71 Setting.commit_ref_keywords = '*'
71 Setting.commit_ref_keywords = '*'
72 Setting.commit_logtime_enabled = '1'
72 Setting.commit_logtime_enabled = '1'
73
73
74 {
74 {
75 '2' => 2.0,
75 '2' => 2.0,
76 '2h' => 2.0,
76 '2h' => 2.0,
77 '2hours' => 2.0,
77 '2hours' => 2.0,
78 '15m' => 0.25,
78 '15m' => 0.25,
79 '15min' => 0.25,
79 '15min' => 0.25,
80 '3h15' => 3.25,
80 '3h15' => 3.25,
81 '3h15m' => 3.25,
81 '3h15m' => 3.25,
82 '3h15min' => 3.25,
82 '3h15min' => 3.25,
83 '3:15' => 3.25,
83 '3:15' => 3.25,
84 '3.25' => 3.25,
84 '3.25' => 3.25,
85 '3.25h' => 3.25,
85 '3.25h' => 3.25,
86 '3,25' => 3.25,
86 '3,25' => 3.25,
87 '3,25h' => 3.25,
87 '3,25h' => 3.25,
88 }.each do |syntax, expected_hours|
88 }.each do |syntax, expected_hours|
89 c = Changeset.new(:repository => Project.find(1).repository,
89 c = Changeset.new(:repository => Project.find(1).repository,
90 :committed_on => 24.hours.ago,
90 :committed_on => 24.hours.ago,
91 :comments => "Worked on this issue #1 @#{syntax}",
91 :comments => "Worked on this issue #1 @#{syntax}",
92 :revision => '520',
92 :revision => '520',
93 :user => User.find(2))
93 :user => User.find(2))
94 assert_difference 'TimeEntry.count' do
94 assert_difference 'TimeEntry.count' do
95 c.scan_comment_for_issue_ids
95 c.scan_comment_for_issue_ids
96 end
96 end
97 assert_equal [1], c.issue_ids.sort
97 assert_equal [1], c.issue_ids.sort
98
98
99 time = TimeEntry.order('id desc').first
99 time = TimeEntry.order('id desc').first
100 assert_equal 1, time.issue_id
100 assert_equal 1, time.issue_id
101 assert_equal 1, time.project_id
101 assert_equal 1, time.project_id
102 assert_equal 2, time.user_id
102 assert_equal 2, time.user_id
103 assert_equal expected_hours, time.hours,
103 assert_equal expected_hours, time.hours,
104 "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
104 "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
105 assert_equal Date.yesterday, time.spent_on
105 assert_equal Date.yesterday, time.spent_on
106 assert time.activity.is_default?
106 assert time.activity.is_default?
107 assert time.comments.include?('r520'),
107 assert time.comments.include?('r520'),
108 "r520 was expected in time_entry comments: #{time.comments}"
108 "r520 was expected in time_entry comments: #{time.comments}"
109 end
109 end
110 end
110 end
111
111
112 def test_ref_keywords_closing_with_timelog
112 def test_ref_keywords_closing_with_timelog
113 Setting.commit_ref_keywords = '*'
113 Setting.commit_ref_keywords = '*'
114 Setting.commit_update_keywords = [{'keywords' => 'fixes , closes', 'status_id' => IssueStatus.where(:is_closed => true).first.id.to_s}]
114 Setting.commit_update_keywords = [{'keywords' => 'fixes , closes',
115 'status_id' => IssueStatus.where(:is_closed => true).first.id.to_s}]
115 Setting.commit_logtime_enabled = '1'
116 Setting.commit_logtime_enabled = '1'
116
117
117 c = Changeset.new(:repository => Project.find(1).repository,
118 c = Changeset.new(:repository => Project.find(1).repository,
118 :committed_on => Time.now,
119 :committed_on => Time.now,
119 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
120 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
120 :user => User.find(2))
121 :user => User.find(2))
121 assert_difference 'TimeEntry.count', 2 do
122 assert_difference 'TimeEntry.count', 2 do
122 c.scan_comment_for_issue_ids
123 c.scan_comment_for_issue_ids
123 end
124 end
124
125
125 assert_equal [1, 2], c.issue_ids.sort
126 assert_equal [1, 2], c.issue_ids.sort
126 assert Issue.find(1).closed?
127 assert Issue.find(1).closed?
127 assert Issue.find(2).closed?
128 assert Issue.find(2).closed?
128
129
129 times = TimeEntry.order('id desc').limit(2)
130 times = TimeEntry.order('id desc').limit(2)
130 assert_equal [1, 2], times.collect(&:issue_id).sort
131 assert_equal [1, 2], times.collect(&:issue_id).sort
131 end
132 end
132
133
133 def test_ref_keywords_any_line_start
134 def test_ref_keywords_any_line_start
134 Setting.commit_ref_keywords = '*'
135 Setting.commit_ref_keywords = '*'
135 c = Changeset.new(:repository => Project.find(1).repository,
136 c = Changeset.new(:repository => Project.find(1).repository,
136 :committed_on => Time.now,
137 :committed_on => Time.now,
137 :comments => '#1 is the reason of this commit',
138 :comments => '#1 is the reason of this commit',
138 :revision => '12345')
139 :revision => '12345')
139 assert c.save
140 assert c.save
140 assert_equal [1], c.issue_ids.sort
141 assert_equal [1], c.issue_ids.sort
141 end
142 end
142
143
143 def test_ref_keywords_allow_brackets_around_a_issue_number
144 def test_ref_keywords_allow_brackets_around_a_issue_number
144 Setting.commit_ref_keywords = '*'
145 Setting.commit_ref_keywords = '*'
145 c = Changeset.new(:repository => Project.find(1).repository,
146 c = Changeset.new(:repository => Project.find(1).repository,
146 :committed_on => Time.now,
147 :committed_on => Time.now,
147 :comments => '[#1] Worked on this issue',
148 :comments => '[#1] Worked on this issue',
148 :revision => '12345')
149 :revision => '12345')
149 assert c.save
150 assert c.save
150 assert_equal [1], c.issue_ids.sort
151 assert_equal [1], c.issue_ids.sort
151 end
152 end
152
153
153 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
154 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
154 Setting.commit_ref_keywords = '*'
155 Setting.commit_ref_keywords = '*'
155 c = Changeset.new(:repository => Project.find(1).repository,
156 c = Changeset.new(:repository => Project.find(1).repository,
156 :committed_on => Time.now,
157 :committed_on => Time.now,
157 :comments => '[#1 #2, #3] Worked on these',
158 :comments => '[#1 #2, #3] Worked on these',
158 :revision => '12345')
159 :revision => '12345')
159 assert c.save
160 assert c.save
160 assert_equal [1,2,3], c.issue_ids.sort
161 assert_equal [1,2,3], c.issue_ids.sort
161 end
162 end
162
163
163 def test_update_keywords_with_multiple_rules
164 def test_update_keywords_with_multiple_rules
164 with_settings :commit_update_keywords => [
165 with_settings :commit_update_keywords => [
165 {'keywords' => 'fixes, closes', 'status_id' => '5'},
166 {'keywords' => 'fixes, closes', 'status_id' => '5'},
166 {'keywords' => 'resolves', 'status_id' => '3'}
167 {'keywords' => 'resolves', 'status_id' => '3'}
167 ] do
168 ] do
168
169
169 issue1 = Issue.generate!
170 issue1 = Issue.generate!
170 issue2 = Issue.generate!
171 issue2 = Issue.generate!
171 Changeset.generate!(:comments => "Closes ##{issue1.id}\nResolves ##{issue2.id}")
172 Changeset.generate!(:comments => "Closes ##{issue1.id}\nResolves ##{issue2.id}")
172 assert_equal 5, issue1.reload.status_id
173 assert_equal 5, issue1.reload.status_id
173 assert_equal 3, issue2.reload.status_id
174 assert_equal 3, issue2.reload.status_id
174 end
175 end
175 end
176 end
176
177
177 def test_update_keywords_with_multiple_rules_should_match_tracker
178 def test_update_keywords_with_multiple_rules_should_match_tracker
178 with_settings :commit_update_keywords => [
179 with_settings :commit_update_keywords => [
179 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
180 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
180 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => ''}
181 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => ''}
181 ] do
182 ] do
182
183
183 issue1 = Issue.generate!(:tracker_id => 2)
184 issue1 = Issue.generate!(:tracker_id => 2)
184 issue2 = Issue.generate!
185 issue2 = Issue.generate!
185 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
186 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
186 assert_equal 5, issue1.reload.status_id
187 assert_equal 5, issue1.reload.status_id
187 assert_equal 3, issue2.reload.status_id
188 assert_equal 3, issue2.reload.status_id
188 end
189 end
189 end
190 end
190
191
191 def test_update_keywords_with_multiple_rules_and_no_match
192 def test_update_keywords_with_multiple_rules_and_no_match
192 with_settings :commit_update_keywords => [
193 with_settings :commit_update_keywords => [
193 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
194 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
194 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => '3'}
195 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => '3'}
195 ] do
196 ] do
196
197
197 issue1 = Issue.generate!(:tracker_id => 2)
198 issue1 = Issue.generate!(:tracker_id => 2)
198 issue2 = Issue.generate!
199 issue2 = Issue.generate!
199 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
200 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
200 assert_equal 5, issue1.reload.status_id
201 assert_equal 5, issue1.reload.status_id
201 assert_equal 1, issue2.reload.status_id # no updates
202 assert_equal 1, issue2.reload.status_id # no updates
202 end
203 end
203 end
204 end
204
205
205 def test_commit_referencing_a_subproject_issue
206 def test_commit_referencing_a_subproject_issue
206 c = Changeset.new(:repository => Project.find(1).repository,
207 c = Changeset.new(:repository => Project.find(1).repository,
207 :committed_on => Time.now,
208 :committed_on => Time.now,
208 :comments => 'refs #5, a subproject issue',
209 :comments => 'refs #5, a subproject issue',
209 :revision => '12345')
210 :revision => '12345')
210 assert c.save
211 assert c.save
211 assert_equal [5], c.issue_ids.sort
212 assert_equal [5], c.issue_ids.sort
212 assert c.issues.first.project != c.project
213 assert c.issues.first.project != c.project
213 end
214 end
214
215
215 def test_commit_closing_a_subproject_issue
216 def test_commit_closing_a_subproject_issue
216 with_settings :commit_update_keywords => [{'keywords' => 'closes', 'status_id' => '5'}],
217 with_settings :commit_update_keywords => [{'keywords' => 'closes', 'status_id' => '5'}],
217 :default_language => 'en' do
218 :default_language => 'en' do
218 issue = Issue.find(5)
219 issue = Issue.find(5)
219 assert !issue.closed?
220 assert !issue.closed?
220 assert_difference 'Journal.count' do
221 assert_difference 'Journal.count' do
221 c = Changeset.new(:repository => Project.find(1).repository,
222 c = Changeset.new(:repository => Project.find(1).repository,
222 :committed_on => Time.now,
223 :committed_on => Time.now,
223 :comments => 'closes #5, a subproject issue',
224 :comments => 'closes #5, a subproject issue',
224 :revision => '12345')
225 :revision => '12345')
225 assert c.save
226 assert c.save
226 end
227 end
227 assert issue.reload.closed?
228 assert issue.reload.closed?
228 journal = Journal.order('id DESC').first
229 journal = Journal.order('id DESC').first
229 assert_equal issue, journal.issue
230 assert_equal issue, journal.issue
230 assert_include "Applied in changeset ecookbook:r12345.", journal.notes
231 assert_include "Applied in changeset ecookbook:r12345.", journal.notes
231 end
232 end
232 end
233 end
233
234
234 def test_commit_referencing_a_parent_project_issue
235 def test_commit_referencing_a_parent_project_issue
235 # repository of child project
236 # repository of child project
236 r = Repository::Subversion.create!(
237 r = Repository::Subversion.create!(
237 :project => Project.find(3),
238 :project => Project.find(3),
238 :url => 'svn://localhost/test')
239 :url => 'svn://localhost/test')
239 c = Changeset.new(:repository => r,
240 c = Changeset.new(:repository => r,
240 :committed_on => Time.now,
241 :committed_on => Time.now,
241 :comments => 'refs #2, an issue of a parent project',
242 :comments => 'refs #2, an issue of a parent project',
242 :revision => '12345')
243 :revision => '12345')
243 assert c.save
244 assert c.save
244 assert_equal [2], c.issue_ids.sort
245 assert_equal [2], c.issue_ids.sort
245 assert c.issues.first.project != c.project
246 assert c.issues.first.project != c.project
246 end
247 end
247
248
248 def test_commit_referencing_a_project_with_commit_cross_project_ref_disabled
249 def test_commit_referencing_a_project_with_commit_cross_project_ref_disabled
249 r = Repository::Subversion.create!(
250 r = Repository::Subversion.create!(
250 :project => Project.find(3),
251 :project => Project.find(3),
251 :url => 'svn://localhost/test')
252 :url => 'svn://localhost/test')
252 with_settings :commit_cross_project_ref => '0' do
253 with_settings :commit_cross_project_ref => '0' do
253 c = Changeset.new(:repository => r,
254 c = Changeset.new(:repository => r,
254 :committed_on => Time.now,
255 :committed_on => Time.now,
255 :comments => 'refs #4, an issue of a different project',
256 :comments => 'refs #4, an issue of a different project',
256 :revision => '12345')
257 :revision => '12345')
257 assert c.save
258 assert c.save
258 assert_equal [], c.issue_ids
259 assert_equal [], c.issue_ids
259 end
260 end
260 end
261 end
261
262
262 def test_commit_referencing_a_project_with_commit_cross_project_ref_enabled
263 def test_commit_referencing_a_project_with_commit_cross_project_ref_enabled
263 r = Repository::Subversion.create!(
264 r = Repository::Subversion.create!(
264 :project => Project.find(3),
265 :project => Project.find(3),
265 :url => 'svn://localhost/test')
266 :url => 'svn://localhost/test')
266 with_settings :commit_cross_project_ref => '1' do
267 with_settings :commit_cross_project_ref => '1' do
267 c = Changeset.new(:repository => r,
268 c = Changeset.new(:repository => r,
268 :committed_on => Time.now,
269 :committed_on => Time.now,
269 :comments => 'refs #4, an issue of a different project',
270 :comments => 'refs #4, an issue of a different project',
270 :revision => '12345')
271 :revision => '12345')
271 assert c.save
272 assert c.save
272 assert_equal [4], c.issue_ids
273 assert_equal [4], c.issue_ids
273 end
274 end
274 end
275 end
275
276
276 def test_old_commits_should_not_update_issues_nor_log_time
277 def test_old_commits_should_not_update_issues_nor_log_time
277 Setting.commit_ref_keywords = '*'
278 Setting.commit_ref_keywords = '*'
278 Setting.commit_update_keywords = {'fixes , closes' => {'status_id' => '5', 'done_ratio' => '90'}}
279 Setting.commit_update_keywords = {'fixes , closes' => {'status_id' => '5', 'done_ratio' => '90'}}
279 Setting.commit_logtime_enabled = '1'
280 Setting.commit_logtime_enabled = '1'
280
281
281 repository = Project.find(1).repository
282 repository = Project.find(1).repository
282 repository.created_on = Time.now
283 repository.created_on = Time.now
283 repository.save!
284 repository.save!
284
285
285 c = Changeset.new(:repository => repository,
286 c = Changeset.new(:repository => repository,
286 :committed_on => 1.month.ago,
287 :committed_on => 1.month.ago,
287 :comments => 'New commit (#2). Fixes #1 @1h',
288 :comments => 'New commit (#2). Fixes #1 @1h',
288 :revision => '12345')
289 :revision => '12345')
289 assert_no_difference 'TimeEntry.count' do
290 assert_no_difference 'TimeEntry.count' do
290 assert c.save
291 assert c.save
291 end
292 end
292 assert_equal [1, 2], c.issue_ids.sort
293 assert_equal [1, 2], c.issue_ids.sort
293 issue = Issue.find(1)
294 issue = Issue.find(1)
294 assert_equal 1, issue.status_id
295 assert_equal 1, issue.status_id
295 assert_equal 0, issue.done_ratio
296 assert_equal 0, issue.done_ratio
296 end
297 end
297
298
298 def test_text_tag_revision
299 def test_text_tag_revision
299 c = Changeset.new(:revision => '520')
300 c = Changeset.new(:revision => '520')
300 assert_equal 'r520', c.text_tag
301 assert_equal 'r520', c.text_tag
301 end
302 end
302
303
303 def test_text_tag_revision_with_same_project
304 def test_text_tag_revision_with_same_project
304 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
305 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
305 assert_equal 'r520', c.text_tag(Project.find(1))
306 assert_equal 'r520', c.text_tag(Project.find(1))
306 end
307 end
307
308
308 def test_text_tag_revision_with_different_project
309 def test_text_tag_revision_with_different_project
309 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
310 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
310 assert_equal 'ecookbook:r520', c.text_tag(Project.find(2))
311 assert_equal 'ecookbook:r520', c.text_tag(Project.find(2))
311 end
312 end
312
313
313 def test_text_tag_revision_with_repository_identifier
314 def test_text_tag_revision_with_repository_identifier
314 r = Repository::Subversion.create!(
315 r = Repository::Subversion.create!(
315 :project_id => 1,
316 :project_id => 1,
316 :url => 'svn://localhost/test',
317 :url => 'svn://localhost/test',
317 :identifier => 'documents')
318 :identifier => 'documents')
318 c = Changeset.new(:revision => '520', :repository => r)
319 c = Changeset.new(:revision => '520', :repository => r)
319 assert_equal 'documents|r520', c.text_tag
320 assert_equal 'documents|r520', c.text_tag
320 assert_equal 'ecookbook:documents|r520', c.text_tag(Project.find(2))
321 assert_equal 'ecookbook:documents|r520', c.text_tag(Project.find(2))
321 end
322 end
322
323
323 def test_text_tag_hash
324 def test_text_tag_hash
324 c = Changeset.new(
325 c = Changeset.new(
325 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
326 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
326 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
327 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
327 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
328 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
328 end
329 end
329
330
330 def test_text_tag_hash_with_same_project
331 def test_text_tag_hash_with_same_project
331 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
332 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
332 assert_equal 'commit:7234cb27', c.text_tag(Project.find(1))
333 assert_equal 'commit:7234cb27', c.text_tag(Project.find(1))
333 end
334 end
334
335
335 def test_text_tag_hash_with_different_project
336 def test_text_tag_hash_with_different_project
336 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
337 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
337 assert_equal 'ecookbook:commit:7234cb27', c.text_tag(Project.find(2))
338 assert_equal 'ecookbook:commit:7234cb27', c.text_tag(Project.find(2))
338 end
339 end
339
340
340 def test_text_tag_hash_all_number
341 def test_text_tag_hash_all_number
341 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
342 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
342 assert_equal 'commit:0123456789', c.text_tag
343 assert_equal 'commit:0123456789', c.text_tag
343 end
344 end
344
345
345 def test_previous
346 def test_previous
346 changeset = Changeset.find_by_revision('3')
347 changeset = Changeset.find_by_revision('3')
347 assert_equal Changeset.find_by_revision('2'), changeset.previous
348 assert_equal Changeset.find_by_revision('2'), changeset.previous
348 end
349 end
349
350
350 def test_previous_nil
351 def test_previous_nil
351 changeset = Changeset.find_by_revision('1')
352 changeset = Changeset.find_by_revision('1')
352 assert_nil changeset.previous
353 assert_nil changeset.previous
353 end
354 end
354
355
355 def test_next
356 def test_next
356 changeset = Changeset.find_by_revision('2')
357 changeset = Changeset.find_by_revision('2')
357 assert_equal Changeset.find_by_revision('3'), changeset.next
358 assert_equal Changeset.find_by_revision('3'), changeset.next
358 end
359 end
359
360
360 def test_next_nil
361 def test_next_nil
361 changeset = Changeset.find_by_revision('10')
362 changeset = Changeset.find_by_revision('10')
362 assert_nil changeset.next
363 assert_nil changeset.next
363 end
364 end
364
365
365 def test_comments_should_be_converted_to_utf8
366 def test_comments_should_be_converted_to_utf8
366 proj = Project.find(3)
367 proj = Project.find(3)
367 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
368 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
368 str = "Texte encod\xe9 en ISO-8859-1."
369 str = "Texte encod\xe9 en ISO-8859-1."
369 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
370 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
370 r = Repository::Bazaar.create!(
371 r = Repository::Bazaar.create!(
371 :project => proj,
372 :project => proj,
372 :url => '/tmp/test/bazaar',
373 :url => '/tmp/test/bazaar',
373 :log_encoding => 'ISO-8859-1' )
374 :log_encoding => 'ISO-8859-1' )
374 assert r
375 assert r
375 c = Changeset.new(:repository => r,
376 c = Changeset.new(:repository => r,
376 :committed_on => Time.now,
377 :committed_on => Time.now,
377 :revision => '123',
378 :revision => '123',
378 :scmid => '12345',
379 :scmid => '12345',
379 :comments => str)
380 :comments => str)
380 assert( c.save )
381 assert( c.save )
381 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
382 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
382 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
383 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
383 assert_equal str_utf8, c.comments
384 assert_equal str_utf8, c.comments
384 end
385 end
385
386
386 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
387 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
387 proj = Project.find(3)
388 proj = Project.find(3)
388 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
389 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
389 str1 = "Texte encod\xe9 en ISO-8859-1."
390 str1 = "Texte encod\xe9 en ISO-8859-1."
390 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
391 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
391 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
392 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
392 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
393 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
393 r = Repository::Bazaar.create!(
394 r = Repository::Bazaar.create!(
394 :project => proj,
395 :project => proj,
395 :url => '/tmp/test/bazaar',
396 :url => '/tmp/test/bazaar',
396 :log_encoding => 'UTF-8' )
397 :log_encoding => 'UTF-8' )
397 assert r
398 assert r
398 c = Changeset.new(:repository => r,
399 c = Changeset.new(:repository => r,
399 :committed_on => Time.now,
400 :committed_on => Time.now,
400 :revision => '123',
401 :revision => '123',
401 :scmid => '12345',
402 :scmid => '12345',
402 :comments => str1,
403 :comments => str1,
403 :committer => str2)
404 :committer => str2)
404 assert( c.save )
405 assert( c.save )
405 assert_equal "Texte encod? en ISO-8859-1.", c.comments
406 assert_equal "Texte encod? en ISO-8859-1.", c.comments
406 assert_equal "?a?b?c?d?e test", c.committer
407 assert_equal "?a?b?c?d?e test", c.committer
407 end
408 end
408
409
409 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
410 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
410 proj = Project.find(3)
411 proj = Project.find(3)
411 str = "test\xb5\xfetest\xb5\xfe"
412 str = "test\xb5\xfetest\xb5\xfe"
412 if str.respond_to?(:force_encoding)
413 if str.respond_to?(:force_encoding)
413 str.force_encoding('ASCII-8BIT')
414 str.force_encoding('ASCII-8BIT')
414 end
415 end
415 r = Repository::Bazaar.create!(
416 r = Repository::Bazaar.create!(
416 :project => proj,
417 :project => proj,
417 :url => '/tmp/test/bazaar',
418 :url => '/tmp/test/bazaar',
418 :log_encoding => 'ISO-2022-JP' )
419 :log_encoding => 'ISO-2022-JP' )
419 assert r
420 assert r
420 c = Changeset.new(:repository => r,
421 c = Changeset.new(:repository => r,
421 :committed_on => Time.now,
422 :committed_on => Time.now,
422 :revision => '123',
423 :revision => '123',
423 :scmid => '12345',
424 :scmid => '12345',
424 :comments => str)
425 :comments => str)
425 assert( c.save )
426 assert( c.save )
426 assert_equal "test??test??", c.comments
427 assert_equal "test??test??", c.comments
427 end
428 end
428
429
429 def test_comments_should_be_converted_all_latin1_to_utf8
430 def test_comments_should_be_converted_all_latin1_to_utf8
430 s1 = "\xC2\x80"
431 s1 = "\xC2\x80"
431 s2 = "\xc3\x82\xc2\x80"
432 s2 = "\xc3\x82\xc2\x80"
432 s4 = s2.dup
433 s4 = s2.dup
433 if s1.respond_to?(:force_encoding)
434 if s1.respond_to?(:force_encoding)
434 s3 = s1.dup
435 s3 = s1.dup
435 s1.force_encoding('ASCII-8BIT')
436 s1.force_encoding('ASCII-8BIT')
436 s2.force_encoding('ASCII-8BIT')
437 s2.force_encoding('ASCII-8BIT')
437 s3.force_encoding('ISO-8859-1')
438 s3.force_encoding('ISO-8859-1')
438 s4.force_encoding('UTF-8')
439 s4.force_encoding('UTF-8')
439 assert_equal s3.encode('UTF-8'), s4
440 assert_equal s3.encode('UTF-8'), s4
440 end
441 end
441 proj = Project.find(3)
442 proj = Project.find(3)
442 r = Repository::Bazaar.create!(
443 r = Repository::Bazaar.create!(
443 :project => proj,
444 :project => proj,
444 :url => '/tmp/test/bazaar',
445 :url => '/tmp/test/bazaar',
445 :log_encoding => 'ISO-8859-1' )
446 :log_encoding => 'ISO-8859-1' )
446 assert r
447 assert r
447 c = Changeset.new(:repository => r,
448 c = Changeset.new(:repository => r,
448 :committed_on => Time.now,
449 :committed_on => Time.now,
449 :revision => '123',
450 :revision => '123',
450 :scmid => '12345',
451 :scmid => '12345',
451 :comments => s1)
452 :comments => s1)
452 assert( c.save )
453 assert( c.save )
453 assert_equal s4, c.comments
454 assert_equal s4, c.comments
454 end
455 end
455
456
456 def test_invalid_utf8_sequences_in_paths_should_be_replaced
457 def test_invalid_utf8_sequences_in_paths_should_be_replaced
457 proj = Project.find(3)
458 proj = Project.find(3)
458 str1 = "Texte encod\xe9 en ISO-8859-1"
459 str1 = "Texte encod\xe9 en ISO-8859-1"
459 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
460 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
460 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
461 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
461 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
462 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
462 r = Repository::Bazaar.create!(
463 r = Repository::Bazaar.create!(
463 :project => proj,
464 :project => proj,
464 :url => '/tmp/test/bazaar',
465 :url => '/tmp/test/bazaar',
465 :log_encoding => 'UTF-8' )
466 :log_encoding => 'UTF-8' )
466 assert r
467 assert r
467 cs = Changeset.new(
468 cs = Changeset.new(
468 :repository => r,
469 :repository => r,
469 :committed_on => Time.now,
470 :committed_on => Time.now,
470 :revision => '123',
471 :revision => '123',
471 :scmid => '12345',
472 :scmid => '12345',
472 :comments => "test")
473 :comments => "test")
473 assert(cs.save)
474 assert(cs.save)
474 ch = Change.new(
475 ch = Change.new(
475 :changeset => cs,
476 :changeset => cs,
476 :action => "A",
477 :action => "A",
477 :path => str1,
478 :path => str1,
478 :from_path => str2,
479 :from_path => str2,
479 :from_revision => "345")
480 :from_revision => "345")
480 assert(ch.save)
481 assert(ch.save)
481 assert_equal "Texte encod? en ISO-8859-1", ch.path
482 assert_equal "Texte encod? en ISO-8859-1", ch.path
482 assert_equal "?a?b?c?d?e test", ch.from_path
483 assert_equal "?a?b?c?d?e test", ch.from_path
483 end
484 end
484
485
485 def test_comments_nil
486 def test_comments_nil
486 proj = Project.find(3)
487 proj = Project.find(3)
487 r = Repository::Bazaar.create!(
488 r = Repository::Bazaar.create!(
488 :project => proj,
489 :project => proj,
489 :url => '/tmp/test/bazaar',
490 :url => '/tmp/test/bazaar',
490 :log_encoding => 'ISO-8859-1' )
491 :log_encoding => 'ISO-8859-1' )
491 assert r
492 assert r
492 c = Changeset.new(:repository => r,
493 c = Changeset.new(:repository => r,
493 :committed_on => Time.now,
494 :committed_on => Time.now,
494 :revision => '123',
495 :revision => '123',
495 :scmid => '12345',
496 :scmid => '12345',
496 :comments => nil,
497 :comments => nil,
497 :committer => nil)
498 :committer => nil)
498 assert( c.save )
499 assert( c.save )
499 assert_equal "", c.comments
500 assert_equal "", c.comments
500 assert_equal nil, c.committer
501 assert_equal nil, c.committer
501 if c.comments.respond_to?(:force_encoding)
502 if c.comments.respond_to?(:force_encoding)
502 assert_equal "UTF-8", c.comments.encoding.to_s
503 assert_equal "UTF-8", c.comments.encoding.to_s
503 end
504 end
504 end
505 end
505
506
506 def test_comments_empty
507 def test_comments_empty
507 proj = Project.find(3)
508 proj = Project.find(3)
508 r = Repository::Bazaar.create!(
509 r = Repository::Bazaar.create!(
509 :project => proj,
510 :project => proj,
510 :url => '/tmp/test/bazaar',
511 :url => '/tmp/test/bazaar',
511 :log_encoding => 'ISO-8859-1' )
512 :log_encoding => 'ISO-8859-1' )
512 assert r
513 assert r
513 c = Changeset.new(:repository => r,
514 c = Changeset.new(:repository => r,
514 :committed_on => Time.now,
515 :committed_on => Time.now,
515 :revision => '123',
516 :revision => '123',
516 :scmid => '12345',
517 :scmid => '12345',
517 :comments => "",
518 :comments => "",
518 :committer => "")
519 :committer => "")
519 assert( c.save )
520 assert( c.save )
520 assert_equal "", c.comments
521 assert_equal "", c.comments
521 assert_equal "", c.committer
522 assert_equal "", c.committer
522 if c.comments.respond_to?(:force_encoding)
523 if c.comments.respond_to?(:force_encoding)
523 assert_equal "UTF-8", c.comments.encoding.to_s
524 assert_equal "UTF-8", c.comments.encoding.to_s
524 assert_equal "UTF-8", c.committer.encoding.to_s
525 assert_equal "UTF-8", c.committer.encoding.to_s
525 end
526 end
526 end
527 end
527
528
528 def test_identifier
529 def test_identifier
529 c = Changeset.find_by_revision('1')
530 c = Changeset.find_by_revision('1')
530 assert_equal c.revision, c.identifier
531 assert_equal c.revision, c.identifier
531 end
532 end
532 end
533 end
General Comments 0
You need to be logged in to leave comments. Login now