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_test.rb 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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. class IssuesTest < Redmine::IntegrationTest
  19. fixtures :projects,
  20. :users, :email_addresses,
  21. :roles,
  22. :members,
  23. :member_roles,
  24. :trackers,
  25. :projects_trackers,
  26. :enabled_modules,
  27. :issue_statuses,
  28. :issues,
  29. :enumerations,
  30. :custom_fields,
  31. :custom_values,
  32. :custom_fields_trackers,
  33. :attachments
  34. # create an issue
  35. def test_add_issue
  36. log_user('jsmith', 'jsmith')
  37. get '/projects/ecookbook/issues/new'
  38. assert_response :success
  39. issue = new_record(Issue) do
  40. post '/projects/ecookbook/issues', :params => {
  41. :issue => {
  42. :tracker_id => "1",
  43. :start_date => "2006-12-26",
  44. :priority_id => "4",
  45. :subject => "new test issue",
  46. :category_id => "",
  47. :description => "new issue",
  48. :done_ratio => "0",
  49. :due_date => "",
  50. :assigned_to_id => "",
  51. :custom_field_values => {'2' => 'Value for field 2'}
  52. }
  53. }
  54. end
  55. # check redirection
  56. assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
  57. follow_redirect!
  58. # check issue attributes
  59. assert_equal 'jsmith', issue.author.login
  60. assert_equal 1, issue.project.id
  61. assert_equal 1, issue.status.id
  62. end
  63. def test_create_issue_by_anonymous_without_permission_should_fail
  64. Role.anonymous.remove_permission! :add_issues
  65. assert_no_difference 'Issue.count' do
  66. post '/projects/1/issues', :params => {
  67. :issue => {
  68. :tracker_id => "1",
  69. :subject => "new test issue"
  70. }
  71. }
  72. end
  73. assert_response 302
  74. end
  75. def test_create_issue_by_anonymous_with_custom_permission_should_succeed
  76. Role.anonymous.remove_permission! :add_issues
  77. Member.create!(:project_id => 1, :principal => Group.anonymous, :role_ids => [3])
  78. issue = new_record(Issue) do
  79. post '/projects/1/issues', :params => {
  80. :issue => {
  81. :tracker_id => "1",
  82. :subject => "new test issue"
  83. }
  84. }
  85. assert_response 302
  86. end
  87. assert_equal User.anonymous, issue.author
  88. end
  89. # add then remove 2 attachments to an issue
  90. def test_issue_attachments
  91. log_user('jsmith', 'jsmith')
  92. set_tmp_attachments_directory
  93. attachment = new_record(Attachment) do
  94. put '/issues/1', :params => {
  95. :issue => {:notes => 'Some notes'},
  96. :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
  97. }
  98. assert_redirected_to "/issues/1"
  99. end
  100. assert_equal Issue.find(1), attachment.container
  101. assert_equal 'testfile.txt', attachment.filename
  102. assert_equal 'This is an attachment', attachment.description
  103. # verify the size of the attachment stored in db
  104. #assert_equal file_data_1.length, attachment.filesize
  105. # verify that the attachment was written to disk
  106. assert File.exist?(attachment.diskfile)
  107. # remove the attachments
  108. Issue.find(1).attachments.each(&:destroy)
  109. assert_equal 0, Issue.find(1).attachments.length
  110. end
  111. def test_next_and_previous_links_should_be_displayed_after_query_grouped_and_sorted_by_version
  112. with_settings :default_language => 'en' do
  113. get '/projects/ecookbook/issues?set_filter=1&group_by=fixed_version&sort=priority:desc,fixed_version,id'
  114. assert_response :success
  115. assert_select 'td.id', :text => '5'
  116. get '/issues/5'
  117. assert_response :success
  118. assert_select '.next-prev-links .position', :text => '5 of 6'
  119. end
  120. end
  121. def test_next_and_previous_links_should_be_displayed_after_filter
  122. with_settings :default_language => 'en' do
  123. get '/projects/ecookbook/issues?set_filter=1&tracker_id=1'
  124. assert_response :success
  125. assert_select 'td.id', :text => '5'
  126. get '/issues/5'
  127. assert_response :success
  128. assert_select '.next-prev-links .position', :text => '3 of 5'
  129. assert_select '.next-prev-links .position a[href^=?]', '/projects/ecookbook/issues?'
  130. end
  131. end
  132. def test_next_and_previous_links_should_be_displayed_after_saved_query
  133. query = IssueQuery.create!(:name => 'Calendar Query',
  134. :visibility => IssueQuery::VISIBILITY_PUBLIC,
  135. :filters => {'tracker_id' => {:operator => '=', :values => ['1']}}
  136. )
  137. with_settings :default_language => 'en' do
  138. get "/projects/ecookbook/issues?set_filter=1&query_id=#{query.id}"
  139. assert_response :success
  140. assert_select 'td.id', :text => '5'
  141. get '/issues/5'
  142. assert_response :success
  143. assert_select '.next-prev-links .position', :text => '6 of 8'
  144. end
  145. end
  146. def test_other_formats_links_on_index
  147. get '/projects/ecookbook/issues'
  148. %w(Atom PDF CSV).each do |format|
  149. assert_select 'a[rel=nofollow][href=?]', "/projects/ecookbook/issues.#{format.downcase}", :text => format
  150. end
  151. end
  152. def test_other_formats_links_on_index_without_project_id_in_url
  153. get '/issues', :params => {
  154. :project_id => 'ecookbook'
  155. }
  156. %w(Atom PDF CSV).each do |format|
  157. assert_select 'a[rel=nofollow][href=?]', "/issues.#{format.downcase}?project_id=ecookbook", :text => format
  158. end
  159. end
  160. def test_pagination_links_on_index
  161. with_settings :per_page_options => '2' do
  162. get '/projects/ecookbook/issues'
  163. assert_select 'a[href=?]', '/projects/ecookbook/issues?page=2', :text => '2'
  164. end
  165. end
  166. def test_pagination_links_should_preserve_query_parameters
  167. with_settings :per_page_options => '2' do
  168. get '/projects/ecookbook/issues?foo=bar'
  169. assert_select 'a[href=?]', '/projects/ecookbook/issues?foo=bar&page=2', :text => '2'
  170. end
  171. end
  172. def test_pagination_links_should_not_use_params_as_url_options
  173. with_settings :per_page_options => '2' do
  174. get '/projects/ecookbook/issues?host=foo'
  175. assert_select 'a[href=?]', '/projects/ecookbook/issues?host=foo&page=2', :text => '2'
  176. end
  177. end
  178. def test_sort_links_on_index
  179. get '/projects/ecookbook/issues'
  180. assert_select 'a[href=?]', '/projects/ecookbook/issues?sort=subject%2Cid%3Adesc', :text => 'Subject'
  181. end
  182. def test_sort_links_should_preserve_query_parameters
  183. get '/projects/ecookbook/issues?foo=bar'
  184. assert_select 'a[href=?]', '/projects/ecookbook/issues?foo=bar&sort=subject%2Cid%3Adesc', :text => 'Subject'
  185. end
  186. def test_sort_links_should_not_use_params_as_url_options
  187. get '/projects/ecookbook/issues?host=foo'
  188. assert_select 'a[href=?]', '/projects/ecookbook/issues?host=foo&sort=subject%2Cid%3Adesc', :text => 'Subject'
  189. end
  190. def test_issue_with_user_custom_field
  191. @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
  192. Role.anonymous.add_permission! :add_issues, :edit_issues
  193. users = Project.find(1).users.sort
  194. tester = users.first
  195. # Issue form
  196. get '/projects/ecookbook/issues/new'
  197. assert_response :success
  198. assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
  199. assert_select 'option', users.size + 1 # +1 for blank value
  200. assert_select 'option[value=?]', tester.id.to_s, :text => tester.name
  201. end
  202. # Create issue
  203. issue = new_record(Issue) do
  204. post '/projects/ecookbook/issues', :params => {
  205. :issue => {
  206. :tracker_id => '1',
  207. :priority_id => '4',
  208. :subject => 'Issue with user custom field',
  209. :custom_field_values => {@field.id.to_s => users.first.id.to_s}
  210. }
  211. }
  212. assert_response 302
  213. end
  214. # Issue view
  215. follow_redirect!
  216. assert_select ".cf_#{@field.id}" do
  217. assert_select '.label', :text => 'Tester:'
  218. assert_select '.value', :text => tester.name
  219. end
  220. assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
  221. assert_select 'option', users.size + 1 # +1 for blank value
  222. assert_select 'option[value=?][selected=selected]', tester.id.to_s, :text => tester.name
  223. end
  224. new_tester = users[1]
  225. with_settings :default_language => 'en' do
  226. # Update issue
  227. assert_difference 'Journal.count' do
  228. put "/issues/#{issue.id}", :params => {
  229. :issue => {
  230. :notes => 'Updating custom field',
  231. :custom_field_values => {@field.id.to_s => new_tester.id.to_s}
  232. }
  233. }
  234. assert_redirected_to "/issues/#{issue.id}"
  235. end
  236. # Issue view
  237. follow_redirect!
  238. assert_select 'ul.details li', :text => "Tester changed from #{tester} to #{new_tester}"
  239. end
  240. end
  241. def test_update_using_invalid_http_verbs
  242. log_user('jsmith', 'jsmith')
  243. subject = 'Updated by an invalid http verb'
  244. get '/issues/update/1', :params => {:issue => {:subject => subject}}
  245. assert_response 404
  246. assert_not_equal subject, Issue.find(1).subject
  247. post '/issues/1', :params => {:issue => {:subject => subject}}
  248. assert_response 404
  249. assert_not_equal subject, Issue.find(1).subject
  250. end
  251. def test_get_watch_should_be_invalid
  252. log_user('jsmith', 'jsmith')
  253. assert_no_difference 'Watcher.count' do
  254. get '/watchers/watch?object_type=issue&object_id=1'
  255. assert_response 404
  256. end
  257. end
  258. end