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