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