annotate .svn/pristine/57/57004ea0d71683df384c4e3126bc90d754acca49.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1296 19
Chris@1296 20 class MemberTest < ActiveSupport::TestCase
Chris@1296 21 fixtures :projects, :trackers, :issue_statuses, :issues,
Chris@1296 22 :enumerations, :users, :issue_categories,
Chris@1296 23 :projects_trackers,
Chris@1296 24 :roles,
Chris@1296 25 :member_roles,
Chris@1296 26 :members,
Chris@1296 27 :enabled_modules,
Chris@1296 28 :workflows,
Chris@1296 29 :groups_users,
Chris@1296 30 :watchers,
Chris@1296 31 :journals, :journal_details,
Chris@1296 32 :messages,
Chris@1296 33 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
Chris@1296 34 :boards
Chris@1296 35
Chris@1296 36 include Redmine::I18n
Chris@1296 37
Chris@1296 38 def setup
Chris@1296 39 @jsmith = Member.find(1)
Chris@1296 40 end
Chris@1296 41
Chris@1296 42 def test_create
Chris@1296 43 member = Member.new(:project_id => 1, :user_id => 4, :role_ids => [1, 2])
Chris@1296 44 assert member.save
Chris@1296 45 member.reload
Chris@1296 46
Chris@1296 47 assert_equal 2, member.roles.size
Chris@1296 48 assert_equal Role.find(1), member.roles.sort.first
Chris@1296 49 end
Chris@1296 50
Chris@1296 51 def test_update
Chris@1296 52 assert_equal "eCookbook", @jsmith.project.name
Chris@1296 53 assert_equal "Manager", @jsmith.roles.first.name
Chris@1296 54 assert_equal "jsmith", @jsmith.user.login
Chris@1296 55
Chris@1296 56 @jsmith.mail_notification = !@jsmith.mail_notification
Chris@1296 57 assert @jsmith.save
Chris@1296 58 end
Chris@1296 59
Chris@1296 60 def test_update_roles
Chris@1296 61 assert_equal 1, @jsmith.roles.size
Chris@1296 62 @jsmith.role_ids = [1, 2]
Chris@1296 63 assert @jsmith.save
Chris@1296 64 assert_equal 2, @jsmith.reload.roles.size
Chris@1296 65 end
Chris@1296 66
Chris@1296 67 def test_validate
Chris@1296 68 member = Member.new(:project_id => 1, :user_id => 2, :role_ids => [2])
Chris@1296 69 # same use can't have more than one membership for a project
Chris@1296 70 assert !member.save
Chris@1296 71
Chris@1296 72 # must have one role at least
Chris@1296 73 user = User.new(:firstname => "new1", :lastname => "user1", :mail => "test_validate@somenet.foo")
Chris@1296 74 user.login = "test_validate"
Chris@1296 75 user.password, user.password_confirmation = "password", "password"
Chris@1296 76 assert user.save
Chris@1296 77
Chris@1296 78 set_language_if_valid 'fr'
Chris@1296 79 member = Member.new(:project_id => 1, :user_id => user.id, :role_ids => [])
Chris@1296 80 assert !member.save
Chris@1296 81 assert_include I18n.translate('activerecord.errors.messages.empty'), member.errors[:role]
Chris@1296 82 str = "R\xc3\xb4le doit \xc3\xaatre renseign\xc3\xa9(e)"
Chris@1296 83 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
Chris@1296 84 assert_equal str, [member.errors.full_messages].flatten.join
Chris@1296 85 end
Chris@1296 86
Chris@1296 87 def test_validate_member_role
Chris@1296 88 user = User.new(:firstname => "new1", :lastname => "user1", :mail => "test_validate@somenet.foo")
Chris@1296 89 user.login = "test_validate_member_role"
Chris@1296 90 user.password, user.password_confirmation = "password", "password"
Chris@1296 91 assert user.save
Chris@1296 92 member = Member.new(:project_id => 1, :user_id => user.id, :role_ids => [5])
Chris@1296 93 assert !member.save
Chris@1296 94 end
Chris@1296 95
Chris@1296 96 def test_destroy
Chris@1296 97 category1 = IssueCategory.find(1)
Chris@1296 98 assert_equal @jsmith.user.id, category1.assigned_to_id
Chris@1296 99 assert_difference 'Member.count', -1 do
Chris@1296 100 assert_difference 'MemberRole.count', -1 do
Chris@1296 101 @jsmith.destroy
Chris@1296 102 end
Chris@1296 103 end
Chris@1296 104 assert_raise(ActiveRecord::RecordNotFound) { Member.find(@jsmith.id) }
Chris@1296 105 category1.reload
Chris@1296 106 assert_nil category1.assigned_to_id
Chris@1296 107 end
Chris@1296 108
Chris@1296 109 def test_sort_without_roles
Chris@1296 110 a = Member.new(:roles => [Role.first])
Chris@1296 111 b = Member.new
Chris@1296 112
Chris@1296 113 assert_equal -1, a <=> b
Chris@1296 114 assert_equal 1, b <=> a
Chris@1296 115 end
Chris@1296 116
Chris@1296 117 def test_sort_without_principal
Chris@1296 118 role = Role.first
Chris@1296 119 a = Member.new(:roles => [role], :principal => User.first)
Chris@1296 120 b = Member.new(:roles => [role])
Chris@1296 121
Chris@1296 122 assert_equal -1, a <=> b
Chris@1296 123 assert_equal 1, b <=> a
Chris@1296 124 end
Chris@1296 125
Chris@1296 126 context "removing permissions" do
Chris@1296 127 setup do
Chris@1296 128 Watcher.delete_all("user_id = 9")
Chris@1296 129 user = User.find(9)
Chris@1296 130 # public
Chris@1296 131 Watcher.create!(:watchable => Issue.find(1), :user => user)
Chris@1296 132 # private
Chris@1296 133 Watcher.create!(:watchable => Issue.find(4), :user => user)
Chris@1296 134 Watcher.create!(:watchable => Message.find(7), :user => user)
Chris@1296 135 Watcher.create!(:watchable => Wiki.find(2), :user => user)
Chris@1296 136 Watcher.create!(:watchable => WikiPage.find(3), :user => user)
Chris@1296 137 end
Chris@1296 138
Chris@1296 139 context "of user" do
Chris@1296 140 setup do
Chris@1296 141 @member = Member.create!(:project => Project.find(2), :principal => User.find(9), :role_ids => [1, 2])
Chris@1296 142 end
Chris@1296 143
Chris@1296 144 context "by deleting membership" do
Chris@1296 145 should "prune watchers" do
Chris@1296 146 assert_difference 'Watcher.count', -4 do
Chris@1296 147 @member.destroy
Chris@1296 148 end
Chris@1296 149 end
Chris@1296 150 end
Chris@1296 151
Chris@1296 152 context "by updating roles" do
Chris@1296 153 should "prune watchers" do
Chris@1296 154 Role.find(2).remove_permission! :view_wiki_pages
Chris@1296 155 member = Member.first(:order => 'id desc')
Chris@1296 156 assert_difference 'Watcher.count', -2 do
Chris@1296 157 member.role_ids = [2]
Chris@1296 158 member.save
Chris@1296 159 end
Chris@1296 160 assert !Message.find(7).watched_by?(@user)
Chris@1296 161 end
Chris@1296 162 end
Chris@1296 163 end
Chris@1296 164
Chris@1296 165 context "of group" do
Chris@1296 166 setup do
Chris@1296 167 group = Group.find(10)
Chris@1296 168 @member = Member.create!(:project => Project.find(2), :principal => group, :role_ids => [1, 2])
Chris@1296 169 group.users << User.find(9)
Chris@1296 170 end
Chris@1296 171
Chris@1296 172 context "by deleting membership" do
Chris@1296 173 should "prune watchers" do
Chris@1296 174 assert_difference 'Watcher.count', -4 do
Chris@1296 175 @member.destroy
Chris@1296 176 end
Chris@1296 177 end
Chris@1296 178 end
Chris@1296 179
Chris@1296 180 context "by updating roles" do
Chris@1296 181 should "prune watchers" do
Chris@1296 182 Role.find(2).remove_permission! :view_wiki_pages
Chris@1296 183 assert_difference 'Watcher.count', -2 do
Chris@1296 184 @member.role_ids = [2]
Chris@1296 185 @member.save
Chris@1296 186 end
Chris@1296 187 end
Chris@1296 188 end
Chris@1296 189 end
Chris@1296 190 end
Chris@1296 191 end