annotate test/unit/activity_test.rb @ 864:2465362d1b56 bug_145

Close obsolete branch bug_145
author Chris Cannam
date Wed, 11 May 2011 11:57:41 +0100
parents 513646585e45
children af80e5618e9b
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 require File.dirname(__FILE__) + '/../test_helper'
Chris@0 19
Chris@0 20 class ActivityTest < ActiveSupport::TestCase
Chris@0 21 fixtures :projects, :versions, :attachments, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
Chris@0 22 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages
Chris@0 23
Chris@0 24 def setup
Chris@0 25 @project = Project.find(1)
Chris@0 26 end
Chris@0 27
Chris@0 28 def test_activity_without_subprojects
Chris@0 29 events = find_events(User.anonymous, :project => @project)
Chris@0 30 assert_not_nil events
Chris@0 31
Chris@0 32 assert events.include?(Issue.find(1))
Chris@0 33 assert !events.include?(Issue.find(4))
Chris@0 34 # subproject issue
Chris@0 35 assert !events.include?(Issue.find(5))
Chris@0 36 end
Chris@0 37
Chris@0 38 def test_activity_with_subprojects
Chris@0 39 events = find_events(User.anonymous, :project => @project, :with_subprojects => 1)
Chris@0 40 assert_not_nil events
Chris@0 41
Chris@0 42 assert events.include?(Issue.find(1))
Chris@0 43 # subproject issue
Chris@0 44 assert events.include?(Issue.find(5))
Chris@0 45 end
Chris@0 46
Chris@0 47 def test_global_activity_anonymous
Chris@0 48 events = find_events(User.anonymous)
Chris@0 49 assert_not_nil events
Chris@0 50
Chris@0 51 assert events.include?(Issue.find(1))
Chris@0 52 assert events.include?(Message.find(5))
Chris@0 53 # Issue of a private project
Chris@0 54 assert !events.include?(Issue.find(4))
Chris@0 55 end
Chris@0 56
Chris@0 57 def test_global_activity_logged_user
Chris@0 58 events = find_events(User.find(2)) # manager
Chris@0 59 assert_not_nil events
Chris@0 60
Chris@0 61 assert events.include?(Issue.find(1))
Chris@0 62 # Issue of a private project the user belongs to
Chris@0 63 assert events.include?(Issue.find(4))
Chris@0 64 end
Chris@0 65
Chris@0 66 def test_user_activity
Chris@0 67 user = User.find(2)
Chris@0 68 events = Redmine::Activity::Fetcher.new(User.anonymous, :author => user).events(nil, nil, :limit => 10)
Chris@0 69
Chris@0 70 assert(events.size > 0)
Chris@0 71 assert(events.size <= 10)
Chris@0 72 assert_nil(events.detect {|e| e.event_author != user})
Chris@0 73 end
Chris@0 74
Chris@0 75 def test_files_activity
Chris@0 76 f = Redmine::Activity::Fetcher.new(User.anonymous, :project => Project.find(1))
Chris@0 77 f.scope = ['files']
Chris@0 78 events = f.events
Chris@0 79
Chris@0 80 assert_kind_of Array, events
Chris@0 81 assert events.include?(Attachment.find_by_container_type_and_container_id('Project', 1))
Chris@0 82 assert events.include?(Attachment.find_by_container_type_and_container_id('Version', 1))
Chris@0 83 assert_equal [Attachment], events.collect(&:class).uniq
Chris@0 84 assert_equal %w(Project Version), events.collect(&:container_type).uniq.sort
Chris@0 85 end
Chris@0 86
Chris@0 87 private
Chris@0 88
Chris@0 89 def find_events(user, options={})
Chris@0 90 Redmine::Activity::Fetcher.new(user, options).events(Date.today - 30, Date.today + 1)
Chris@0 91 end
Chris@0 92 end