annotate .svn/pristine/46/46c5de8338ae67ca1d4c913350410a5c21e8dc3e.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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