Chris@441
|
1 # Redmine - project management software
|
Chris@1494
|
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@441
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@441
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@119
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19
|
Chris@0
|
20 class ActivityTest < ActiveSupport::TestCase
|
Chris@0
|
21 fixtures :projects, :versions, :attachments, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
|
Chris@1464
|
22 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, :time_entries,
|
Chris@1464
|
23 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
|
Chris@0
|
24
|
Chris@0
|
25 def setup
|
Chris@0
|
26 @project = Project.find(1)
|
Chris@0
|
27 end
|
Chris@441
|
28
|
Chris@0
|
29 def test_activity_without_subprojects
|
Chris@0
|
30 events = find_events(User.anonymous, :project => @project)
|
Chris@0
|
31 assert_not_nil events
|
Chris@441
|
32
|
Chris@0
|
33 assert events.include?(Issue.find(1))
|
Chris@0
|
34 assert !events.include?(Issue.find(4))
|
Chris@0
|
35 # subproject issue
|
Chris@0
|
36 assert !events.include?(Issue.find(5))
|
Chris@0
|
37 end
|
Chris@0
|
38
|
Chris@0
|
39 def test_activity_with_subprojects
|
Chris@0
|
40 events = find_events(User.anonymous, :project => @project, :with_subprojects => 1)
|
Chris@0
|
41 assert_not_nil events
|
Chris@441
|
42
|
Chris@0
|
43 assert events.include?(Issue.find(1))
|
Chris@0
|
44 # subproject issue
|
Chris@0
|
45 assert events.include?(Issue.find(5))
|
Chris@0
|
46 end
|
Chris@441
|
47
|
Chris@0
|
48 def test_global_activity_anonymous
|
Chris@0
|
49 events = find_events(User.anonymous)
|
Chris@0
|
50 assert_not_nil events
|
Chris@441
|
51
|
Chris@0
|
52 assert events.include?(Issue.find(1))
|
Chris@0
|
53 assert events.include?(Message.find(5))
|
Chris@0
|
54 # Issue of a private project
|
Chris@0
|
55 assert !events.include?(Issue.find(4))
|
Chris@441
|
56 # Private issue and comment
|
Chris@441
|
57 assert !events.include?(Issue.find(14))
|
Chris@441
|
58 assert !events.include?(Journal.find(5))
|
Chris@0
|
59 end
|
Chris@441
|
60
|
Chris@0
|
61 def test_global_activity_logged_user
|
Chris@0
|
62 events = find_events(User.find(2)) # manager
|
Chris@0
|
63 assert_not_nil events
|
Chris@441
|
64
|
Chris@0
|
65 assert events.include?(Issue.find(1))
|
Chris@0
|
66 # Issue of a private project the user belongs to
|
Chris@0
|
67 assert events.include?(Issue.find(4))
|
Chris@0
|
68 end
|
Chris@441
|
69
|
Chris@0
|
70 def test_user_activity
|
Chris@0
|
71 user = User.find(2)
|
Chris@0
|
72 events = Redmine::Activity::Fetcher.new(User.anonymous, :author => user).events(nil, nil, :limit => 10)
|
Chris@441
|
73
|
Chris@0
|
74 assert(events.size > 0)
|
Chris@0
|
75 assert(events.size <= 10)
|
Chris@0
|
76 assert_nil(events.detect {|e| e.event_author != user})
|
Chris@0
|
77 end
|
Chris@441
|
78
|
Chris@0
|
79 def test_files_activity
|
Chris@0
|
80 f = Redmine::Activity::Fetcher.new(User.anonymous, :project => Project.find(1))
|
Chris@0
|
81 f.scope = ['files']
|
Chris@0
|
82 events = f.events
|
Chris@441
|
83
|
Chris@0
|
84 assert_kind_of Array, events
|
Chris@0
|
85 assert events.include?(Attachment.find_by_container_type_and_container_id('Project', 1))
|
Chris@0
|
86 assert events.include?(Attachment.find_by_container_type_and_container_id('Version', 1))
|
Chris@0
|
87 assert_equal [Attachment], events.collect(&:class).uniq
|
Chris@0
|
88 assert_equal %w(Project Version), events.collect(&:container_type).uniq.sort
|
Chris@0
|
89 end
|
Chris@441
|
90
|
Chris@1464
|
91 def test_event_group_for_issue
|
Chris@1464
|
92 issue = Issue.find(1)
|
Chris@1464
|
93 assert_equal issue, issue.event_group
|
Chris@1464
|
94 end
|
Chris@1464
|
95
|
Chris@1464
|
96 def test_event_group_for_journal
|
Chris@1464
|
97 issue = Issue.find(1)
|
Chris@1464
|
98 journal = issue.journals.first
|
Chris@1464
|
99 assert_equal issue, journal.event_group
|
Chris@1464
|
100 end
|
Chris@1464
|
101
|
Chris@1464
|
102 def test_event_group_for_issue_time_entry
|
Chris@1464
|
103 time = TimeEntry.where(:issue_id => 1).first
|
Chris@1464
|
104 assert_equal time.issue, time.event_group
|
Chris@1464
|
105 end
|
Chris@1464
|
106
|
Chris@1464
|
107 def test_event_group_for_project_time_entry
|
Chris@1464
|
108 time = TimeEntry.where(:issue_id => nil).first
|
Chris@1464
|
109 assert_equal time, time.event_group
|
Chris@1464
|
110 end
|
Chris@1464
|
111
|
Chris@1464
|
112 def test_event_group_for_message
|
Chris@1464
|
113 message = Message.find(1)
|
Chris@1464
|
114 reply = message.children.first
|
Chris@1464
|
115 assert_equal message, message.event_group
|
Chris@1464
|
116 assert_equal message, reply.event_group
|
Chris@1464
|
117 end
|
Chris@1464
|
118
|
Chris@1464
|
119 def test_event_group_for_wiki_content_version
|
Chris@1464
|
120 content = WikiContent::Version.find(1)
|
Chris@1464
|
121 assert_equal content.page, content.event_group
|
Chris@1464
|
122 end
|
Chris@1464
|
123
|
Chris@0
|
124 private
|
Chris@441
|
125
|
Chris@0
|
126 def find_events(user, options={})
|
Chris@0
|
127 Redmine::Activity::Fetcher.new(user, options).events(Date.today - 30, Date.today + 1)
|
Chris@0
|
128 end
|
Chris@0
|
129 end
|