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