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