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 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2015 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 < ActionController::TestCase
  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_template 'edit'
  65. assert_select 'div.conflict'
  66. assert_select 'input[name=?][value=?]', 'conflict_resolution', 'overwrite'
  67. assert_select 'input[name=?][value=?]', 'conflict_resolution', 'add_notes'
  68. assert_select 'label' do
  69. assert_select 'input[name=?][value=?]', 'conflict_resolution', 'cancel'
  70. assert_select 'a[href="/issues/2"]'
  71. end
  72. end
  73. def test_update_stale_issue_should_save_attachments
  74. set_tmp_attachments_directory
  75. issue = Issue.find(2)
  76. @request.session[:user_id] = 2
  77. assert_no_difference 'Journal.count' do
  78. assert_no_difference 'TimeEntry.count' do
  79. assert_difference 'Attachment.count' do
  80. put :update,
  81. :id => issue.id,
  82. :issue => {
  83. :fixed_version_id => 4,
  84. :notes => 'My notes',
  85. :lock_version => (issue.lock_version - 1)
  86. },
  87. :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}},
  88. :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id }
  89. end
  90. end
  91. end
  92. assert_response :success
  93. assert_template 'edit'
  94. attachment = Attachment.order('id DESC').first
  95. assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
  96. assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
  97. end
  98. def test_update_stale_issue_without_notes_should_not_show_add_notes_option
  99. issue = Issue.find(2)
  100. @request.session[:user_id] = 2
  101. put :update, :id => issue.id,
  102. :issue => {
  103. :fixed_version_id => 4,
  104. :notes => '',
  105. :lock_version => (issue.lock_version - 1)
  106. }
  107. assert_select 'div.conflict'
  108. assert_select 'input[name=conflict_resolution][value=overwrite]'
  109. assert_select 'input[name=conflict_resolution][value=add_notes]', 0
  110. assert_select 'input[name=conflict_resolution][value=cancel]'
  111. end
  112. def test_update_stale_issue_should_show_conflicting_journals
  113. @request.session[:user_id] = 2
  114. put :update, :id => 1,
  115. :issue => {
  116. :fixed_version_id => 4,
  117. :notes => '',
  118. :lock_version => 2
  119. },
  120. :last_journal_id => 1
  121. assert_not_nil assigns(:conflict_journals)
  122. assert_equal 1, assigns(:conflict_journals).size
  123. assert_equal 2, assigns(:conflict_journals).first.id
  124. assert_select 'div.conflict', :text => /Some notes with Redmine links/
  125. end
  126. def test_update_stale_issue_without_previous_journal_should_show_all_journals
  127. @request.session[:user_id] = 2
  128. put :update, :id => 1,
  129. :issue => {
  130. :fixed_version_id => 4,
  131. :notes => '',
  132. :lock_version => 2
  133. },
  134. :last_journal_id => ''
  135. assert_not_nil assigns(:conflict_journals)
  136. assert_equal 2, assigns(:conflict_journals).size
  137. assert_select 'div.conflict', :text => /Some notes with Redmine links/
  138. assert_select 'div.conflict', :text => /Journal notes/
  139. end
  140. def test_update_stale_issue_should_show_private_journals_with_permission_only
  141. journal = Journal.create!(:journalized => Issue.find(1), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
  142. @request.session[:user_id] = 2
  143. put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => ''
  144. assert_include journal, assigns(:conflict_journals)
  145. Role.find(1).remove_permission! :view_private_notes
  146. put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => ''
  147. assert_not_include journal, assigns(:conflict_journals)
  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 journal.details.empty?
  184. end
  185. def test_update_stale_issue_with_cancel_conflict_resolution_should_redirect_without_updating
  186. @request.session[:user_id] = 2
  187. assert_no_difference 'Journal.count' do
  188. put :update, :id => 1,
  189. :issue => {
  190. :fixed_version_id => 4,
  191. :notes => 'add_notes_conflict_resolution',
  192. :lock_version => 2
  193. },
  194. :conflict_resolution => 'cancel'
  195. end
  196. assert_redirected_to '/issues/1'
  197. issue = Issue.find(1)
  198. assert_nil issue.fixed_version_id
  199. end
  200. def test_put_update_with_spent_time_and_failure_should_not_add_spent_time
  201. @request.session[:user_id] = 2
  202. assert_no_difference('TimeEntry.count') do
  203. put :update,
  204. :id => 1,
  205. :issue => { :subject => '' },
  206. :time_entry => { :hours => '2.5', :comments => 'should not be added', :activity_id => TimeEntryActivity.first.id }
  207. assert_response :success
  208. end
  209. assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2.5'
  210. assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'should not be added'
  211. assert_select 'select[name=?]', 'time_entry[activity_id]' do
  212. assert_select 'option[value=?][selected=selected]', TimeEntryActivity.first.id.to_s
  213. end
  214. end
  215. def test_index_should_rescue_invalid_sql_query
  216. IssueQuery.any_instance.stubs(:statement).returns("INVALID STATEMENT")
  217. get :index
  218. assert_response 500
  219. assert_select 'p', :text => /An error occurred/
  220. assert_nil session[:query]
  221. assert_nil session[:issues_index_sort]
  222. end
  223. end