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.

context_menus_controller_test.rb 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2014 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 ContextMenusControllerTest < ActionController::TestCase
  19. fixtures :projects,
  20. :trackers,
  21. :projects_trackers,
  22. :roles,
  23. :member_roles,
  24. :members,
  25. :enabled_modules,
  26. :workflows,
  27. :journals, :journal_details,
  28. :versions,
  29. :issues, :issue_statuses, :issue_categories,
  30. :users,
  31. :enumerations,
  32. :time_entries
  33. def test_context_menu_one_issue
  34. @request.session[:user_id] = 2
  35. get :issues, :ids => [1]
  36. assert_response :success
  37. assert_template 'context_menu'
  38. assert_select 'a.icon-edit[href=?]', '/issues/1/edit', :text => 'Edit'
  39. assert_select 'a.icon-copy[href=?]', '/projects/ecookbook/issues/1/copy', :text => 'Copy'
  40. assert_select 'a.icon-del[href=?]', '/issues?ids%5B%5D=1', :text => 'Delete'
  41. # Statuses
  42. assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5', :text => 'Closed'
  43. assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8', :text => 'Immediate'
  44. # No inactive priorities
  45. assert_select 'a', :text => /Inactive Priority/, :count => 0
  46. # Versions
  47. assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3', :text => '2.0'
  48. assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4', :text => 'eCookbook Subproject 1 - 2.0'
  49. # Assignees
  50. assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3', :text => 'Dave Lopper'
  51. end
  52. def test_context_menu_one_issue_by_anonymous
  53. get :issues, :ids => [1]
  54. assert_response :success
  55. assert_template 'context_menu'
  56. assert_tag :tag => 'a', :content => 'Delete',
  57. :attributes => { :href => '#',
  58. :class => 'icon-del disabled' }
  59. end
  60. def test_context_menu_multiple_issues_of_same_project
  61. @request.session[:user_id] = 2
  62. get :issues, :ids => [1, 2]
  63. assert_response :success
  64. assert_template 'context_menu'
  65. assert_not_nil assigns(:issues)
  66. assert_equal [1, 2], assigns(:issues).map(&:id).sort
  67. ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
  68. assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
  69. assert_select 'a.icon-copy[href=?]', "/issues/bulk_edit?copy=1&amp;#{ids}", :text => 'Copy'
  70. assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
  71. assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
  72. assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
  73. assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3", :text => 'Dave Lopper'
  74. end
  75. def test_context_menu_multiple_issues_of_different_projects
  76. @request.session[:user_id] = 2
  77. get :issues, :ids => [1, 2, 6]
  78. assert_response :success
  79. assert_template 'context_menu'
  80. assert_not_nil assigns(:issues)
  81. assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
  82. ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
  83. assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
  84. assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
  85. assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
  86. assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
  87. assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2", :text => 'John Smith'
  88. end
  89. def test_context_menu_should_include_list_custom_fields
  90. field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
  91. :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
  92. @request.session[:user_id] = 2
  93. get :issues, :ids => [1]
  94. assert_select "li.cf_#{field.id}" do
  95. assert_select 'a[href=#]', :text => 'List'
  96. assert_select 'ul' do
  97. assert_select 'a', 3
  98. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo", :text => 'Foo'
  99. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
  100. end
  101. end
  102. end
  103. def test_context_menu_should_not_include_null_value_for_required_custom_fields
  104. field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
  105. :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
  106. @request.session[:user_id] = 2
  107. get :issues, :ids => [1, 2]
  108. assert_select "li.cf_#{field.id}" do
  109. assert_select 'a[href=#]', :text => 'List'
  110. assert_select 'ul' do
  111. assert_select 'a', 2
  112. assert_select 'a', :text => 'none', :count => 0
  113. end
  114. end
  115. end
  116. def test_context_menu_on_single_issue_should_select_current_custom_field_value
  117. field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
  118. :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
  119. issue = Issue.find(1)
  120. issue.custom_field_values = {field.id => 'Bar'}
  121. issue.save!
  122. @request.session[:user_id] = 2
  123. get :issues, :ids => [1]
  124. assert_select "li.cf_#{field.id}" do
  125. assert_select 'a[href=#]', :text => 'List'
  126. assert_select 'ul' do
  127. assert_select 'a', 3
  128. assert_select 'a.icon-checked', :text => 'Bar'
  129. end
  130. end
  131. end
  132. def test_context_menu_should_include_bool_custom_fields
  133. field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
  134. :is_for_all => true, :tracker_ids => [1, 2, 3])
  135. @request.session[:user_id] = 2
  136. get :issues, :ids => [1]
  137. assert_select "li.cf_#{field.id}" do
  138. assert_select 'a[href=#]', :text => 'Bool'
  139. assert_select 'ul' do
  140. assert_select 'a', 3
  141. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=0", :text => 'No'
  142. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1", :text => 'Yes'
  143. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
  144. end
  145. end
  146. end
  147. def test_context_menu_should_include_user_custom_fields
  148. field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
  149. :is_for_all => true, :tracker_ids => [1, 2, 3])
  150. @request.session[:user_id] = 2
  151. get :issues, :ids => [1]
  152. assert_select "li.cf_#{field.id}" do
  153. assert_select 'a[href=#]', :text => 'User'
  154. assert_select 'ul' do
  155. assert_select 'a', Project.find(1).members.count + 1
  156. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2", :text => 'John Smith'
  157. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
  158. end
  159. end
  160. end
  161. def test_context_menu_should_include_version_custom_fields
  162. field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
  163. @request.session[:user_id] = 2
  164. get :issues, :ids => [1]
  165. assert_select "li.cf_#{field.id}" do
  166. assert_select 'a[href=#]', :text => 'Version'
  167. assert_select 'ul' do
  168. assert_select 'a', Project.find(1).shared_versions.count + 1
  169. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3", :text => '2.0'
  170. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
  171. end
  172. end
  173. end
  174. def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
  175. @request.session[:user_id] = 2
  176. get :issues, :ids => [1]
  177. assert_response :success
  178. assert_template 'context_menu'
  179. assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2', :text => / me /
  180. end
  181. def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects
  182. @request.session[:user_id] = 2
  183. version = Version.create!(:name => 'Shared', :sharing => 'system', :project_id => 1)
  184. get :issues, :ids => [1, 4]
  185. assert_response :success
  186. assert_template 'context_menu'
  187. assert_include version, assigns(:versions)
  188. assert_select 'a', :text => 'eCookbook - Shared'
  189. end
  190. def test_context_menu_with_issue_that_is_not_visible_should_fail
  191. get :issues, :ids => [1, 4] # issue 4 is not visible
  192. assert_response 302
  193. end
  194. def test_should_respond_with_404_without_ids
  195. get :issues
  196. assert_response 404
  197. end
  198. def test_time_entries_context_menu
  199. @request.session[:user_id] = 2
  200. get :time_entries, :ids => [1, 2]
  201. assert_response :success
  202. assert_template 'time_entries'
  203. assert_select 'a:not(.disabled)', :text => 'Edit'
  204. end
  205. def test_time_entries_context_menu_without_edit_permission
  206. @request.session[:user_id] = 2
  207. Role.find_by_name('Manager').remove_permission! :edit_time_entries
  208. get :time_entries, :ids => [1, 2]
  209. assert_response :success
  210. assert_template 'time_entries'
  211. assert_select 'a.disabled', :text => 'Edit'
  212. end
  213. end