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.

activities_controller_test.rb 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../../test_helper', __FILE__)
  19. class ActivitiesControllerTest < Redmine::ControllerTest
  20. fixtures :projects, :trackers, :issue_statuses, :issues,
  21. :enumerations, :users, :issue_categories,
  22. :projects_trackers,
  23. :roles,
  24. :member_roles,
  25. :members,
  26. :groups_users,
  27. :enabled_modules,
  28. :journals, :journal_details
  29. def test_project_index
  30. get :index, :params => {
  31. :id => 1,
  32. :with_subprojects => 0
  33. }
  34. assert_response :success
  35. assert_select 'h3', :text => /#{2.days.ago.to_date.day}/
  36. assert_select 'dl dt.issue-edit a', :text => /(#{IssueStatus.find(2).name})/
  37. end
  38. def test_project_index_with_invalid_project_id_should_respond_404
  39. get :index, :params => {
  40. :id => 299
  41. }
  42. assert_response 404
  43. end
  44. def test_previous_project_index
  45. @request.session[:user_id] = 1
  46. get :index, :params => {
  47. :id => 1,
  48. :from => 2.days.ago.to_date
  49. }
  50. assert_response :success
  51. assert_select 'h3', :text => /#{User.current.time_to_date(3.days.ago).day}/
  52. assert_select 'dl dt.issue a', :text => /Cannot print recipes/
  53. end
  54. def test_global_index
  55. @request.session[:user_id] = 1
  56. get :index
  57. assert_response :success
  58. i5 = Issue.find(5)
  59. d5 = User.find(1).time_to_date(i5.created_on)
  60. assert_select 'h3', :text => /#{d5.day}/
  61. assert_select 'dl dt.issue a', :text => /Subproject issue/
  62. end
  63. def test_user_index
  64. @request.session[:user_id] = 1
  65. get :index, :params => {
  66. :user_id => 2
  67. }
  68. assert_response :success
  69. assert_select 'h2 a[href="/users/2"]', :text => 'John Smith'
  70. i1 = Issue.find(1)
  71. d1 = User.find(1).time_to_date(i1.created_on)
  72. assert_select 'h3', :text => /#{d1.day}/
  73. assert_select 'dl dt.issue a', :text => /Cannot print recipes/
  74. end
  75. def test_user_index_with_invalid_user_id_should_respond_404
  76. get :index, :params => {
  77. :user_id => 299
  78. }
  79. assert_response 404
  80. end
  81. def test_index_atom_feed
  82. get :index, :params => {
  83. :format => 'atom',
  84. :with_subprojects => 0
  85. }
  86. assert_response :success
  87. assert_select 'feed' do
  88. assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?with_subprojects=0'
  89. assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?with_subprojects=0'
  90. assert_select 'entry' do
  91. assert_select 'link[href=?]', 'http://test.host/issues/11'
  92. end
  93. end
  94. end
  95. def test_index_atom_feed_with_explicit_selection
  96. get :index, :params => {
  97. :format => 'atom',
  98. :with_subprojects => 0,
  99. :show_changesets => 1,
  100. :show_documents => 1,
  101. :show_files => 1,
  102. :show_issues => 1,
  103. :show_messages => 1,
  104. :show_news => 1,
  105. :show_time_entries => 1,
  106. :show_wiki_edits => 1
  107. }
  108. assert_response :success
  109. assert_select 'feed' do
  110. assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?show_changesets=1&show_documents=1&show_files=1&show_issues=1&show_messages=1&show_news=1&show_time_entries=1&show_wiki_edits=1&with_subprojects=0'
  111. assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?show_changesets=1&show_documents=1&show_files=1&show_issues=1&show_messages=1&show_news=1&show_time_entries=1&show_wiki_edits=1&with_subprojects=0'
  112. assert_select 'entry' do
  113. assert_select 'link[href=?]', 'http://test.host/issues/11'
  114. end
  115. end
  116. end
  117. def test_index_atom_feed_with_one_item_type
  118. with_settings :default_language => 'en' do
  119. get :index, :params => {
  120. :format => 'atom',
  121. :show_issues => '1'
  122. }
  123. assert_response :success
  124. assert_select 'title', :text => /Issues/
  125. end
  126. end
  127. def test_index_atom_feed_with_user
  128. get :index, :params => {
  129. :user_id => 2,
  130. :format => 'atom'
  131. }
  132. assert_response :success
  133. assert_select 'title', :text => "Redmine: #{User.find(2).name}"
  134. end
  135. def test_index_should_show_private_notes_with_permission_only
  136. journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes', :private_notes => true)
  137. @request.session[:user_id] = 2
  138. get :index
  139. assert_response :success
  140. assert_select 'dl', :text => /Private notes/
  141. Role.find(1).remove_permission! :view_private_notes
  142. get :index
  143. assert_response :success
  144. assert_select 'dl', :text => /Private notes/, :count => 0
  145. end
  146. def test_index_with_submitted_scope_should_save_as_preference
  147. @request.session[:user_id] = 2
  148. get :index, :params => {
  149. :show_issues => '1',
  150. :show_messages => '1',
  151. :submit => 'Apply'
  152. }
  153. assert_response :success
  154. assert_equal %w(issues messages), User.find(2).pref.activity_scope.sort
  155. end
  156. def test_index_scope_should_default_to_user_preference
  157. pref = User.find(2).pref
  158. pref.activity_scope = %w(issues news)
  159. pref.save!
  160. @request.session[:user_id] = 2
  161. get :index
  162. assert_response :success
  163. assert_select '#activity_scope_form' do
  164. assert_select 'input[checked=checked]', 2
  165. assert_select 'input[name=show_issues][checked=checked]'
  166. assert_select 'input[name=show_news][checked=checked]'
  167. end
  168. end
  169. def test_index_should_not_show_next_page_link
  170. @request.session[:user_id] = 2
  171. get :index
  172. assert_response :success
  173. assert_select '.pagination a', :text => /Previous/
  174. assert_select '.pagination a', :text => /Next/, :count => 0
  175. end
  176. def test_index_up_to_yesterday_should_show_next_page_link
  177. @request.session[:user_id] = 2
  178. get :index, :params => {
  179. :from => (User.find(2).today-1)
  180. }
  181. assert_response :success
  182. assert_select '.pagination a', :text => /Previous/
  183. assert_select '.pagination a', :text => /Next/
  184. end
  185. end