1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
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.
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.
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.
18 require File.dirname(__FILE__) + '/../test_helper'
20 class ActivityTest < ActiveSupport::TestCase
21 fixtures :projects, :versions, :attachments, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
22 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages
25 @project = Project.find(1)
28 def test_activity_without_subprojects
29 events = find_events(User.anonymous, :project => @project)
32 assert events.include?(Issue.find(1))
33 assert !events.include?(Issue.find(4))
35 assert !events.include?(Issue.find(5))
38 def test_activity_with_subprojects
39 events = find_events(User.anonymous, :project => @project, :with_subprojects => 1)
42 assert events.include?(Issue.find(1))
44 assert events.include?(Issue.find(5))
47 def test_global_activity_anonymous
48 events = find_events(User.anonymous)
51 assert events.include?(Issue.find(1))
52 assert events.include?(Message.find(5))
53 # Issue of a private project
54 assert !events.include?(Issue.find(4))
57 def test_global_activity_logged_user
58 events = find_events(User.find(2)) # manager
61 assert events.include?(Issue.find(1))
62 # Issue of a private project the user belongs to
63 assert events.include?(Issue.find(4))
66 def test_user_activity
68 events = Redmine::Activity::Fetcher.new(User.anonymous, :author => user).events(nil, nil, :limit => 10)
70 assert(events.size > 0)
71 assert(events.size <= 10)
72 assert_nil(events.detect {|e| e.event_author != user})
75 def test_files_activity
76 f = Redmine::Activity::Fetcher.new(User.anonymous, :project => Project.find(1))
80 assert_kind_of Array, events
81 assert events.include?(Attachment.find_by_container_type_and_container_id('Project', 1))
82 assert events.include?(Attachment.find_by_container_type_and_container_id('Version', 1))
83 assert_equal [Attachment], events.collect(&:class).uniq
84 assert_equal %w(Project Version), events.collect(&:container_type).uniq.sort
89 def find_events(user, options={})
90 Redmine::Activity::Fetcher.new(user, options).events(Date.today - 30, Date.today + 1)