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