@@ -1,282 +1,282 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2016 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 | require 'issues_controller' |
|
19 | require 'issues_controller' | |
20 |
|
20 | |||
21 | class IssuesControllerTransactionTest < Redmine::ControllerTest |
|
21 | class IssuesControllerTransactionTest < Redmine::ControllerTest | |
22 | tests IssuesController |
|
22 | tests IssuesController | |
23 | fixtures :projects, |
|
23 | fixtures :projects, | |
24 | :users, |
|
24 | :users, | |
25 | :roles, |
|
25 | :roles, | |
26 | :members, |
|
26 | :members, | |
27 | :member_roles, |
|
27 | :member_roles, | |
28 | :issues, |
|
28 | :issues, | |
29 | :issue_statuses, |
|
29 | :issue_statuses, | |
30 | :versions, |
|
30 | :versions, | |
31 | :trackers, |
|
31 | :trackers, | |
32 | :projects_trackers, |
|
32 | :projects_trackers, | |
33 | :issue_categories, |
|
33 | :issue_categories, | |
34 | :enabled_modules, |
|
34 | :enabled_modules, | |
35 | :enumerations, |
|
35 | :enumerations, | |
36 | :attachments, |
|
36 | :attachments, | |
37 | :workflows, |
|
37 | :workflows, | |
38 | :custom_fields, |
|
38 | :custom_fields, | |
39 | :custom_values, |
|
39 | :custom_values, | |
40 | :custom_fields_projects, |
|
40 | :custom_fields_projects, | |
41 | :custom_fields_trackers, |
|
41 | :custom_fields_trackers, | |
42 | :time_entries, |
|
42 | :time_entries, | |
43 | :journals, |
|
43 | :journals, | |
44 | :journal_details, |
|
44 | :journal_details, | |
45 | :queries |
|
45 | :queries | |
46 |
|
46 | |||
47 | self.use_transactional_fixtures = false |
|
47 | self.use_transactional_fixtures = false | |
48 |
|
48 | |||
49 | def setup |
|
49 | def setup | |
50 | User.current = nil |
|
50 | User.current = nil | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def test_update_stale_issue_should_not_update_the_issue |
|
53 | def test_update_stale_issue_should_not_update_the_issue | |
54 | issue = Issue.find(2) |
|
54 | issue = Issue.find(2) | |
55 | @request.session[:user_id] = 2 |
|
55 | @request.session[:user_id] = 2 | |
56 |
|
56 | |||
57 | assert_no_difference 'Journal.count' do |
|
57 | assert_no_difference 'Journal.count' do | |
58 | assert_no_difference 'TimeEntry.count' do |
|
58 | assert_no_difference 'TimeEntry.count' do | |
59 | put :update, |
|
59 | put :update, | |
60 | :id => issue.id, |
|
60 | :id => issue.id, | |
61 | :issue => { |
|
61 | :issue => { | |
62 | :fixed_version_id => 4, |
|
62 | :fixed_version_id => 4, | |
63 | :notes => 'My notes', |
|
63 | :notes => 'My notes', | |
64 | :lock_version => (issue.lock_version - 1) |
|
64 | :lock_version => (issue.lock_version - 1) | |
65 | }, |
|
65 | }, | |
66 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id } |
|
66 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id } | |
67 | end |
|
67 | end | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | assert_response :success |
|
70 | assert_response :success | |
71 |
|
71 | |||
72 | assert_select 'div.conflict' |
|
72 | assert_select 'div.conflict' | |
73 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'overwrite' |
|
73 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'overwrite' | |
74 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'add_notes' |
|
74 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'add_notes' | |
75 | assert_select 'label' do |
|
75 | assert_select 'label' do | |
76 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'cancel' |
|
76 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'cancel' | |
77 | assert_select 'a[href="/issues/2"]' |
|
77 | assert_select 'a[href="/issues/2"]' | |
78 | end |
|
78 | end | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def test_update_stale_issue_should_save_attachments |
|
81 | def test_update_stale_issue_should_save_attachments | |
82 | set_tmp_attachments_directory |
|
82 | set_tmp_attachments_directory | |
83 | issue = Issue.find(2) |
|
83 | issue = Issue.find(2) | |
84 | @request.session[:user_id] = 2 |
|
84 | @request.session[:user_id] = 2 | |
85 |
|
85 | |||
86 | assert_no_difference 'Journal.count' do |
|
86 | assert_no_difference 'Journal.count' do | |
87 | assert_no_difference 'TimeEntry.count' do |
|
87 | assert_no_difference 'TimeEntry.count' do | |
88 | assert_difference 'Attachment.count' do |
|
88 | assert_difference 'Attachment.count' do | |
89 | put :update, |
|
89 | put :update, | |
90 | :id => issue.id, |
|
90 | :id => issue.id, | |
91 | :issue => { |
|
91 | :issue => { | |
92 | :fixed_version_id => 4, |
|
92 | :fixed_version_id => 4, | |
93 | :notes => 'My notes', |
|
93 | :notes => 'My notes', | |
94 | :lock_version => (issue.lock_version - 1) |
|
94 | :lock_version => (issue.lock_version - 1) | |
95 | }, |
|
95 | }, | |
96 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}, |
|
96 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}, | |
97 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id } |
|
97 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id } | |
98 | end |
|
98 | end | |
99 | end |
|
99 | end | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | assert_response :success |
|
102 | assert_response :success | |
103 |
|
103 | |||
104 | attachment = Attachment.order('id DESC').first |
|
104 | attachment = Attachment.order('id DESC').first | |
105 | assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token |
|
105 | assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token | |
106 | assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' |
|
106 | assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' | |
107 | end |
|
107 | end | |
108 |
|
108 | |||
109 | def test_update_stale_issue_without_notes_should_not_show_add_notes_option |
|
109 | def test_update_stale_issue_without_notes_should_not_show_add_notes_option | |
110 | issue = Issue.find(2) |
|
110 | issue = Issue.find(2) | |
111 | @request.session[:user_id] = 2 |
|
111 | @request.session[:user_id] = 2 | |
112 |
|
112 | |||
113 | put :update, :id => issue.id, |
|
113 | put :update, :id => issue.id, | |
114 | :issue => { |
|
114 | :issue => { | |
115 | :fixed_version_id => 4, |
|
115 | :fixed_version_id => 4, | |
116 | :notes => '', |
|
116 | :notes => '', | |
117 | :lock_version => (issue.lock_version - 1) |
|
117 | :lock_version => (issue.lock_version - 1) | |
118 | } |
|
118 | } | |
119 | assert_response :success |
|
119 | assert_response :success | |
120 |
|
120 | |||
121 | assert_select 'div.conflict' |
|
121 | assert_select 'div.conflict' | |
122 | assert_select 'input[name=conflict_resolution][value=overwrite]' |
|
122 | assert_select 'input[name=conflict_resolution][value=overwrite]' | |
123 | assert_select 'input[name=conflict_resolution][value=add_notes]', 0 |
|
123 | assert_select 'input[name=conflict_resolution][value=add_notes]', 0 | |
124 | assert_select 'input[name=conflict_resolution][value=cancel]' |
|
124 | assert_select 'input[name=conflict_resolution][value=cancel]' | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | def test_update_stale_issue_should_show_conflicting_journals |
|
127 | def test_update_stale_issue_should_show_conflicting_journals | |
128 | @request.session[:user_id] = 2 |
|
128 | @request.session[:user_id] = 2 | |
129 |
|
129 | |||
130 | put :update, :id => 1, |
|
130 | put :update, :id => 1, | |
131 | :issue => { |
|
131 | :issue => { | |
132 | :fixed_version_id => 4, |
|
132 | :fixed_version_id => 4, | |
133 | :notes => '', |
|
133 | :notes => '', | |
134 | :lock_version => 2 |
|
134 | :lock_version => 2 | |
135 | }, |
|
135 | }, | |
136 | :last_journal_id => 1 |
|
136 | :last_journal_id => 1 | |
137 | assert_response :success |
|
137 | assert_response :success | |
138 |
|
138 | |||
139 | assert_select '.conflict-journal', 1 |
|
139 | assert_select '.conflict-journal', 1 | |
140 | assert_select 'div.conflict', :text => /Some notes with Redmine links/ |
|
140 | assert_select 'div.conflict', :text => /Some notes with Redmine links/ | |
141 | end |
|
141 | end | |
142 |
|
142 | |||
143 | def test_update_stale_issue_without_previous_journal_should_show_all_journals |
|
143 | def test_update_stale_issue_without_previous_journal_should_show_all_journals | |
144 | @request.session[:user_id] = 2 |
|
144 | @request.session[:user_id] = 2 | |
145 |
|
145 | |||
146 | put :update, :id => 1, |
|
146 | put :update, :id => 1, | |
147 | :issue => { |
|
147 | :issue => { | |
148 | :fixed_version_id => 4, |
|
148 | :fixed_version_id => 4, | |
149 | :notes => '', |
|
149 | :notes => '', | |
150 | :lock_version => 2 |
|
150 | :lock_version => 2 | |
151 | }, |
|
151 | }, | |
152 | :last_journal_id => '' |
|
152 | :last_journal_id => '' | |
153 | assert_response :success |
|
153 | assert_response :success | |
154 |
|
154 | |||
155 | assert_select '.conflict-journal', 2 |
|
155 | assert_select '.conflict-journal', 2 | |
156 | assert_select 'div.conflict', :text => /Some notes with Redmine links/ |
|
156 | assert_select 'div.conflict', :text => /Some notes with Redmine links/ | |
157 | assert_select 'div.conflict', :text => /Journal notes/ |
|
157 | assert_select 'div.conflict', :text => /Journal notes/ | |
158 | end |
|
158 | end | |
159 |
|
159 | |||
160 | def test_update_stale_issue_should_show_private_journals_with_permission_only |
|
160 | def test_update_stale_issue_should_show_private_journals_with_permission_only | |
161 | journal = Journal.create!(:journalized => Issue.find(1), :notes => 'Privates notes', :private_notes => true, :user_id => 1) |
|
161 | journal = Journal.create!(:journalized => Issue.find(1), :notes => 'Privates notes', :private_notes => true, :user_id => 1) | |
162 |
|
162 | |||
163 | @request.session[:user_id] = 2 |
|
163 | @request.session[:user_id] = 2 | |
164 | put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => '' |
|
164 | put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => '' | |
165 | assert_response :success |
|
165 | assert_response :success | |
166 | assert_select '.conflict-journal', :text => /Privates notes/ |
|
166 | assert_select '.conflict-journal', :text => /Privates notes/ | |
167 |
|
167 | |||
168 | Role.find(1).remove_permission! :view_private_notes |
|
168 | Role.find(1).remove_permission! :view_private_notes | |
169 | put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => '' |
|
169 | put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => '' | |
170 | assert_response :success |
|
170 | assert_response :success | |
171 | assert_select '.conflict-journal', :text => /Privates notes/, :count => 0 |
|
171 | assert_select '.conflict-journal', :text => /Privates notes/, :count => 0 | |
172 | end |
|
172 | end | |
173 |
|
173 | |||
174 | def test_update_stale_issue_with_overwrite_conflict_resolution_should_update |
|
174 | def test_update_stale_issue_with_overwrite_conflict_resolution_should_update | |
175 | @request.session[:user_id] = 2 |
|
175 | @request.session[:user_id] = 2 | |
176 |
|
176 | |||
177 | assert_difference 'Journal.count' do |
|
177 | assert_difference 'Journal.count' do | |
178 | put :update, :id => 1, |
|
178 | put :update, :id => 1, | |
179 | :issue => { |
|
179 | :issue => { | |
180 | :fixed_version_id => 4, |
|
180 | :fixed_version_id => 4, | |
181 | :notes => 'overwrite_conflict_resolution', |
|
181 | :notes => 'overwrite_conflict_resolution', | |
182 | :lock_version => 2 |
|
182 | :lock_version => 2 | |
183 | }, |
|
183 | }, | |
184 | :conflict_resolution => 'overwrite' |
|
184 | :conflict_resolution => 'overwrite' | |
185 | end |
|
185 | end | |
186 |
|
186 | |||
187 | assert_response 302 |
|
187 | assert_response 302 | |
188 | issue = Issue.find(1) |
|
188 | issue = Issue.find(1) | |
189 | assert_equal 4, issue.fixed_version_id |
|
189 | assert_equal 4, issue.fixed_version_id | |
190 | journal = Journal.order('id DESC').first |
|
190 | journal = Journal.order('id DESC').first | |
191 | assert_equal 'overwrite_conflict_resolution', journal.notes |
|
191 | assert_equal 'overwrite_conflict_resolution', journal.notes | |
192 | assert journal.details.any? |
|
192 | assert journal.details.any? | |
193 | end |
|
193 | end | |
194 |
|
194 | |||
195 | def test_update_stale_issue_with_add_notes_conflict_resolution_should_update |
|
195 | def test_update_stale_issue_with_add_notes_conflict_resolution_should_update | |
196 | @request.session[:user_id] = 2 |
|
196 | @request.session[:user_id] = 2 | |
197 |
|
197 | |||
198 | assert_difference 'Journal.count' do |
|
198 | assert_difference 'Journal.count' do | |
199 | put :update, :id => 1, |
|
199 | put :update, :id => 1, | |
200 | :issue => { |
|
200 | :issue => { | |
201 | :fixed_version_id => 4, |
|
201 | :fixed_version_id => 4, | |
202 | :notes => 'add_notes_conflict_resolution', |
|
202 | :notes => 'add_notes_conflict_resolution', | |
203 | :lock_version => 2 |
|
203 | :lock_version => 2 | |
204 | }, |
|
204 | }, | |
205 | :conflict_resolution => 'add_notes' |
|
205 | :conflict_resolution => 'add_notes' | |
206 | end |
|
206 | end | |
207 |
|
207 | |||
208 | assert_response 302 |
|
208 | assert_response 302 | |
209 | issue = Issue.find(1) |
|
209 | issue = Issue.find(1) | |
210 | assert_nil issue.fixed_version_id |
|
210 | assert_nil issue.fixed_version_id | |
211 | journal = Journal.order('id DESC').first |
|
211 | journal = Journal.order('id DESC').first | |
212 | assert_equal 'add_notes_conflict_resolution', journal.notes |
|
212 | assert_equal 'add_notes_conflict_resolution', journal.notes | |
213 | assert_equal false, journal.private_notes |
|
213 | assert_equal false, journal.private_notes | |
214 | assert journal.details.empty? |
|
214 | assert journal.details.empty? | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | def test_update_stale_issue_with_add_notes_conflict_resolution_should_preserve_private_notes |
|
217 | def test_update_stale_issue_with_add_notes_conflict_resolution_should_preserve_private_notes | |
218 | @request.session[:user_id] = 2 |
|
218 | @request.session[:user_id] = 2 | |
219 |
|
219 | |||
220 | journal = new_record(Journal) do |
|
220 | journal = new_record(Journal) do | |
221 | put :update, :id => 1, |
|
221 | put :update, :id => 1, | |
222 | :issue => { |
|
222 | :issue => { | |
223 | :fixed_version_id => 4, |
|
223 | :fixed_version_id => 4, | |
224 | :notes => 'add_privates_notes_conflict_resolution', |
|
224 | :notes => 'add_privates_notes_conflict_resolution', | |
225 | :private_notes => '1', |
|
225 | :private_notes => '1', | |
226 | :lock_version => 2 |
|
226 | :lock_version => 2 | |
227 | }, |
|
227 | }, | |
228 | :conflict_resolution => 'add_notes' |
|
228 | :conflict_resolution => 'add_notes' | |
229 | end |
|
229 | end | |
230 |
|
230 | |||
231 | assert_response 302 |
|
231 | assert_response 302 | |
232 | assert_equal 'add_privates_notes_conflict_resolution', journal.notes |
|
232 | assert_equal 'add_privates_notes_conflict_resolution', journal.notes | |
233 | assert_equal true, journal.private_notes |
|
233 | assert_equal true, journal.private_notes | |
234 | assert journal.details.empty? |
|
234 | assert journal.details.empty? | |
235 | end |
|
235 | end | |
236 |
|
236 | |||
237 | def test_update_stale_issue_with_cancel_conflict_resolution_should_redirect_without_updating |
|
237 | def test_update_stale_issue_with_cancel_conflict_resolution_should_redirect_without_updating | |
238 | @request.session[:user_id] = 2 |
|
238 | @request.session[:user_id] = 2 | |
239 |
|
239 | |||
240 | assert_no_difference 'Journal.count' do |
|
240 | assert_no_difference 'Journal.count' do | |
241 | put :update, :id => 1, |
|
241 | put :update, :id => 1, | |
242 | :issue => { |
|
242 | :issue => { | |
243 | :fixed_version_id => 4, |
|
243 | :fixed_version_id => 4, | |
244 | :notes => 'add_notes_conflict_resolution', |
|
244 | :notes => 'add_notes_conflict_resolution', | |
245 | :lock_version => 2 |
|
245 | :lock_version => 2 | |
246 | }, |
|
246 | }, | |
247 | :conflict_resolution => 'cancel' |
|
247 | :conflict_resolution => 'cancel' | |
248 | end |
|
248 | end | |
249 |
|
249 | |||
250 | assert_redirected_to '/issues/1' |
|
250 | assert_redirected_to '/issues/1' | |
251 | issue = Issue.find(1) |
|
251 | issue = Issue.find(1) | |
252 | assert_nil issue.fixed_version_id |
|
252 | assert_nil issue.fixed_version_id | |
253 | end |
|
253 | end | |
254 |
|
254 | |||
255 | def test_put_update_with_spent_time_and_failure_should_not_add_spent_time |
|
255 | def test_put_update_with_spent_time_and_failure_should_not_add_spent_time | |
256 | @request.session[:user_id] = 2 |
|
256 | @request.session[:user_id] = 2 | |
257 |
|
257 | |||
258 | assert_no_difference('TimeEntry.count') do |
|
258 | assert_no_difference('TimeEntry.count') do | |
259 | put :update, |
|
259 | put :update, | |
260 | :id => 1, |
|
260 | :id => 1, | |
261 | :issue => { :subject => '' }, |
|
261 | :issue => { :subject => '' }, | |
262 | :time_entry => { :hours => '2.5', :comments => 'should not be added', :activity_id => TimeEntryActivity.first.id } |
|
262 | :time_entry => { :hours => '2.5', :comments => 'should not be added', :activity_id => TimeEntryActivity.first.id } | |
263 | assert_response :success |
|
263 | assert_response :success | |
264 | end |
|
264 | end | |
265 |
|
265 | |||
266 | assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2.5' |
|
266 | assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2.50' | |
267 | assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'should not be added' |
|
267 | assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'should not be added' | |
268 | assert_select 'select[name=?]', 'time_entry[activity_id]' do |
|
268 | assert_select 'select[name=?]', 'time_entry[activity_id]' do | |
269 | assert_select 'option[value=?][selected=selected]', TimeEntryActivity.first.id.to_s |
|
269 | assert_select 'option[value=?][selected=selected]', TimeEntryActivity.first.id.to_s | |
270 | end |
|
270 | end | |
271 | end |
|
271 | end | |
272 |
|
272 | |||
273 | def test_index_should_rescue_invalid_sql_query |
|
273 | def test_index_should_rescue_invalid_sql_query | |
274 | IssueQuery.any_instance.stubs(:statement).returns("INVALID STATEMENT") |
|
274 | IssueQuery.any_instance.stubs(:statement).returns("INVALID STATEMENT") | |
275 |
|
275 | |||
276 | get :index |
|
276 | get :index | |
277 | assert_response 500 |
|
277 | assert_response 500 | |
278 | assert_select 'p', :text => /An error occurred/ |
|
278 | assert_select 'p', :text => /An error occurred/ | |
279 | assert_nil session[:query] |
|
279 | assert_nil session[:query] | |
280 | assert_nil session[:issues_index_sort] |
|
280 | assert_nil session[:issues_index_sort] | |
281 | end |
|
281 | end | |
282 | end |
|
282 | end |
General Comments 0
You need to be logged in to leave comments.
Login now