Chris@909
|
1 # Redmine - project management software
|
Chris@1295
|
2 # Copyright (C) 2006-2013 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 :groups_users,
|
Chris@909
|
29 :watchers,
|
Chris@909
|
30 :journals, :journal_details,
|
Chris@909
|
31 :messages,
|
Chris@909
|
32 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
|
Chris@909
|
33 :boards
|
Chris@0
|
34
|
Chris@1115
|
35 include Redmine::I18n
|
Chris@1115
|
36
|
Chris@0
|
37 def setup
|
Chris@0
|
38 @jsmith = Member.find(1)
|
Chris@0
|
39 end
|
Chris@909
|
40
|
Chris@0
|
41 def test_create
|
Chris@0
|
42 member = Member.new(:project_id => 1, :user_id => 4, :role_ids => [1, 2])
|
Chris@0
|
43 assert member.save
|
Chris@0
|
44 member.reload
|
Chris@909
|
45
|
Chris@0
|
46 assert_equal 2, member.roles.size
|
Chris@0
|
47 assert_equal Role.find(1), member.roles.sort.first
|
Chris@0
|
48 end
|
Chris@0
|
49
|
Chris@909
|
50 def test_update
|
Chris@0
|
51 assert_equal "eCookbook", @jsmith.project.name
|
Chris@0
|
52 assert_equal "Manager", @jsmith.roles.first.name
|
Chris@0
|
53 assert_equal "jsmith", @jsmith.user.login
|
Chris@909
|
54
|
Chris@0
|
55 @jsmith.mail_notification = !@jsmith.mail_notification
|
Chris@0
|
56 assert @jsmith.save
|
Chris@0
|
57 end
|
Chris@0
|
58
|
Chris@0
|
59 def test_update_roles
|
Chris@0
|
60 assert_equal 1, @jsmith.roles.size
|
Chris@0
|
61 @jsmith.role_ids = [1, 2]
|
Chris@0
|
62 assert @jsmith.save
|
Chris@0
|
63 assert_equal 2, @jsmith.reload.roles.size
|
Chris@0
|
64 end
|
Chris@909
|
65
|
Chris@0
|
66 def test_validate
|
Chris@0
|
67 member = Member.new(:project_id => 1, :user_id => 2, :role_ids => [2])
|
Chris@0
|
68 # same use can't have more than one membership for a project
|
Chris@0
|
69 assert !member.save
|
Chris@909
|
70
|
Chris@0
|
71 # must have one role at least
|
Chris@1115
|
72 user = User.new(:firstname => "new1", :lastname => "user1", :mail => "test_validate@somenet.foo")
|
Chris@1115
|
73 user.login = "test_validate"
|
Chris@1115
|
74 user.password, user.password_confirmation = "password", "password"
|
Chris@1115
|
75 assert user.save
|
Chris@1115
|
76
|
Chris@1115
|
77 set_language_if_valid 'fr'
|
Chris@1115
|
78 member = Member.new(:project_id => 1, :user_id => user.id, :role_ids => [])
|
Chris@1115
|
79 assert !member.save
|
Chris@1115
|
80 assert_include I18n.translate('activerecord.errors.messages.empty'), member.errors[:role]
|
Chris@1115
|
81 str = "R\xc3\xb4le doit \xc3\xaatre renseign\xc3\xa9(e)"
|
Chris@1115
|
82 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
|
Chris@1115
|
83 assert_equal str, [member.errors.full_messages].flatten.join
|
Chris@1115
|
84 end
|
Chris@1115
|
85
|
Chris@1115
|
86 def test_validate_member_role
|
Chris@1115
|
87 user = User.new(:firstname => "new1", :lastname => "user1", :mail => "test_validate@somenet.foo")
|
Chris@1115
|
88 user.login = "test_validate_member_role"
|
Chris@1115
|
89 user.password, user.password_confirmation = "password", "password"
|
Chris@1115
|
90 assert user.save
|
Chris@1115
|
91 member = Member.new(:project_id => 1, :user_id => user.id, :role_ids => [5])
|
Chris@0
|
92 assert !member.save
|
Chris@0
|
93 end
|
Chris@909
|
94
|
Chris@0
|
95 def test_destroy
|
Chris@1115
|
96 category1 = IssueCategory.find(1)
|
Chris@1115
|
97 assert_equal @jsmith.user.id, category1.assigned_to_id
|
Chris@0
|
98 assert_difference 'Member.count', -1 do
|
Chris@0
|
99 assert_difference 'MemberRole.count', -1 do
|
Chris@0
|
100 @jsmith.destroy
|
Chris@0
|
101 end
|
Chris@0
|
102 end
|
Chris@0
|
103 assert_raise(ActiveRecord::RecordNotFound) { Member.find(@jsmith.id) }
|
Chris@1115
|
104 category1.reload
|
Chris@1115
|
105 assert_nil category1.assigned_to_id
|
Chris@0
|
106 end
|
Chris@909
|
107
|
Chris@929
|
108 def test_sort_without_roles
|
Chris@929
|
109 a = Member.new(:roles => [Role.first])
|
Chris@929
|
110 b = Member.new
|
Chris@929
|
111
|
Chris@929
|
112 assert_equal -1, a <=> b
|
Chris@929
|
113 assert_equal 1, b <=> a
|
Chris@929
|
114 end
|
Chris@929
|
115
|
Chris@929
|
116 def test_sort_without_principal
|
Chris@929
|
117 role = Role.first
|
Chris@929
|
118 a = Member.new(:roles => [role], :principal => User.first)
|
Chris@929
|
119 b = Member.new(:roles => [role])
|
Chris@929
|
120
|
Chris@929
|
121 assert_equal -1, a <=> b
|
Chris@929
|
122 assert_equal 1, b <=> a
|
Chris@929
|
123 end
|
Chris@0
|
124 end
|