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