##// END OF EJS Templates
Added a unit test on User#role_for_project...
Jean-Philippe Lang -
r414:adee6de1404f
parent child
Show More
@@ -1,101 +1,112
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19
20 20 class UserTest < Test::Unit::TestCase
21 fixtures :users
21 fixtures :users, :members, :projects
22 22
23 23 def setup
24 24 @admin = User.find(1)
25 25 @jsmith = User.find(2)
26 @dlopper = User.find(3)
26 27 end
27 28
28 29 def test_truth
29 30 assert_kind_of User, @jsmith
30 31 end
31 32
32 33 def test_create
33 34 user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo")
34 35
35 36 user.login = "jsmith"
36 37 user.password, user.password_confirmation = "password", "password"
37 38 # login uniqueness
38 39 assert !user.save
39 40 assert_equal 1, user.errors.count
40 41
41 42 user.login = "newuser"
42 43 user.password, user.password_confirmation = "passwd", "password"
43 44 # password confirmation
44 45 assert !user.save
45 46 assert_equal 1, user.errors.count
46 47
47 48 user.password, user.password_confirmation = "password", "password"
48 49 assert user.save
49 50 end
50 51
51 52 def test_update
52 53 assert_equal "admin", @admin.login
53 54 @admin.login = "john"
54 55 assert @admin.save, @admin.errors.full_messages.join("; ")
55 56 @admin.reload
56 57 assert_equal "john", @admin.login
57 58 end
58 59
59 60 def test_validate
60 61 @admin.login = ""
61 62 assert !@admin.save
62 63 assert_equal 2, @admin.errors.count
63 64 end
64 65
65 66 def test_password
66 67 user = User.try_to_login("admin", "admin")
67 68 assert_kind_of User, user
68 69 assert_equal "admin", user.login
69 70 user.password = "hello"
70 71 assert user.save
71 72
72 73 user = User.try_to_login("admin", "hello")
73 74 assert_kind_of User, user
74 75 assert_equal "admin", user.login
75 76 assert_equal User.hash_password("hello"), user.hashed_password
76 77 end
77 78
78 79 def test_lock
79 80 user = User.try_to_login("jsmith", "jsmith")
80 81 assert_equal @jsmith, user
81 82
82 83 @jsmith.status = User::STATUS_LOCKED
83 84 assert @jsmith.save
84 85
85 86 user = User.try_to_login("jsmith", "jsmith")
86 87 assert_equal nil, user
87 88 end
88 89
89 90 def test_rss_key
90 91 assert_nil @jsmith.rss_key
91 92 key = @jsmith.get_or_create_rss_key
92 93 assert_kind_of Token, key
93 94 assert_equal 40, key.value.length
94 95
95 96 @jsmith.reload
96 97 assert_equal key.value, @jsmith.get_or_create_rss_key.value
97 98
98 99 @jsmith.reload
99 100 assert_equal key.value, @jsmith.rss_key.value
100 101 end
102
103 def test_role_for_project
104 # user with a role
105 role = @jsmith.role_for_project(Project.find(1))
106 assert_kind_of Role, role
107 assert_equal "Manager", role.name
108
109 # user with no role
110 assert_nil @dlopper.role_for_project(Project.find(2))
111 end
101 112 end
General Comments 0
You need to be logged in to leave comments. Login now