annotate .svn/pristine/b8/b8a1965fd8f5780ffc827ed99a393772297ea734.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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