annotate test/unit/member_test.rb @ 917:66ac47c3719b cannam_integration

Rename .text.html.erb and .text.plain.erb to .html.erb and .text.erb in line with the other mailer files
author Chris Cannam
date Tue, 06 Mar 2012 14:05:16 +0000
parents cbb26bc654de
children 5f33065ddc4b
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 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@909 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@909 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 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@0 35
Chris@0 36 def setup
Chris@0 37 @jsmith = Member.find(1)
Chris@0 38 end
Chris@909 39
Chris@0 40 def test_create
Chris@0 41 member = Member.new(:project_id => 1, :user_id => 4, :role_ids => [1, 2])
Chris@0 42 assert member.save
Chris@0 43 member.reload
Chris@909 44
Chris@0 45 assert_equal 2, member.roles.size
Chris@0 46 assert_equal Role.find(1), member.roles.sort.first
Chris@0 47 end
Chris@0 48
Chris@909 49 def test_update
Chris@0 50 assert_equal "eCookbook", @jsmith.project.name
Chris@0 51 assert_equal "Manager", @jsmith.roles.first.name
Chris@0 52 assert_equal "jsmith", @jsmith.user.login
Chris@909 53
Chris@0 54 @jsmith.mail_notification = !@jsmith.mail_notification
Chris@0 55 assert @jsmith.save
Chris@0 56 end
Chris@0 57
Chris@0 58 def test_update_roles
Chris@0 59 assert_equal 1, @jsmith.roles.size
Chris@0 60 @jsmith.role_ids = [1, 2]
Chris@0 61 assert @jsmith.save
Chris@0 62 assert_equal 2, @jsmith.reload.roles.size
Chris@0 63 end
Chris@909 64
Chris@0 65 def test_validate
Chris@0 66 member = Member.new(:project_id => 1, :user_id => 2, :role_ids => [2])
Chris@0 67 # same use can't have more than one membership for a project
Chris@0 68 assert !member.save
Chris@909 69
Chris@0 70 member = Member.new(:project_id => 1, :user_id => 2, :role_ids => [])
Chris@0 71 # must have one role at least
Chris@0 72 assert !member.save
Chris@0 73 end
Chris@909 74
Chris@0 75 def test_destroy
Chris@0 76 assert_difference 'Member.count', -1 do
Chris@0 77 assert_difference 'MemberRole.count', -1 do
Chris@0 78 @jsmith.destroy
Chris@0 79 end
Chris@0 80 end
Chris@909 81
Chris@0 82 assert_raise(ActiveRecord::RecordNotFound) { Member.find(@jsmith.id) }
Chris@0 83 end
Chris@909 84
Chris@0 85 context "removing permissions" do
Chris@0 86 setup do
Chris@0 87 Watcher.delete_all("user_id = 9")
Chris@0 88 user = User.find(9)
Chris@0 89 # public
Chris@0 90 Watcher.create!(:watchable => Issue.find(1), :user => user)
Chris@0 91 # private
Chris@0 92 Watcher.create!(:watchable => Issue.find(4), :user => user)
Chris@0 93 Watcher.create!(:watchable => Message.find(7), :user => user)
Chris@0 94 Watcher.create!(:watchable => Wiki.find(2), :user => user)
Chris@0 95 Watcher.create!(:watchable => WikiPage.find(3), :user => user)
Chris@0 96 end
Chris@909 97
Chris@0 98 context "of user" do
Chris@0 99 setup do
Chris@0 100 @member = Member.create!(:project => Project.find(2), :principal => User.find(9), :role_ids => [1, 2])
Chris@0 101 end
Chris@909 102
Chris@0 103 context "by deleting membership" do
Chris@0 104 should "prune watchers" do
Chris@0 105 assert_difference 'Watcher.count', -4 do
Chris@0 106 @member.destroy
Chris@0 107 end
Chris@0 108 end
Chris@0 109 end
Chris@909 110
Chris@0 111 context "by updating roles" do
Chris@0 112 should "prune watchers" do
Chris@0 113 Role.find(2).remove_permission! :view_wiki_pages
Chris@0 114 member = Member.first(:order => 'id desc')
Chris@0 115 assert_difference 'Watcher.count', -2 do
Chris@0 116 member.role_ids = [2]
Chris@0 117 member.save
Chris@0 118 end
Chris@0 119 assert !Message.find(7).watched_by?(@user)
Chris@0 120 end
Chris@0 121 end
Chris@0 122 end
Chris@909 123
Chris@0 124 context "of group" do
Chris@0 125 setup do
Chris@0 126 group = Group.find(10)
Chris@0 127 @member = Member.create!(:project => Project.find(2), :principal => group, :role_ids => [1, 2])
Chris@0 128 group.users << User.find(9)
Chris@0 129 end
Chris@0 130
Chris@0 131 context "by deleting membership" do
Chris@0 132 should "prune watchers" do
Chris@0 133 assert_difference 'Watcher.count', -4 do
Chris@0 134 @member.destroy
Chris@0 135 end
Chris@0 136 end
Chris@909 137 end
Chris@0 138
Chris@0 139 context "by updating roles" do
Chris@0 140 should "prune watchers" do
Chris@0 141 Role.find(2).remove_permission! :view_wiki_pages
Chris@0 142 assert_difference 'Watcher.count', -2 do
Chris@0 143 @member.role_ids = [2]
Chris@0 144 @member.save
Chris@0 145 end
Chris@0 146 end
Chris@0 147 end
Chris@0 148 end
Chris@0 149 end
Chris@0 150 end