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

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