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