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