##// END OF EJS Templates
Merged r12944 (#16143)....
Jean-Philippe Lang -
r12672:dbe03f544355
parent child
Show More
@@ -0,0 +1,12
1 class ChangeChangesetsCommentsLimit < ActiveRecord::Migration
2 def up
3 if ActiveRecord::Base.connection.adapter_name =~ /mysql/i
4 max_size = 16.megabytes
5 change_column :changesets, :comments, :text, :limit => max_size
6 end
7 end
8
9 def down
10 # no-op
11 end
12 end
@@ -1,543 +1,554
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2014 Jean-Philippe Lang
4 # Copyright (C) 2006-2014 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',
114 Setting.commit_update_keywords = [{'keywords' => 'fixes , closes',
115 'status_id' => IssueStatus.where(:is_closed => true).first.id.to_s}]
115 'status_id' => IssueStatus.where(:is_closed => true).first.id.to_s}]
116 Setting.commit_logtime_enabled = '1'
116 Setting.commit_logtime_enabled = '1'
117
117
118 c = Changeset.new(:repository => Project.find(1).repository,
118 c = Changeset.new(:repository => Project.find(1).repository,
119 :committed_on => Time.now,
119 :committed_on => Time.now,
120 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
120 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
121 :user => User.find(2))
121 :user => User.find(2))
122 assert_difference 'TimeEntry.count', 2 do
122 assert_difference 'TimeEntry.count', 2 do
123 c.scan_comment_for_issue_ids
123 c.scan_comment_for_issue_ids
124 end
124 end
125
125
126 assert_equal [1, 2], c.issue_ids.sort
126 assert_equal [1, 2], c.issue_ids.sort
127 assert Issue.find(1).closed?
127 assert Issue.find(1).closed?
128 assert Issue.find(2).closed?
128 assert Issue.find(2).closed?
129
129
130 times = TimeEntry.order('id desc').limit(2)
130 times = TimeEntry.order('id desc').limit(2)
131 assert_equal [1, 2], times.collect(&:issue_id).sort
131 assert_equal [1, 2], times.collect(&:issue_id).sort
132 end
132 end
133
133
134 def test_ref_keywords_any_line_start
134 def test_ref_keywords_any_line_start
135 Setting.commit_ref_keywords = '*'
135 Setting.commit_ref_keywords = '*'
136 c = Changeset.new(:repository => Project.find(1).repository,
136 c = Changeset.new(:repository => Project.find(1).repository,
137 :committed_on => Time.now,
137 :committed_on => Time.now,
138 :comments => '#1 is the reason of this commit',
138 :comments => '#1 is the reason of this commit',
139 :revision => '12345')
139 :revision => '12345')
140 assert c.save
140 assert c.save
141 assert_equal [1], c.issue_ids.sort
141 assert_equal [1], c.issue_ids.sort
142 end
142 end
143
143
144 def test_ref_keywords_allow_brackets_around_a_issue_number
144 def test_ref_keywords_allow_brackets_around_a_issue_number
145 Setting.commit_ref_keywords = '*'
145 Setting.commit_ref_keywords = '*'
146 c = Changeset.new(:repository => Project.find(1).repository,
146 c = Changeset.new(:repository => Project.find(1).repository,
147 :committed_on => Time.now,
147 :committed_on => Time.now,
148 :comments => '[#1] Worked on this issue',
148 :comments => '[#1] Worked on this issue',
149 :revision => '12345')
149 :revision => '12345')
150 assert c.save
150 assert c.save
151 assert_equal [1], c.issue_ids.sort
151 assert_equal [1], c.issue_ids.sort
152 end
152 end
153
153
154 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
154 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
155 Setting.commit_ref_keywords = '*'
155 Setting.commit_ref_keywords = '*'
156 c = Changeset.new(:repository => Project.find(1).repository,
156 c = Changeset.new(:repository => Project.find(1).repository,
157 :committed_on => Time.now,
157 :committed_on => Time.now,
158 :comments => '[#1 #2, #3] Worked on these',
158 :comments => '[#1 #2, #3] Worked on these',
159 :revision => '12345')
159 :revision => '12345')
160 assert c.save
160 assert c.save
161 assert_equal [1,2,3], c.issue_ids.sort
161 assert_equal [1,2,3], c.issue_ids.sort
162 end
162 end
163
163
164 def test_update_keywords_with_multiple_rules
164 def test_update_keywords_with_multiple_rules
165 with_settings :commit_update_keywords => [
165 with_settings :commit_update_keywords => [
166 {'keywords' => 'fixes, closes', 'status_id' => '5'},
166 {'keywords' => 'fixes, closes', 'status_id' => '5'},
167 {'keywords' => 'resolves', 'status_id' => '3'}
167 {'keywords' => 'resolves', 'status_id' => '3'}
168 ] do
168 ] do
169
169
170 issue1 = Issue.generate!
170 issue1 = Issue.generate!
171 issue2 = Issue.generate!
171 issue2 = Issue.generate!
172 Changeset.generate!(:comments => "Closes ##{issue1.id}\nResolves ##{issue2.id}")
172 Changeset.generate!(:comments => "Closes ##{issue1.id}\nResolves ##{issue2.id}")
173 assert_equal 5, issue1.reload.status_id
173 assert_equal 5, issue1.reload.status_id
174 assert_equal 3, issue2.reload.status_id
174 assert_equal 3, issue2.reload.status_id
175 end
175 end
176 end
176 end
177
177
178 def test_update_keywords_with_multiple_rules_should_match_tracker
178 def test_update_keywords_with_multiple_rules_should_match_tracker
179 with_settings :commit_update_keywords => [
179 with_settings :commit_update_keywords => [
180 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
180 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
181 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => ''}
181 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => ''}
182 ] do
182 ] do
183
183
184 issue1 = Issue.generate!(:tracker_id => 2)
184 issue1 = Issue.generate!(:tracker_id => 2)
185 issue2 = Issue.generate!
185 issue2 = Issue.generate!
186 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
186 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
187 assert_equal 5, issue1.reload.status_id
187 assert_equal 5, issue1.reload.status_id
188 assert_equal 3, issue2.reload.status_id
188 assert_equal 3, issue2.reload.status_id
189 end
189 end
190 end
190 end
191
191
192 def test_update_keywords_with_multiple_rules_and_no_match
192 def test_update_keywords_with_multiple_rules_and_no_match
193 with_settings :commit_update_keywords => [
193 with_settings :commit_update_keywords => [
194 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
194 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
195 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => '3'}
195 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => '3'}
196 ] do
196 ] do
197
197
198 issue1 = Issue.generate!(:tracker_id => 2)
198 issue1 = Issue.generate!(:tracker_id => 2)
199 issue2 = Issue.generate!
199 issue2 = Issue.generate!
200 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
200 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
201 assert_equal 5, issue1.reload.status_id
201 assert_equal 5, issue1.reload.status_id
202 assert_equal 1, issue2.reload.status_id # no updates
202 assert_equal 1, issue2.reload.status_id # no updates
203 end
203 end
204 end
204 end
205
205
206 def test_commit_referencing_a_subproject_issue
206 def test_commit_referencing_a_subproject_issue
207 c = Changeset.new(:repository => Project.find(1).repository,
207 c = Changeset.new(:repository => Project.find(1).repository,
208 :committed_on => Time.now,
208 :committed_on => Time.now,
209 :comments => 'refs #5, a subproject issue',
209 :comments => 'refs #5, a subproject issue',
210 :revision => '12345')
210 :revision => '12345')
211 assert c.save
211 assert c.save
212 assert_equal [5], c.issue_ids.sort
212 assert_equal [5], c.issue_ids.sort
213 assert c.issues.first.project != c.project
213 assert c.issues.first.project != c.project
214 end
214 end
215
215
216 def test_commit_closing_a_subproject_issue
216 def test_commit_closing_a_subproject_issue
217 with_settings :commit_update_keywords => [{'keywords' => 'closes', 'status_id' => '5'}],
217 with_settings :commit_update_keywords => [{'keywords' => 'closes', 'status_id' => '5'}],
218 :default_language => 'en' do
218 :default_language => 'en' do
219 issue = Issue.find(5)
219 issue = Issue.find(5)
220 assert !issue.closed?
220 assert !issue.closed?
221 assert_difference 'Journal.count' do
221 assert_difference 'Journal.count' do
222 c = Changeset.new(:repository => Project.find(1).repository,
222 c = Changeset.new(:repository => Project.find(1).repository,
223 :committed_on => Time.now,
223 :committed_on => Time.now,
224 :comments => 'closes #5, a subproject issue',
224 :comments => 'closes #5, a subproject issue',
225 :revision => '12345')
225 :revision => '12345')
226 assert c.save
226 assert c.save
227 end
227 end
228 assert issue.reload.closed?
228 assert issue.reload.closed?
229 journal = Journal.order('id DESC').first
229 journal = Journal.order('id DESC').first
230 assert_equal issue, journal.issue
230 assert_equal issue, journal.issue
231 assert_include "Applied in changeset ecookbook:r12345.", journal.notes
231 assert_include "Applied in changeset ecookbook:r12345.", journal.notes
232 end
232 end
233 end
233 end
234
234
235 def test_commit_referencing_a_parent_project_issue
235 def test_commit_referencing_a_parent_project_issue
236 # repository of child project
236 # repository of child project
237 r = Repository::Subversion.create!(
237 r = Repository::Subversion.create!(
238 :project => Project.find(3),
238 :project => Project.find(3),
239 :url => 'svn://localhost/test')
239 :url => 'svn://localhost/test')
240 c = Changeset.new(:repository => r,
240 c = Changeset.new(:repository => r,
241 :committed_on => Time.now,
241 :committed_on => Time.now,
242 :comments => 'refs #2, an issue of a parent project',
242 :comments => 'refs #2, an issue of a parent project',
243 :revision => '12345')
243 :revision => '12345')
244 assert c.save
244 assert c.save
245 assert_equal [2], c.issue_ids.sort
245 assert_equal [2], c.issue_ids.sort
246 assert c.issues.first.project != c.project
246 assert c.issues.first.project != c.project
247 end
247 end
248
248
249 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
250 r = Repository::Subversion.create!(
250 r = Repository::Subversion.create!(
251 :project => Project.find(3),
251 :project => Project.find(3),
252 :url => 'svn://localhost/test')
252 :url => 'svn://localhost/test')
253 with_settings :commit_cross_project_ref => '0' do
253 with_settings :commit_cross_project_ref => '0' do
254 c = Changeset.new(:repository => r,
254 c = Changeset.new(:repository => r,
255 :committed_on => Time.now,
255 :committed_on => Time.now,
256 :comments => 'refs #4, an issue of a different project',
256 :comments => 'refs #4, an issue of a different project',
257 :revision => '12345')
257 :revision => '12345')
258 assert c.save
258 assert c.save
259 assert_equal [], c.issue_ids
259 assert_equal [], c.issue_ids
260 end
260 end
261 end
261 end
262
262
263 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
264 r = Repository::Subversion.create!(
264 r = Repository::Subversion.create!(
265 :project => Project.find(3),
265 :project => Project.find(3),
266 :url => 'svn://localhost/test')
266 :url => 'svn://localhost/test')
267 with_settings :commit_cross_project_ref => '1' do
267 with_settings :commit_cross_project_ref => '1' do
268 c = Changeset.new(:repository => r,
268 c = Changeset.new(:repository => r,
269 :committed_on => Time.now,
269 :committed_on => Time.now,
270 :comments => 'refs #4, an issue of a different project',
270 :comments => 'refs #4, an issue of a different project',
271 :revision => '12345')
271 :revision => '12345')
272 assert c.save
272 assert c.save
273 assert_equal [4], c.issue_ids
273 assert_equal [4], c.issue_ids
274 end
274 end
275 end
275 end
276
276
277 def test_old_commits_should_not_update_issues_nor_log_time
277 def test_old_commits_should_not_update_issues_nor_log_time
278 Setting.commit_ref_keywords = '*'
278 Setting.commit_ref_keywords = '*'
279 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'}}
280 Setting.commit_logtime_enabled = '1'
280 Setting.commit_logtime_enabled = '1'
281
281
282 repository = Project.find(1).repository
282 repository = Project.find(1).repository
283 repository.created_on = Time.now
283 repository.created_on = Time.now
284 repository.save!
284 repository.save!
285
285
286 c = Changeset.new(:repository => repository,
286 c = Changeset.new(:repository => repository,
287 :committed_on => 1.month.ago,
287 :committed_on => 1.month.ago,
288 :comments => 'New commit (#2). Fixes #1 @1h',
288 :comments => 'New commit (#2). Fixes #1 @1h',
289 :revision => '12345')
289 :revision => '12345')
290 assert_no_difference 'TimeEntry.count' do
290 assert_no_difference 'TimeEntry.count' do
291 assert c.save
291 assert c.save
292 end
292 end
293 assert_equal [1, 2], c.issue_ids.sort
293 assert_equal [1, 2], c.issue_ids.sort
294 issue = Issue.find(1)
294 issue = Issue.find(1)
295 assert_equal 1, issue.status_id
295 assert_equal 1, issue.status_id
296 assert_equal 0, issue.done_ratio
296 assert_equal 0, issue.done_ratio
297 end
297 end
298
298
299 def test_text_tag_revision
299 def test_text_tag_revision
300 c = Changeset.new(:revision => '520')
300 c = Changeset.new(:revision => '520')
301 assert_equal 'r520', c.text_tag
301 assert_equal 'r520', c.text_tag
302 end
302 end
303
303
304 def test_text_tag_revision_with_same_project
304 def test_text_tag_revision_with_same_project
305 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
305 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
306 assert_equal 'r520', c.text_tag(Project.find(1))
306 assert_equal 'r520', c.text_tag(Project.find(1))
307 end
307 end
308
308
309 def test_text_tag_revision_with_different_project
309 def test_text_tag_revision_with_different_project
310 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
310 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
311 assert_equal 'ecookbook:r520', c.text_tag(Project.find(2))
311 assert_equal 'ecookbook:r520', c.text_tag(Project.find(2))
312 end
312 end
313
313
314 def test_text_tag_revision_with_repository_identifier
314 def test_text_tag_revision_with_repository_identifier
315 r = Repository::Subversion.create!(
315 r = Repository::Subversion.create!(
316 :project_id => 1,
316 :project_id => 1,
317 :url => 'svn://localhost/test',
317 :url => 'svn://localhost/test',
318 :identifier => 'documents')
318 :identifier => 'documents')
319 c = Changeset.new(:revision => '520', :repository => r)
319 c = Changeset.new(:revision => '520', :repository => r)
320 assert_equal 'documents|r520', c.text_tag
320 assert_equal 'documents|r520', c.text_tag
321 assert_equal 'ecookbook:documents|r520', c.text_tag(Project.find(2))
321 assert_equal 'ecookbook:documents|r520', c.text_tag(Project.find(2))
322 end
322 end
323
323
324 def test_text_tag_hash
324 def test_text_tag_hash
325 c = Changeset.new(
325 c = Changeset.new(
326 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
326 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
327 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
327 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
328 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
328 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
329 end
329 end
330
330
331 def test_text_tag_hash_with_same_project
331 def test_text_tag_hash_with_same_project
332 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)
333 assert_equal 'commit:7234cb27', c.text_tag(Project.find(1))
333 assert_equal 'commit:7234cb27', c.text_tag(Project.find(1))
334 end
334 end
335
335
336 def test_text_tag_hash_with_different_project
336 def test_text_tag_hash_with_different_project
337 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)
338 assert_equal 'ecookbook:commit:7234cb27', c.text_tag(Project.find(2))
338 assert_equal 'ecookbook:commit:7234cb27', c.text_tag(Project.find(2))
339 end
339 end
340
340
341 def test_text_tag_hash_all_number
341 def test_text_tag_hash_all_number
342 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
342 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
343 assert_equal 'commit:0123456789', c.text_tag
343 assert_equal 'commit:0123456789', c.text_tag
344 end
344 end
345
345
346 def test_text_tag_hash_with_repository_identifier
346 def test_text_tag_hash_with_repository_identifier
347 r = Repository::Subversion.new(
347 r = Repository::Subversion.new(
348 :project_id => 1,
348 :project_id => 1,
349 :url => 'svn://localhost/test',
349 :url => 'svn://localhost/test',
350 :identifier => 'documents')
350 :identifier => 'documents')
351 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => r)
351 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => r)
352 assert_equal 'commit:documents|7234cb27', c.text_tag
352 assert_equal 'commit:documents|7234cb27', c.text_tag
353 assert_equal 'ecookbook:commit:documents|7234cb27', c.text_tag(Project.find(2))
353 assert_equal 'ecookbook:commit:documents|7234cb27', c.text_tag(Project.find(2))
354 end
354 end
355
355
356 def test_previous
356 def test_previous
357 changeset = Changeset.find_by_revision('3')
357 changeset = Changeset.find_by_revision('3')
358 assert_equal Changeset.find_by_revision('2'), changeset.previous
358 assert_equal Changeset.find_by_revision('2'), changeset.previous
359 end
359 end
360
360
361 def test_previous_nil
361 def test_previous_nil
362 changeset = Changeset.find_by_revision('1')
362 changeset = Changeset.find_by_revision('1')
363 assert_nil changeset.previous
363 assert_nil changeset.previous
364 end
364 end
365
365
366 def test_next
366 def test_next
367 changeset = Changeset.find_by_revision('2')
367 changeset = Changeset.find_by_revision('2')
368 assert_equal Changeset.find_by_revision('3'), changeset.next
368 assert_equal Changeset.find_by_revision('3'), changeset.next
369 end
369 end
370
370
371 def test_next_nil
371 def test_next_nil
372 changeset = Changeset.find_by_revision('10')
372 changeset = Changeset.find_by_revision('10')
373 assert_nil changeset.next
373 assert_nil changeset.next
374 end
374 end
375
375
376 def test_comments_should_be_converted_to_utf8
376 def test_comments_should_be_converted_to_utf8
377 proj = Project.find(3)
377 proj = Project.find(3)
378 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
378 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
379 str = "Texte encod\xe9 en ISO-8859-1."
379 str = "Texte encod\xe9 en ISO-8859-1."
380 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
380 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
381 r = Repository::Bazaar.create!(
381 r = Repository::Bazaar.create!(
382 :project => proj,
382 :project => proj,
383 :url => '/tmp/test/bazaar',
383 :url => '/tmp/test/bazaar',
384 :log_encoding => 'ISO-8859-1' )
384 :log_encoding => 'ISO-8859-1' )
385 assert r
385 assert r
386 c = Changeset.new(:repository => r,
386 c = Changeset.new(:repository => r,
387 :committed_on => Time.now,
387 :committed_on => Time.now,
388 :revision => '123',
388 :revision => '123',
389 :scmid => '12345',
389 :scmid => '12345',
390 :comments => str)
390 :comments => str)
391 assert( c.save )
391 assert( c.save )
392 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
392 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
393 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
393 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
394 assert_equal str_utf8, c.comments
394 assert_equal str_utf8, c.comments
395 end
395 end
396
396
397 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
397 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
398 proj = Project.find(3)
398 proj = Project.find(3)
399 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
399 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
400 str1 = "Texte encod\xe9 en ISO-8859-1."
400 str1 = "Texte encod\xe9 en ISO-8859-1."
401 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
401 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
402 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
402 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
403 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
403 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
404 r = Repository::Bazaar.create!(
404 r = Repository::Bazaar.create!(
405 :project => proj,
405 :project => proj,
406 :url => '/tmp/test/bazaar',
406 :url => '/tmp/test/bazaar',
407 :log_encoding => 'UTF-8' )
407 :log_encoding => 'UTF-8' )
408 assert r
408 assert r
409 c = Changeset.new(:repository => r,
409 c = Changeset.new(:repository => r,
410 :committed_on => Time.now,
410 :committed_on => Time.now,
411 :revision => '123',
411 :revision => '123',
412 :scmid => '12345',
412 :scmid => '12345',
413 :comments => str1,
413 :comments => str1,
414 :committer => str2)
414 :committer => str2)
415 assert( c.save )
415 assert( c.save )
416 assert_equal "Texte encod? en ISO-8859-1.", c.comments
416 assert_equal "Texte encod? en ISO-8859-1.", c.comments
417 assert_equal "?a?b?c?d?e test", c.committer
417 assert_equal "?a?b?c?d?e test", c.committer
418 end
418 end
419
419
420 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
420 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
421 proj = Project.find(3)
421 proj = Project.find(3)
422 str = "test\xb5\xfetest\xb5\xfe"
422 str = "test\xb5\xfetest\xb5\xfe"
423 if str.respond_to?(:force_encoding)
423 if str.respond_to?(:force_encoding)
424 str.force_encoding('ASCII-8BIT')
424 str.force_encoding('ASCII-8BIT')
425 end
425 end
426 r = Repository::Bazaar.create!(
426 r = Repository::Bazaar.create!(
427 :project => proj,
427 :project => proj,
428 :url => '/tmp/test/bazaar',
428 :url => '/tmp/test/bazaar',
429 :log_encoding => 'ISO-2022-JP' )
429 :log_encoding => 'ISO-2022-JP' )
430 assert r
430 assert r
431 c = Changeset.new(:repository => r,
431 c = Changeset.new(:repository => r,
432 :committed_on => Time.now,
432 :committed_on => Time.now,
433 :revision => '123',
433 :revision => '123',
434 :scmid => '12345',
434 :scmid => '12345',
435 :comments => str)
435 :comments => str)
436 assert( c.save )
436 assert( c.save )
437 assert_equal "test??test??", c.comments
437 assert_equal "test??test??", c.comments
438 end
438 end
439
439
440 def test_comments_should_be_converted_all_latin1_to_utf8
440 def test_comments_should_be_converted_all_latin1_to_utf8
441 s1 = "\xC2\x80"
441 s1 = "\xC2\x80"
442 s2 = "\xc3\x82\xc2\x80"
442 s2 = "\xc3\x82\xc2\x80"
443 s4 = s2.dup
443 s4 = s2.dup
444 if s1.respond_to?(:force_encoding)
444 if s1.respond_to?(:force_encoding)
445 s3 = s1.dup
445 s3 = s1.dup
446 s1.force_encoding('ASCII-8BIT')
446 s1.force_encoding('ASCII-8BIT')
447 s2.force_encoding('ASCII-8BIT')
447 s2.force_encoding('ASCII-8BIT')
448 s3.force_encoding('ISO-8859-1')
448 s3.force_encoding('ISO-8859-1')
449 s4.force_encoding('UTF-8')
449 s4.force_encoding('UTF-8')
450 assert_equal s3.encode('UTF-8'), s4
450 assert_equal s3.encode('UTF-8'), s4
451 end
451 end
452 proj = Project.find(3)
452 proj = Project.find(3)
453 r = Repository::Bazaar.create!(
453 r = Repository::Bazaar.create!(
454 :project => proj,
454 :project => proj,
455 :url => '/tmp/test/bazaar',
455 :url => '/tmp/test/bazaar',
456 :log_encoding => 'ISO-8859-1' )
456 :log_encoding => 'ISO-8859-1' )
457 assert r
457 assert r
458 c = Changeset.new(:repository => r,
458 c = Changeset.new(:repository => r,
459 :committed_on => Time.now,
459 :committed_on => Time.now,
460 :revision => '123',
460 :revision => '123',
461 :scmid => '12345',
461 :scmid => '12345',
462 :comments => s1)
462 :comments => s1)
463 assert( c.save )
463 assert( c.save )
464 assert_equal s4, c.comments
464 assert_equal s4, c.comments
465 end
465 end
466
466
467 def test_invalid_utf8_sequences_in_paths_should_be_replaced
467 def test_invalid_utf8_sequences_in_paths_should_be_replaced
468 proj = Project.find(3)
468 proj = Project.find(3)
469 str1 = "Texte encod\xe9 en ISO-8859-1"
469 str1 = "Texte encod\xe9 en ISO-8859-1"
470 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
470 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
471 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
471 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
472 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
472 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
473 r = Repository::Bazaar.create!(
473 r = Repository::Bazaar.create!(
474 :project => proj,
474 :project => proj,
475 :url => '/tmp/test/bazaar',
475 :url => '/tmp/test/bazaar',
476 :log_encoding => 'UTF-8' )
476 :log_encoding => 'UTF-8' )
477 assert r
477 assert r
478 cs = Changeset.new(
478 cs = Changeset.new(
479 :repository => r,
479 :repository => r,
480 :committed_on => Time.now,
480 :committed_on => Time.now,
481 :revision => '123',
481 :revision => '123',
482 :scmid => '12345',
482 :scmid => '12345',
483 :comments => "test")
483 :comments => "test")
484 assert(cs.save)
484 assert(cs.save)
485 ch = Change.new(
485 ch = Change.new(
486 :changeset => cs,
486 :changeset => cs,
487 :action => "A",
487 :action => "A",
488 :path => str1,
488 :path => str1,
489 :from_path => str2,
489 :from_path => str2,
490 :from_revision => "345")
490 :from_revision => "345")
491 assert(ch.save)
491 assert(ch.save)
492 assert_equal "Texte encod? en ISO-8859-1", ch.path
492 assert_equal "Texte encod? en ISO-8859-1", ch.path
493 assert_equal "?a?b?c?d?e test", ch.from_path
493 assert_equal "?a?b?c?d?e test", ch.from_path
494 end
494 end
495
495
496 def test_comments_nil
496 def test_comments_nil
497 proj = Project.find(3)
497 proj = Project.find(3)
498 r = Repository::Bazaar.create!(
498 r = Repository::Bazaar.create!(
499 :project => proj,
499 :project => proj,
500 :url => '/tmp/test/bazaar',
500 :url => '/tmp/test/bazaar',
501 :log_encoding => 'ISO-8859-1' )
501 :log_encoding => 'ISO-8859-1' )
502 assert r
502 assert r
503 c = Changeset.new(:repository => r,
503 c = Changeset.new(:repository => r,
504 :committed_on => Time.now,
504 :committed_on => Time.now,
505 :revision => '123',
505 :revision => '123',
506 :scmid => '12345',
506 :scmid => '12345',
507 :comments => nil,
507 :comments => nil,
508 :committer => nil)
508 :committer => nil)
509 assert( c.save )
509 assert( c.save )
510 assert_equal "", c.comments
510 assert_equal "", c.comments
511 assert_equal nil, c.committer
511 assert_equal nil, c.committer
512 if c.comments.respond_to?(:force_encoding)
512 if c.comments.respond_to?(:force_encoding)
513 assert_equal "UTF-8", c.comments.encoding.to_s
513 assert_equal "UTF-8", c.comments.encoding.to_s
514 end
514 end
515 end
515 end
516
516
517 def test_comments_empty
517 def test_comments_empty
518 proj = Project.find(3)
518 proj = Project.find(3)
519 r = Repository::Bazaar.create!(
519 r = Repository::Bazaar.create!(
520 :project => proj,
520 :project => proj,
521 :url => '/tmp/test/bazaar',
521 :url => '/tmp/test/bazaar',
522 :log_encoding => 'ISO-8859-1' )
522 :log_encoding => 'ISO-8859-1' )
523 assert r
523 assert r
524 c = Changeset.new(:repository => r,
524 c = Changeset.new(:repository => r,
525 :committed_on => Time.now,
525 :committed_on => Time.now,
526 :revision => '123',
526 :revision => '123',
527 :scmid => '12345',
527 :scmid => '12345',
528 :comments => "",
528 :comments => "",
529 :committer => "")
529 :committer => "")
530 assert( c.save )
530 assert( c.save )
531 assert_equal "", c.comments
531 assert_equal "", c.comments
532 assert_equal "", c.committer
532 assert_equal "", c.committer
533 if c.comments.respond_to?(:force_encoding)
533 if c.comments.respond_to?(:force_encoding)
534 assert_equal "UTF-8", c.comments.encoding.to_s
534 assert_equal "UTF-8", c.comments.encoding.to_s
535 assert_equal "UTF-8", c.committer.encoding.to_s
535 assert_equal "UTF-8", c.committer.encoding.to_s
536 end
536 end
537 end
537 end
538
538
539 def test_comments_should_accept_more_than_64k
540 c = Changeset.new(:repository => Repository.first,
541 :committed_on => Time.now,
542 :revision => '123',
543 :scmid => '12345',
544 :comments => "a" * 500.kilobyte)
545 assert c.save
546 c.reload
547 assert_equal 500.kilobyte, c.comments.size
548 end
549
539 def test_identifier
550 def test_identifier
540 c = Changeset.find_by_revision('1')
551 c = Changeset.find_by_revision('1')
541 assert_equal c.revision, c.identifier
552 assert_equal c.revision, c.identifier
542 end
553 end
543 end
554 end
General Comments 0
You need to be logged in to leave comments. Login now