annotate test/unit/member_test.rb @ 669:202986dd17e4 live bibliography_plugin_alpha

Merge from branch "cannam_integration"
author Chris Cannam
date Fri, 09 Sep 2011 16:56:21 +0100
parents af80e5618e9b
children cbb26bc654de
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006 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@0 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@0 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@117 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19
Chris@0 20 class MemberTest < ActiveSupport::TestCase
Chris@0 21 fixtures :all
Chris@0 22
Chris@0 23 def setup
Chris@0 24 @jsmith = Member.find(1)
Chris@0 25 end
Chris@0 26
Chris@0 27 def test_create
Chris@0 28 member = Member.new(:project_id => 1, :user_id => 4, :role_ids => [1, 2])
Chris@0 29 assert member.save
Chris@0 30 member.reload
Chris@0 31
Chris@0 32 assert_equal 2, member.roles.size
Chris@0 33 assert_equal Role.find(1), member.roles.sort.first
Chris@0 34 end
Chris@0 35
Chris@0 36 def test_update
Chris@0 37 assert_equal "eCookbook", @jsmith.project.name
Chris@0 38 assert_equal "Manager", @jsmith.roles.first.name
Chris@0 39 assert_equal "jsmith", @jsmith.user.login
Chris@0 40
Chris@0 41 @jsmith.mail_notification = !@jsmith.mail_notification
Chris@0 42 assert @jsmith.save
Chris@0 43 end
Chris@0 44
Chris@0 45 def test_update_roles
Chris@0 46 assert_equal 1, @jsmith.roles.size
Chris@0 47 @jsmith.role_ids = [1, 2]
Chris@0 48 assert @jsmith.save
Chris@0 49 assert_equal 2, @jsmith.reload.roles.size
Chris@0 50 end
Chris@0 51
Chris@0 52 def test_validate
Chris@0 53 member = Member.new(:project_id => 1, :user_id => 2, :role_ids => [2])
Chris@0 54 # same use can't have more than one membership for a project
Chris@0 55 assert !member.save
Chris@0 56
Chris@0 57 member = Member.new(:project_id => 1, :user_id => 2, :role_ids => [])
Chris@0 58 # must have one role at least
Chris@0 59 assert !member.save
Chris@0 60 end
Chris@0 61
Chris@0 62 def test_destroy
Chris@0 63 assert_difference 'Member.count', -1 do
Chris@0 64 assert_difference 'MemberRole.count', -1 do
Chris@0 65 @jsmith.destroy
Chris@0 66 end
Chris@0 67 end
Chris@0 68
Chris@0 69 assert_raise(ActiveRecord::RecordNotFound) { Member.find(@jsmith.id) }
Chris@0 70 end
Chris@0 71
Chris@0 72 context "removing permissions" do
Chris@0 73 setup do
Chris@0 74 Watcher.delete_all("user_id = 9")
Chris@0 75 user = User.find(9)
Chris@0 76 # public
Chris@0 77 Watcher.create!(:watchable => Issue.find(1), :user => user)
Chris@0 78 # private
Chris@0 79 Watcher.create!(:watchable => Issue.find(4), :user => user)
Chris@0 80 Watcher.create!(:watchable => Message.find(7), :user => user)
Chris@0 81 Watcher.create!(:watchable => Wiki.find(2), :user => user)
Chris@0 82 Watcher.create!(:watchable => WikiPage.find(3), :user => user)
Chris@0 83 end
Chris@0 84
Chris@0 85 context "of user" do
Chris@0 86 setup do
Chris@0 87 @member = Member.create!(:project => Project.find(2), :principal => User.find(9), :role_ids => [1, 2])
Chris@0 88 end
Chris@0 89
Chris@0 90 context "by deleting membership" do
Chris@0 91 should "prune watchers" do
Chris@0 92 assert_difference 'Watcher.count', -4 do
Chris@0 93 @member.destroy
Chris@0 94 end
Chris@0 95 end
Chris@0 96 end
Chris@0 97
Chris@0 98 context "by updating roles" do
Chris@0 99 should "prune watchers" do
Chris@0 100 Role.find(2).remove_permission! :view_wiki_pages
Chris@0 101 member = Member.first(:order => 'id desc')
Chris@0 102 assert_difference 'Watcher.count', -2 do
Chris@0 103 member.role_ids = [2]
Chris@0 104 member.save
Chris@0 105 end
Chris@0 106 assert !Message.find(7).watched_by?(@user)
Chris@0 107 end
Chris@0 108 end
Chris@0 109 end
Chris@0 110
Chris@0 111 context "of group" do
Chris@0 112 setup do
Chris@0 113 group = Group.find(10)
Chris@0 114 @member = Member.create!(:project => Project.find(2), :principal => group, :role_ids => [1, 2])
Chris@0 115 group.users << User.find(9)
Chris@0 116 end
Chris@0 117
Chris@0 118 context "by deleting membership" do
Chris@0 119 should "prune watchers" do
Chris@0 120 assert_difference 'Watcher.count', -4 do
Chris@0 121 @member.destroy
Chris@0 122 end
Chris@0 123 end
Chris@0 124 end
Chris@0 125
Chris@0 126 context "by updating roles" do
Chris@0 127 should "prune watchers" do
Chris@0 128 Role.find(2).remove_permission! :view_wiki_pages
Chris@0 129 assert_difference 'Watcher.count', -2 do
Chris@0 130 @member.role_ids = [2]
Chris@0 131 @member.save
Chris@0 132 end
Chris@0 133 end
Chris@0 134 end
Chris@0 135 end
Chris@0 136 end
Chris@0 137 end