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