Chris@909: # Redmine - project management software Chris@909: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@909: # Chris@909: # This program is free software; you can redistribute it and/or Chris@909: # modify it under the terms of the GNU General Public License Chris@909: # as published by the Free Software Foundation; either version 2 Chris@909: # of the License, or (at your option) any later version. Chris@909: # Chris@909: # This program is distributed in the hope that it will be useful, Chris@909: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@909: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@909: # GNU General Public License for more details. Chris@909: # Chris@909: # You should have received a copy of the GNU General Public License Chris@909: # along with this program; if not, write to the Free Software Chris@909: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@909: Chris@909: require File.expand_path('../../test_helper', __FILE__) Chris@909: Chris@909: class ActivityTest < ActiveSupport::TestCase Chris@909: fixtures :projects, :versions, :attachments, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details, Chris@909: :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages Chris@909: Chris@909: def setup Chris@909: @project = Project.find(1) Chris@909: end Chris@909: Chris@909: def test_activity_without_subprojects Chris@909: events = find_events(User.anonymous, :project => @project) Chris@909: assert_not_nil events Chris@909: Chris@909: assert events.include?(Issue.find(1)) Chris@909: assert !events.include?(Issue.find(4)) Chris@909: # subproject issue Chris@909: assert !events.include?(Issue.find(5)) Chris@909: end Chris@909: Chris@909: def test_activity_with_subprojects Chris@909: events = find_events(User.anonymous, :project => @project, :with_subprojects => 1) Chris@909: assert_not_nil events Chris@909: Chris@909: assert events.include?(Issue.find(1)) Chris@909: # subproject issue Chris@909: assert events.include?(Issue.find(5)) Chris@909: end Chris@909: Chris@909: def test_global_activity_anonymous Chris@909: events = find_events(User.anonymous) Chris@909: assert_not_nil events Chris@909: Chris@909: assert events.include?(Issue.find(1)) Chris@909: assert events.include?(Message.find(5)) Chris@909: # Issue of a private project Chris@909: assert !events.include?(Issue.find(4)) Chris@909: # Private issue and comment Chris@909: assert !events.include?(Issue.find(14)) Chris@909: assert !events.include?(Journal.find(5)) Chris@909: end Chris@909: Chris@909: def test_global_activity_logged_user Chris@909: events = find_events(User.find(2)) # manager Chris@909: assert_not_nil events Chris@909: Chris@909: assert events.include?(Issue.find(1)) Chris@909: # Issue of a private project the user belongs to Chris@909: assert events.include?(Issue.find(4)) Chris@909: end Chris@909: Chris@909: def test_user_activity Chris@909: user = User.find(2) Chris@909: events = Redmine::Activity::Fetcher.new(User.anonymous, :author => user).events(nil, nil, :limit => 10) Chris@909: Chris@909: assert(events.size > 0) Chris@909: assert(events.size <= 10) Chris@909: assert_nil(events.detect {|e| e.event_author != user}) Chris@909: end Chris@909: Chris@909: def test_files_activity Chris@909: f = Redmine::Activity::Fetcher.new(User.anonymous, :project => Project.find(1)) Chris@909: f.scope = ['files'] Chris@909: events = f.events Chris@909: Chris@909: assert_kind_of Array, events Chris@909: assert events.include?(Attachment.find_by_container_type_and_container_id('Project', 1)) Chris@909: assert events.include?(Attachment.find_by_container_type_and_container_id('Version', 1)) Chris@909: assert_equal [Attachment], events.collect(&:class).uniq Chris@909: assert_equal %w(Project Version), events.collect(&:container_type).uniq.sort Chris@909: end Chris@909: Chris@909: private Chris@909: Chris@909: def find_events(user, options={}) Chris@909: Redmine::Activity::Fetcher.new(user, options).events(Date.today - 30, Date.today + 1) Chris@909: end Chris@909: end