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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 ActivitiesControllerTest < Redmine::ControllerTest
  19. fixtures :projects, :trackers, :issue_statuses, :issues,
  20. :enumerations, :users, :issue_categories,
  21. :projects_trackers,
  22. :roles,
  23. :member_roles,
  24. :members,
  25. :groups_users,
  26. :enabled_modules,
  27. :journals, :journal_details
  28. def test_project_index
  29. get :index, :params => {
  30. :id => 1,
  31. :with_subprojects => 0
  32. }
  33. assert_response :success
  34. assert_select 'h3', :text => /#{2.days.ago.to_date.day}/
  35. assert_select 'dl dt.issue-edit a', :text => /(#{IssueStatus.find(2).name})/
  36. end
  37. def test_project_index_with_invalid_project_id_should_respond_404
  38. get :index, :params => {
  39. :id => 299
  40. }
  41. assert_response 404
  42. end
  43. def test_previous_project_index
  44. get :index, :params => {
  45. :id => 1,
  46. :from => 2.days.ago.to_date
  47. }
  48. assert_response :success
  49. assert_select 'h3', :text => /#{3.days.ago.to_date.day}/
  50. assert_select 'dl dt.issue a', :text => /Cannot print recipes/
  51. end
  52. def test_global_index
  53. @request.session[:user_id] = 1
  54. get :index
  55. assert_response :success
  56. i5 = Issue.find(5)
  57. d5 = User.find(1).time_to_date(i5.created_on)
  58. assert_select 'h3', :text => /#{d5.day}/
  59. assert_select 'dl dt.issue a', :text => /Subproject issue/
  60. end
  61. def test_user_index
  62. @request.session[:user_id] = 1
  63. get :index, :params => {
  64. :user_id => 2
  65. }
  66. assert_response :success
  67. assert_select 'h2 a[href="/users/2"]', :text => 'John Smith'
  68. i1 = Issue.find(1)
  69. d1 = User.find(1).time_to_date(i1.created_on)
  70. assert_select 'h3', :text => /#{d1.day}/
  71. assert_select 'dl dt.issue a', :text => /Cannot print recipes/
  72. end
  73. def test_user_index_with_invalid_user_id_should_respond_404
  74. get :index, :params => {
  75. :user_id => 299
  76. }
  77. assert_response 404
  78. end
  79. def test_index_atom_feed
  80. get :index, :params => {
  81. :format => 'atom',
  82. :with_subprojects => 0
  83. }
  84. assert_response :success
  85. assert_select 'feed' do
  86. assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?with_subprojects=0'
  87. assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?with_subprojects=0'
  88. assert_select 'entry' do
  89. assert_select 'link[href=?]', 'http://test.host/issues/11'
  90. end
  91. end
  92. end
  93. def test_index_atom_feed_with_explicit_selection
  94. get :index, :params => {
  95. :format => 'atom',
  96. :with_subprojects => 0,
  97. :show_changesets => 1,
  98. :show_documents => 1,
  99. :show_files => 1,
  100. :show_issues => 1,
  101. :show_messages => 1,
  102. :show_news => 1,
  103. :show_time_entries => 1,
  104. :show_wiki_edits => 1
  105. }
  106. assert_response :success
  107. assert_select 'feed' do
  108. 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'
  109. 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'
  110. assert_select 'entry' do
  111. assert_select 'link[href=?]', 'http://test.host/issues/11'
  112. end
  113. end
  114. end
  115. def test_index_atom_feed_with_one_item_type
  116. with_settings :default_language => 'en' do
  117. get :index, :params => {
  118. :format => 'atom',
  119. :show_issues => '1'
  120. }
  121. assert_response :success
  122. assert_select 'title', :text => /Issues/
  123. end
  124. end
  125. def test_index_atom_feed_with_user
  126. get :index, :params => {
  127. :user_id => 2,
  128. :format => 'atom'
  129. }
  130. assert_response :success
  131. assert_select 'title', :text => "Redmine: #{User.find(2).name}"
  132. end
  133. def test_index_should_show_private_notes_with_permission_only
  134. journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes', :private_notes => true)
  135. @request.session[:user_id] = 2
  136. get :index
  137. assert_response :success
  138. assert_select 'dl', :text => /Private notes/
  139. Role.find(1).remove_permission! :view_private_notes
  140. get :index
  141. assert_response :success
  142. assert_select 'dl', :text => /Private notes/, :count => 0
  143. end
  144. def test_index_with_submitted_scope_should_save_as_preference
  145. @request.session[:user_id] = 2
  146. get :index, :params => {
  147. :show_issues => '1',
  148. :show_messages => '1',
  149. :submit => 'Apply'
  150. }
  151. assert_response :success
  152. assert_equal %w(issues messages), User.find(2).pref.activity_scope.sort
  153. end
  154. def test_index_scope_should_default_to_user_preference
  155. pref = User.find(2).pref
  156. pref.activity_scope = %w(issues news)
  157. pref.save!
  158. @request.session[:user_id] = 2
  159. get :index
  160. assert_response :success
  161. assert_select '#activity_scope_form' do
  162. assert_select 'input[checked=checked]', 2
  163. assert_select 'input[name=show_issues][checked=checked]'
  164. assert_select 'input[name=show_news][checked=checked]'
  165. end
  166. end
  167. def test_index_should_not_show_next_page_link
  168. @request.session[:user_id] = 2
  169. get :index
  170. assert_response :success
  171. assert_select '.pagination a', :text => /Previous/
  172. assert_select '.pagination a', :text => /Next/, :count => 0
  173. end
  174. def test_index_up_to_yesterday_should_show_next_page_link
  175. @request.session[:user_id] = 2
  176. get :index, :params => {
  177. :from => (User.find(2).today-1)
  178. }
  179. assert_response :success
  180. assert_select '.pagination a', :text => /Previous/
  181. assert_select '.pagination a', :text => /Next/
  182. end
  183. end