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