annotate .svn/pristine/05/058be0b3a53e81bfbd2f18f23f7014355fe7cd0a.svn-base @ 976:0befb332f41a get_statistics

get stats up to current date
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 25 Oct 2012 13:50:45 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19
Chris@909 20 class MemberTest < ActiveSupport::TestCase
Chris@909 21 fixtures :projects, :trackers, :issue_statuses, :issues,
Chris@909 22 :enumerations, :users, :issue_categories,
Chris@909 23 :projects_trackers,
Chris@909 24 :roles,
Chris@909 25 :member_roles,
Chris@909 26 :members,
Chris@909 27 :enabled_modules,
Chris@909 28 :workflows,
Chris@909 29 :groups_users,
Chris@909 30 :watchers,
Chris@909 31 :journals, :journal_details,
Chris@909 32 :messages,
Chris@909 33 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
Chris@909 34 :boards
Chris@909 35
Chris@909 36 def setup
Chris@909 37 @jsmith = Member.find(1)
Chris@909 38 end
Chris@909 39
Chris@909 40 def test_create
Chris@909 41 member = Member.new(:project_id => 1, :user_id => 4, :role_ids => [1, 2])
Chris@909 42 assert member.save
Chris@909 43 member.reload
Chris@909 44
Chris@909 45 assert_equal 2, member.roles.size
Chris@909 46 assert_equal Role.find(1), member.roles.sort.first
Chris@909 47 end
Chris@909 48
Chris@909 49 def test_update
Chris@909 50 assert_equal "eCookbook", @jsmith.project.name
Chris@909 51 assert_equal "Manager", @jsmith.roles.first.name
Chris@909 52 assert_equal "jsmith", @jsmith.user.login
Chris@909 53
Chris@909 54 @jsmith.mail_notification = !@jsmith.mail_notification
Chris@909 55 assert @jsmith.save
Chris@909 56 end
Chris@909 57
Chris@909 58 def test_update_roles
Chris@909 59 assert_equal 1, @jsmith.roles.size
Chris@909 60 @jsmith.role_ids = [1, 2]
Chris@909 61 assert @jsmith.save
Chris@909 62 assert_equal 2, @jsmith.reload.roles.size
Chris@909 63 end
Chris@909 64
Chris@909 65 def test_validate
Chris@909 66 member = Member.new(:project_id => 1, :user_id => 2, :role_ids => [2])
Chris@909 67 # same use can't have more than one membership for a project
Chris@909 68 assert !member.save
Chris@909 69
Chris@909 70 member = Member.new(:project_id => 1, :user_id => 2, :role_ids => [])
Chris@909 71 # must have one role at least
Chris@909 72 assert !member.save
Chris@909 73 end
Chris@909 74
Chris@909 75 def test_destroy
Chris@909 76 assert_difference 'Member.count', -1 do
Chris@909 77 assert_difference 'MemberRole.count', -1 do
Chris@909 78 @jsmith.destroy
Chris@909 79 end
Chris@909 80 end
Chris@909 81
Chris@909 82 assert_raise(ActiveRecord::RecordNotFound) { Member.find(@jsmith.id) }
Chris@909 83 end
Chris@909 84
Chris@909 85 context "removing permissions" do
Chris@909 86 setup do
Chris@909 87 Watcher.delete_all("user_id = 9")
Chris@909 88 user = User.find(9)
Chris@909 89 # public
Chris@909 90 Watcher.create!(:watchable => Issue.find(1), :user => user)
Chris@909 91 # private
Chris@909 92 Watcher.create!(:watchable => Issue.find(4), :user => user)
Chris@909 93 Watcher.create!(:watchable => Message.find(7), :user => user)
Chris@909 94 Watcher.create!(:watchable => Wiki.find(2), :user => user)
Chris@909 95 Watcher.create!(:watchable => WikiPage.find(3), :user => user)
Chris@909 96 end
Chris@909 97
Chris@909 98 context "of user" do
Chris@909 99 setup do
Chris@909 100 @member = Member.create!(:project => Project.find(2), :principal => User.find(9), :role_ids => [1, 2])
Chris@909 101 end
Chris@909 102
Chris@909 103 context "by deleting membership" do
Chris@909 104 should "prune watchers" do
Chris@909 105 assert_difference 'Watcher.count', -4 do
Chris@909 106 @member.destroy
Chris@909 107 end
Chris@909 108 end
Chris@909 109 end
Chris@909 110
Chris@909 111 context "by updating roles" do
Chris@909 112 should "prune watchers" do
Chris@909 113 Role.find(2).remove_permission! :view_wiki_pages
Chris@909 114 member = Member.first(:order => 'id desc')
Chris@909 115 assert_difference 'Watcher.count', -2 do
Chris@909 116 member.role_ids = [2]
Chris@909 117 member.save
Chris@909 118 end
Chris@909 119 assert !Message.find(7).watched_by?(@user)
Chris@909 120 end
Chris@909 121 end
Chris@909 122 end
Chris@909 123
Chris@909 124 context "of group" do
Chris@909 125 setup do
Chris@909 126 group = Group.find(10)
Chris@909 127 @member = Member.create!(:project => Project.find(2), :principal => group, :role_ids => [1, 2])
Chris@909 128 group.users << User.find(9)
Chris@909 129 end
Chris@909 130
Chris@909 131 context "by deleting membership" do
Chris@909 132 should "prune watchers" do
Chris@909 133 assert_difference 'Watcher.count', -4 do
Chris@909 134 @member.destroy
Chris@909 135 end
Chris@909 136 end
Chris@909 137 end
Chris@909 138
Chris@909 139 context "by updating roles" do
Chris@909 140 should "prune watchers" do
Chris@909 141 Role.find(2).remove_permission! :view_wiki_pages
Chris@909 142 assert_difference 'Watcher.count', -2 do
Chris@909 143 @member.role_ids = [2]
Chris@909 144 @member.save
Chris@909 145 end
Chris@909 146 end
Chris@909 147 end
Chris@909 148 end
Chris@909 149 end
Chris@909 150 end