##// END OF EJS Templates
Rails4: replace deprecated Relation#first with finder options at IssuesControllerTransactionTest...
Toshi MARUYAMA -
r12363:190bb9af3048
parent child
Show More
@@ -1,263 +1,263
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 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 < ActionController::TestCase
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 assert_template 'edit'
72 72
73 73 assert_select 'div.conflict'
74 74 assert_select 'input[name=?][value=?]', 'conflict_resolution', 'overwrite'
75 75 assert_select 'input[name=?][value=?]', 'conflict_resolution', 'add_notes'
76 76 assert_select 'label' do
77 77 assert_select 'input[name=?][value=?]', 'conflict_resolution', 'cancel'
78 78 assert_select 'a[href=/issues/2]'
79 79 end
80 80 end
81 81
82 82 def test_update_stale_issue_should_save_attachments
83 83 set_tmp_attachments_directory
84 84 issue = Issue.find(2)
85 85 @request.session[:user_id] = 2
86 86
87 87 assert_no_difference 'Journal.count' do
88 88 assert_no_difference 'TimeEntry.count' do
89 89 assert_difference 'Attachment.count' do
90 90 put :update,
91 91 :id => issue.id,
92 92 :issue => {
93 93 :fixed_version_id => 4,
94 94 :notes => 'My notes',
95 95 :lock_version => (issue.lock_version - 1)
96 96 },
97 97 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}},
98 98 :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id }
99 99 end
100 100 end
101 101 end
102 102
103 103 assert_response :success
104 104 assert_template 'edit'
105 attachment = Attachment.first(:order => 'id DESC')
105 attachment = Attachment.order('id DESC').first
106 106 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
107 107 assert_tag 'input', :attributes => {:name => 'attachments[p0][filename]', :value => 'testfile.txt'}
108 108 end
109 109
110 110 def test_update_stale_issue_without_notes_should_not_show_add_notes_option
111 111 issue = Issue.find(2)
112 112 @request.session[:user_id] = 2
113 113
114 114 put :update, :id => issue.id,
115 115 :issue => {
116 116 :fixed_version_id => 4,
117 117 :notes => '',
118 118 :lock_version => (issue.lock_version - 1)
119 119 }
120 120
121 121 assert_tag 'div', :attributes => {:class => 'conflict'}
122 122 assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'overwrite'}
123 123 assert_no_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'add_notes'}
124 124 assert_tag 'input', :attributes => {: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
138 138 assert_not_nil assigns(:conflict_journals)
139 139 assert_equal 1, assigns(:conflict_journals).size
140 140 assert_equal 2, assigns(:conflict_journals).first.id
141 141 assert_tag 'div', :attributes => {:class => 'conflict'},
142 142 :descendant => {:content => /Some notes with Redmine links/}
143 143 end
144 144
145 145 def test_update_stale_issue_without_previous_journal_should_show_all_journals
146 146 @request.session[:user_id] = 2
147 147
148 148 put :update, :id => 1,
149 149 :issue => {
150 150 :fixed_version_id => 4,
151 151 :notes => '',
152 152 :lock_version => 2
153 153 },
154 154 :last_journal_id => ''
155 155
156 156 assert_not_nil assigns(:conflict_journals)
157 157 assert_equal 2, assigns(:conflict_journals).size
158 158 assert_tag 'div', :attributes => {:class => 'conflict'},
159 159 :descendant => {:content => /Some notes with Redmine links/}
160 160 assert_tag 'div', :attributes => {:class => 'conflict'},
161 161 :descendant => {:content => /Journal notes/}
162 162 end
163 163
164 164 def test_update_stale_issue_should_show_private_journals_with_permission_only
165 165 journal = Journal.create!(:journalized => Issue.find(1), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
166 166
167 167 @request.session[:user_id] = 2
168 168 put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => ''
169 169 assert_include journal, assigns(:conflict_journals)
170 170
171 171 Role.find(1).remove_permission! :view_private_notes
172 172 put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => ''
173 173 assert_not_include journal, assigns(:conflict_journals)
174 174 end
175 175
176 176 def test_update_stale_issue_with_overwrite_conflict_resolution_should_update
177 177 @request.session[:user_id] = 2
178 178
179 179 assert_difference 'Journal.count' do
180 180 put :update, :id => 1,
181 181 :issue => {
182 182 :fixed_version_id => 4,
183 183 :notes => 'overwrite_conflict_resolution',
184 184 :lock_version => 2
185 185 },
186 186 :conflict_resolution => 'overwrite'
187 187 end
188 188
189 189 assert_response 302
190 190 issue = Issue.find(1)
191 191 assert_equal 4, issue.fixed_version_id
192 journal = Journal.first(:order => 'id DESC')
192 journal = Journal.order('id DESC').first
193 193 assert_equal 'overwrite_conflict_resolution', journal.notes
194 194 assert journal.details.any?
195 195 end
196 196
197 197 def test_update_stale_issue_with_add_notes_conflict_resolution_should_update
198 198 @request.session[:user_id] = 2
199 199
200 200 assert_difference 'Journal.count' do
201 201 put :update, :id => 1,
202 202 :issue => {
203 203 :fixed_version_id => 4,
204 204 :notes => 'add_notes_conflict_resolution',
205 205 :lock_version => 2
206 206 },
207 207 :conflict_resolution => 'add_notes'
208 208 end
209 209
210 210 assert_response 302
211 211 issue = Issue.find(1)
212 212 assert_nil issue.fixed_version_id
213 journal = Journal.first(:order => 'id DESC')
213 journal = Journal.order('id DESC').first
214 214 assert_equal 'add_notes_conflict_resolution', journal.notes
215 215 assert journal.details.empty?
216 216 end
217 217
218 218 def test_update_stale_issue_with_cancel_conflict_resolution_should_redirect_without_updating
219 219 @request.session[:user_id] = 2
220 220
221 221 assert_no_difference 'Journal.count' do
222 222 put :update, :id => 1,
223 223 :issue => {
224 224 :fixed_version_id => 4,
225 225 :notes => 'add_notes_conflict_resolution',
226 226 :lock_version => 2
227 227 },
228 228 :conflict_resolution => 'cancel'
229 229 end
230 230
231 231 assert_redirected_to '/issues/1'
232 232 issue = Issue.find(1)
233 233 assert_nil issue.fixed_version_id
234 234 end
235 235
236 236 def test_put_update_with_spent_time_and_failure_should_not_add_spent_time
237 237 @request.session[:user_id] = 2
238 238
239 239 assert_no_difference('TimeEntry.count') do
240 240 put :update,
241 241 :id => 1,
242 242 :issue => { :subject => '' },
243 243 :time_entry => { :hours => '2.5', :comments => 'should not be added', :activity_id => TimeEntryActivity.first.id }
244 244 assert_response :success
245 245 end
246 246
247 247 assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2.5'
248 248 assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'should not be added'
249 249 assert_select 'select[name=?]', 'time_entry[activity_id]' do
250 250 assert_select 'option[value=?][selected=selected]', TimeEntryActivity.first.id
251 251 end
252 252 end
253 253
254 254 def test_index_should_rescue_invalid_sql_query
255 255 IssueQuery.any_instance.stubs(:statement).returns("INVALID STATEMENT")
256 256
257 257 get :index
258 258 assert_response 500
259 259 assert_tag 'p', :content => /An error occurred/
260 260 assert_nil session[:query]
261 261 assert_nil session[:issues_index_sort]
262 262 end
263 263 end
General Comments 0
You need to be logged in to leave comments. Login now