##// END OF EJS Templates
fix find_all_by_id(n1, n2) parameter at test_member_of_scope_should_return_the_union_of_all_members of PrincipalTest...
Toshi MARUYAMA -
r12194:74dbb35b87c5
parent child
Show More
@@ -1,117 +1,119
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2013 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 require File.expand_path('../../test_helper', __FILE__)
21 21
22 22 class PrincipalTest < ActiveSupport::TestCase
23 23 fixtures :users, :projects, :members, :member_roles
24 24
25 25 def test_active_scope_should_return_groups_and_active_users
26 26 result = Principal.active.all
27 27 assert_include Group.first, result
28 28 assert_not_nil result.detect {|p| p.is_a?(User)}
29 29 assert_nil result.detect {|p| p.is_a?(User) && !p.active?}
30 30 assert_nil result.detect {|p| p.is_a?(AnonymousUser)}
31 31 end
32 32
33 33 def test_member_of_scope_should_return_the_union_of_all_members
34 projects = Project.find_all_by_id(1, 2)
35 assert_equal projects.map(&:principals).flatten.sort, Principal.member_of(projects).sort
34 projects = Project.find([1])
35 assert_equal [3, 2], Principal.member_of(projects).sort.map(&:id)
36 projects = Project.find([1, 2])
37 assert_equal [3, 2, 8, 11], Principal.member_of(projects).sort.map(&:id)
36 38 end
37 39
38 40 def test_member_of_scope_should_be_empty_for_no_projects
39 41 assert_equal [], Principal.member_of([]).sort
40 42 end
41 43
42 44 def test_not_member_of_scope_should_return_users_that_have_no_memberships
43 45 [[1], [1, 2]].each do |ids|
44 46 projects = Project.find(ids)
45 47 assert_equal ids.size, projects.count
46 48 expected = (Principal.all - projects.map(&:memberships).flatten.map(&:principal)).sort
47 49 assert_equal expected, Principal.not_member_of(projects).sort
48 50 end
49 51 end
50 52
51 53 def test_not_member_of_scope_should_be_empty_for_no_projects
52 54 assert_equal [], Principal.not_member_of([]).sort
53 55 end
54 56
55 57 def test_sorted_scope_should_sort_users_before_groups
56 58 scope = Principal.where("type <> ?", 'AnonymousUser')
57 59 expected_order = scope.all.sort do |a, b|
58 60 if a.is_a?(User) && b.is_a?(Group)
59 61 -1
60 62 elsif a.is_a?(Group) && b.is_a?(User)
61 63 1
62 64 else
63 65 a.name.downcase <=> b.name.downcase
64 66 end
65 67 end
66 68 assert_equal expected_order.map(&:name).map(&:downcase), scope.sorted.all.map(&:name).map(&:downcase)
67 69 end
68 70
69 71 test "like scope should search login" do
70 72 results = Principal.like('jsmi')
71 73
72 74 assert results.any?
73 75 assert results.all? {|u| u.login.match(/jsmi/i) }
74 76 end
75 77
76 78 test "like scope should search firstname" do
77 79 results = Principal.like('john')
78 80
79 81 assert results.any?
80 82 assert results.all? {|u| u.firstname.match(/john/i) }
81 83 end
82 84
83 85 test "like scope should search lastname" do
84 86 results = Principal.like('smi')
85 87
86 88 assert results.any?
87 89 assert results.all? {|u| u.lastname.match(/smi/i) }
88 90 end
89 91
90 92 test "like scope should search mail" do
91 93 results = Principal.like('somenet')
92 94
93 95 assert results.any?
94 96 assert results.all? {|u| u.mail.match(/somenet/i) }
95 97 end
96 98
97 99 test "like scope should search firstname and lastname" do
98 100 results = Principal.like('john smi')
99 101
100 102 assert_equal 1, results.count
101 103 assert_equal User.find(2), results.first
102 104 end
103 105
104 106 test "like scope should search lastname and firstname" do
105 107 results = Principal.like('smith joh')
106 108
107 109 assert_equal 1, results.count
108 110 assert_equal User.find(2), results.first
109 111 end
110 112
111 113 def test_like_scope_with_cyrillic_name
112 114 user = User.generate!(:firstname => 'Соболев', :lastname => 'Денис')
113 115 results = Principal.like('Собо')
114 116 assert_equal 1, results.count
115 117 assert_equal user, results.first
116 118 end
117 119 end
General Comments 0
You need to be logged in to leave comments. Login now