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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 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
  21. def setup
  22. @project = Project.find(1)
  23. end
  24. def test_activity_without_subprojects
  25. events = find_events(User.anonymous, :project => @project)
  26. assert_not_nil events
  27. assert events.include?(Issue.find(1))
  28. assert !events.include?(Issue.find(4))
  29. # subproject issue
  30. assert !events.include?(Issue.find(5))
  31. end
  32. def test_activity_with_subprojects
  33. events = find_events(User.anonymous, :project => @project, :with_subprojects => 1)
  34. assert_not_nil events
  35. assert events.include?(Issue.find(1))
  36. # subproject issue
  37. assert events.include?(Issue.find(5))
  38. end
  39. def test_global_activity_anonymous
  40. events = find_events(User.anonymous)
  41. assert_not_nil events
  42. assert events.include?(Issue.find(1))
  43. assert events.include?(Message.find(5))
  44. # Issue of a private project
  45. assert !events.include?(Issue.find(4))
  46. # Private issue and comment
  47. assert !events.include?(Issue.find(14))
  48. assert !events.include?(Journal.find(5))
  49. end
  50. def test_global_activity_logged_user
  51. events = find_events(User.find(2)) # manager
  52. assert_not_nil events
  53. assert events.include?(Issue.find(1))
  54. # Issue of a private project the user belongs to
  55. assert events.include?(Issue.find(4))
  56. end
  57. def test_user_activity
  58. user = User.find(2)
  59. events = Redmine::Activity::Fetcher.new(User.anonymous, :author => user).events(nil, nil, :limit => 10)
  60. assert(events.size > 0)
  61. assert(events.size <= 10)
  62. assert_nil(events.detect {|e| e.event_author != user})
  63. end
  64. def test_files_activity
  65. f = Redmine::Activity::Fetcher.new(User.anonymous, :project => Project.find(1))
  66. f.scope = ['files']
  67. events = f.events
  68. assert_kind_of Array, events
  69. assert events.include?(Attachment.find_by_container_type_and_container_id('Project', 1))
  70. assert events.include?(Attachment.find_by_container_type_and_container_id('Version', 1))
  71. assert_equal [Attachment], events.collect(&:class).uniq
  72. assert_equal %w(Project Version), events.collect(&:container_type).uniq.sort
  73. end
  74. private
  75. def find_events(user, options={})
  76. Redmine::Activity::Fetcher.new(user, options).events(Date.today - 30, Date.today + 1)
  77. end
  78. end