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.

activity_test.rb 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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 ActivityTest < ActiveSupport::TestCase
  19. fixtures :projects, :versions, :attachments, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
  20. :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, :time_entries,
  21. :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
  22. def setup
  23. @project = Project.find(1)
  24. end
  25. def test_activity_without_subprojects
  26. events = find_events(User.anonymous, :project => @project)
  27. assert_not_nil events
  28. assert events.include?(Issue.find(1))
  29. assert !events.include?(Issue.find(4))
  30. # subproject issue
  31. assert !events.include?(Issue.find(5))
  32. end
  33. def test_activity_with_subprojects
  34. events = find_events(User.anonymous, :project => @project, :with_subprojects => 1)
  35. assert_not_nil events
  36. assert events.include?(Issue.find(1))
  37. # subproject issue
  38. assert events.include?(Issue.find(5))
  39. end
  40. def test_global_activity_anonymous
  41. events = find_events(User.anonymous)
  42. assert_not_nil events
  43. assert events.include?(Issue.find(1))
  44. assert events.include?(Message.find(5))
  45. # Issue of a private project
  46. assert !events.include?(Issue.find(4))
  47. # Private issue and comment
  48. assert !events.include?(Issue.find(14))
  49. assert !events.include?(Journal.find(5))
  50. end
  51. def test_global_activity_logged_user
  52. events = find_events(User.find(2)) # manager
  53. assert_not_nil events
  54. assert events.include?(Issue.find(1))
  55. # Issue of a private project the user belongs to
  56. assert events.include?(Issue.find(4))
  57. end
  58. def test_user_activity
  59. user = User.find(2)
  60. events = Redmine::Activity::Fetcher.new(User.anonymous, :author => user).events(nil, nil, :limit => 10)
  61. assert(events.size > 0)
  62. assert(events.size <= 10)
  63. assert_nil(events.detect {|e| e.event_author != user})
  64. end
  65. def test_files_activity
  66. f = Redmine::Activity::Fetcher.new(User.anonymous, :project => Project.find(1))
  67. f.scope = ['files']
  68. events = f.events
  69. assert_kind_of Array, events
  70. assert events.include?(Attachment.find_by_container_type_and_container_id('Project', 1))
  71. assert events.include?(Attachment.find_by_container_type_and_container_id('Version', 1))
  72. assert_equal [Attachment], events.collect(&:class).uniq
  73. assert_equal %w(Project Version), events.collect(&:container_type).uniq.sort
  74. end
  75. def test_event_group_for_issue
  76. issue = Issue.find(1)
  77. assert_equal issue, issue.event_group
  78. end
  79. def test_event_group_for_journal
  80. issue = Issue.find(1)
  81. journal = issue.journals.first
  82. assert_equal issue, journal.event_group
  83. end
  84. def test_event_group_for_issue_time_entry
  85. time = TimeEntry.where(:issue_id => 1).first
  86. assert_equal time.issue, time.event_group
  87. end
  88. def test_event_group_for_project_time_entry
  89. time = TimeEntry.where(:issue_id => nil).first
  90. assert_equal time, time.event_group
  91. end
  92. def test_event_group_for_message
  93. message = Message.find(1)
  94. reply = message.children.first
  95. assert_equal message, message.event_group
  96. assert_equal message, reply.event_group
  97. end
  98. def test_event_group_for_wiki_content_version
  99. content = WikiContent::Version.find(1)
  100. assert_equal content.page, content.event_group
  101. end
  102. private
  103. def find_events(user, options={})
  104. Redmine::Activity::Fetcher.new(user, options).events(Date.today - 30, Date.today + 1)
  105. end
  106. end