You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

issues_controller_transaction_test.rb 9.3KB

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