annotate test/unit/activity_test.rb @ 669:202986dd17e4 live bibliography_plugin_alpha

Merge from branch "cannam_integration"
author Chris Cannam
date Fri, 09 Sep 2011 16:56:21 +0100
parents cbce1fd3b1b7
children 433d4f72a19b
rev   line source
Chris@441 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 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@441 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@441 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@119 18 require File.expand_path('../../test_helper', __FILE__)
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@441 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@441 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@441 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@441 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@441 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@441 55 # Private issue and comment
Chris@441 56 assert !events.include?(Issue.find(14))
Chris@441 57 assert !events.include?(Journal.find(5))
Chris@0 58 end
Chris@441 59
Chris@0 60 def test_global_activity_logged_user
Chris@0 61 events = find_events(User.find(2)) # manager
Chris@0 62 assert_not_nil events
Chris@441 63
Chris@0 64 assert events.include?(Issue.find(1))
Chris@0 65 # Issue of a private project the user belongs to
Chris@0 66 assert events.include?(Issue.find(4))
Chris@0 67 end
Chris@441 68
Chris@0 69 def test_user_activity
Chris@0 70 user = User.find(2)
Chris@0 71 events = Redmine::Activity::Fetcher.new(User.anonymous, :author => user).events(nil, nil, :limit => 10)
Chris@441 72
Chris@0 73 assert(events.size > 0)
Chris@0 74 assert(events.size <= 10)
Chris@0 75 assert_nil(events.detect {|e| e.event_author != user})
Chris@0 76 end
Chris@441 77
Chris@0 78 def test_files_activity
Chris@0 79 f = Redmine::Activity::Fetcher.new(User.anonymous, :project => Project.find(1))
Chris@0 80 f.scope = ['files']
Chris@0 81 events = f.events
Chris@441 82
Chris@0 83 assert_kind_of Array, events
Chris@0 84 assert events.include?(Attachment.find_by_container_type_and_container_id('Project', 1))
Chris@0 85 assert events.include?(Attachment.find_by_container_type_and_container_id('Version', 1))
Chris@0 86 assert_equal [Attachment], events.collect(&:class).uniq
Chris@0 87 assert_equal %w(Project Version), events.collect(&:container_type).uniq.sort
Chris@0 88 end
Chris@441 89
Chris@0 90 private
Chris@441 91
Chris@0 92 def find_events(user, options={})
Chris@0 93 Redmine::Activity::Fetcher.new(user, options).events(Date.today - 30, Date.today + 1)
Chris@0 94 end
Chris@0 95 end