##// END OF EJS Templates
Test moved to tests with transactional fixtures disabled....
Jean-Philippe Lang -
r10415:31ee1d22eb89
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
@@ -1,247 +1,265
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 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 fixtures :projects,
23 23 :users,
24 24 :roles,
25 25 :members,
26 26 :member_roles,
27 27 :issues,
28 28 :issue_statuses,
29 29 :versions,
30 30 :trackers,
31 31 :projects_trackers,
32 32 :issue_categories,
33 33 :enabled_modules,
34 34 :enumerations,
35 35 :attachments,
36 36 :workflows,
37 37 :custom_fields,
38 38 :custom_values,
39 39 :custom_fields_projects,
40 40 :custom_fields_trackers,
41 41 :time_entries,
42 42 :journals,
43 43 :journal_details,
44 44 :queries
45 45
46 46 self.use_transactional_fixtures = false
47 47
48 48 def setup
49 49 @controller = IssuesController.new
50 50 @request = ActionController::TestRequest.new
51 51 @response = ActionController::TestResponse.new
52 52 User.current = nil
53 53 end
54 54
55 55 def test_update_stale_issue_should_not_update_the_issue
56 56 issue = Issue.find(2)
57 57 @request.session[:user_id] = 2
58 58
59 59 assert_no_difference 'Journal.count' do
60 60 assert_no_difference 'TimeEntry.count' do
61 61 put :update,
62 62 :id => issue.id,
63 63 :issue => {
64 64 :fixed_version_id => 4,
65 65 :notes => 'My notes',
66 66 :lock_version => (issue.lock_version - 1)
67 67 },
68 68 :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id }
69 69 end
70 70 end
71 71
72 72 assert_response :success
73 73 assert_template 'edit'
74 74
75 75 assert_select 'div.conflict'
76 76 assert_select 'input[name=?][value=?]', 'conflict_resolution', 'overwrite'
77 77 assert_select 'input[name=?][value=?]', 'conflict_resolution', 'add_notes'
78 78 assert_select 'label' do
79 79 assert_select 'input[name=?][value=?]', 'conflict_resolution', 'cancel'
80 80 assert_select 'a[href=/issues/2]'
81 81 end
82 82 end
83 83
84 84 def test_update_stale_issue_should_save_attachments
85 85 set_tmp_attachments_directory
86 86 issue = Issue.find(2)
87 87 @request.session[:user_id] = 2
88 88
89 89 assert_no_difference 'Journal.count' do
90 90 assert_no_difference 'TimeEntry.count' do
91 91 assert_difference 'Attachment.count' do
92 92 put :update,
93 93 :id => issue.id,
94 94 :issue => {
95 95 :fixed_version_id => 4,
96 96 :notes => 'My notes',
97 97 :lock_version => (issue.lock_version - 1)
98 98 },
99 99 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}},
100 100 :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id }
101 101 end
102 102 end
103 103 end
104 104
105 105 assert_response :success
106 106 assert_template 'edit'
107 107 attachment = Attachment.first(:order => 'id DESC')
108 108 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
109 109 assert_tag 'span', :content => /testfile.txt/
110 110 end
111 111
112 112 def test_update_stale_issue_without_notes_should_not_show_add_notes_option
113 113 issue = Issue.find(2)
114 114 @request.session[:user_id] = 2
115 115
116 116 put :update, :id => issue.id,
117 117 :issue => {
118 118 :fixed_version_id => 4,
119 119 :notes => '',
120 120 :lock_version => (issue.lock_version - 1)
121 121 }
122 122
123 123 assert_tag 'div', :attributes => {:class => 'conflict'}
124 124 assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'overwrite'}
125 125 assert_no_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'add_notes'}
126 126 assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'cancel'}
127 127 end
128 128
129 129 def test_update_stale_issue_should_show_conflicting_journals
130 130 @request.session[:user_id] = 2
131 131
132 132 put :update, :id => 1,
133 133 :issue => {
134 134 :fixed_version_id => 4,
135 135 :notes => '',
136 136 :lock_version => 2
137 137 },
138 138 :last_journal_id => 1
139 139
140 140 assert_not_nil assigns(:conflict_journals)
141 141 assert_equal 1, assigns(:conflict_journals).size
142 142 assert_equal 2, assigns(:conflict_journals).first.id
143 143 assert_tag 'div', :attributes => {:class => 'conflict'},
144 144 :descendant => {:content => /Some notes with Redmine links/}
145 145 end
146 146
147 147 def test_update_stale_issue_without_previous_journal_should_show_all_journals
148 148 @request.session[:user_id] = 2
149 149
150 150 put :update, :id => 1,
151 151 :issue => {
152 152 :fixed_version_id => 4,
153 153 :notes => '',
154 154 :lock_version => 2
155 155 },
156 156 :last_journal_id => ''
157 157
158 158 assert_not_nil assigns(:conflict_journals)
159 159 assert_equal 2, assigns(:conflict_journals).size
160 160 assert_tag 'div', :attributes => {:class => 'conflict'},
161 161 :descendant => {:content => /Some notes with Redmine links/}
162 162 assert_tag 'div', :attributes => {:class => 'conflict'},
163 163 :descendant => {:content => /Journal notes/}
164 164 end
165 165
166 166 def test_update_stale_issue_should_show_private_journals_with_permission_only
167 167 journal = Journal.create!(:journalized => Issue.find(1), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
168 168
169 169 @request.session[:user_id] = 2
170 170 put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => ''
171 171 assert_include journal, assigns(:conflict_journals)
172 172
173 173 Role.find(1).remove_permission! :view_private_notes
174 174 put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => ''
175 175 assert_not_include journal, assigns(:conflict_journals)
176 176 end
177 177
178 178 def test_update_stale_issue_with_overwrite_conflict_resolution_should_update
179 179 @request.session[:user_id] = 2
180 180
181 181 assert_difference 'Journal.count' do
182 182 put :update, :id => 1,
183 183 :issue => {
184 184 :fixed_version_id => 4,
185 185 :notes => 'overwrite_conflict_resolution',
186 186 :lock_version => 2
187 187 },
188 188 :conflict_resolution => 'overwrite'
189 189 end
190 190
191 191 assert_response 302
192 192 issue = Issue.find(1)
193 193 assert_equal 4, issue.fixed_version_id
194 194 journal = Journal.first(:order => 'id DESC')
195 195 assert_equal 'overwrite_conflict_resolution', journal.notes
196 196 assert journal.details.any?
197 197 end
198 198
199 199 def test_update_stale_issue_with_add_notes_conflict_resolution_should_update
200 200 @request.session[:user_id] = 2
201 201
202 202 assert_difference 'Journal.count' do
203 203 put :update, :id => 1,
204 204 :issue => {
205 205 :fixed_version_id => 4,
206 206 :notes => 'add_notes_conflict_resolution',
207 207 :lock_version => 2
208 208 },
209 209 :conflict_resolution => 'add_notes'
210 210 end
211 211
212 212 assert_response 302
213 213 issue = Issue.find(1)
214 214 assert_nil issue.fixed_version_id
215 215 journal = Journal.first(:order => 'id DESC')
216 216 assert_equal 'add_notes_conflict_resolution', journal.notes
217 217 assert journal.details.empty?
218 218 end
219 219
220 220 def test_update_stale_issue_with_cancel_conflict_resolution_should_redirect_without_updating
221 221 @request.session[:user_id] = 2
222 222
223 223 assert_no_difference 'Journal.count' do
224 224 put :update, :id => 1,
225 225 :issue => {
226 226 :fixed_version_id => 4,
227 227 :notes => 'add_notes_conflict_resolution',
228 228 :lock_version => 2
229 229 },
230 230 :conflict_resolution => 'cancel'
231 231 end
232 232
233 233 assert_redirected_to '/issues/1'
234 234 issue = Issue.find(1)
235 235 assert_nil issue.fixed_version_id
236 236 end
237 237
238 def test_put_update_with_spent_time_and_failure_should_not_add_spent_time
239 @request.session[:user_id] = 2
240
241 assert_no_difference('TimeEntry.count') do
242 put :update,
243 :id => 1,
244 :issue => { :subject => '' },
245 :time_entry => { :hours => '2.5', :comments => 'should not be added', :activity_id => TimeEntryActivity.first.id }
246 assert_response :success
247 end
248
249 assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2.5'
250 assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'should not be added'
251 assert_select 'select[name=?]', 'time_entry[activity_id]' do
252 assert_select 'option[value=?][selected=selected]', TimeEntryActivity.first.id
253 end
254 end
255
238 256 def test_index_should_rescue_invalid_sql_query
239 257 Query.any_instance.stubs(:statement).returns("INVALID STATEMENT")
240 258
241 259 get :index
242 260 assert_response 500
243 261 assert_tag 'p', :content => /An error occurred/
244 262 assert_nil session[:query]
245 263 assert_nil session[:issues_index_sort]
246 264 end
247 265 end
General Comments 0
You need to be logged in to leave comments. Login now