comparison .svn/pristine/a0/a031ba3671a49b989b6b3f05b2432855669191cf.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # encoding: utf-8
2 #
3 # Redmine - project management software
4 # Copyright (C) 2006-2013 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_all_by_id(1, 2)
35 assert_equal projects.map(&:principals).flatten.sort, Principal.member_of(projects).sort
36 end
37
38 def test_member_of_scope_should_be_empty_for_no_projects
39 assert_equal [], Principal.member_of([]).sort
40 end
41
42 def test_not_member_of_scope_should_return_users_that_have_no_memberships
43 projects = Project.find_all_by_id(1, 2)
44 expected = (Principal.all - projects.map(&:memberships).flatten.map(&:principal)).sort
45 assert_equal expected, Principal.not_member_of(projects).sort
46 end
47
48 def test_not_member_of_scope_should_be_empty_for_no_projects
49 assert_equal [], Principal.not_member_of([]).sort
50 end
51
52 def test_sorted_scope_should_sort_users_before_groups
53 scope = Principal.where("type <> ?", 'AnonymousUser')
54 expected_order = scope.all.sort do |a, b|
55 if a.is_a?(User) && b.is_a?(Group)
56 -1
57 elsif a.is_a?(Group) && b.is_a?(User)
58 1
59 else
60 a.name.downcase <=> b.name.downcase
61 end
62 end
63 assert_equal expected_order.map(&:name).map(&:downcase), scope.sorted.all.map(&:name).map(&:downcase)
64 end
65
66 test "like scope should search login" do
67 results = Principal.like('jsmi')
68
69 assert results.any?
70 assert results.all? {|u| u.login.match(/jsmi/i) }
71 end
72
73 test "like scope should search firstname" do
74 results = Principal.like('john')
75
76 assert results.any?
77 assert results.all? {|u| u.firstname.match(/john/i) }
78 end
79
80 test "like scope should search lastname" do
81 results = Principal.like('smi')
82
83 assert results.any?
84 assert results.all? {|u| u.lastname.match(/smi/i) }
85 end
86
87 test "like scope should search mail" do
88 results = Principal.like('somenet')
89
90 assert results.any?
91 assert results.all? {|u| u.mail.match(/somenet/i) }
92 end
93
94 test "like scope should search firstname and lastname" do
95 results = Principal.like('john smi')
96
97 assert_equal 1, results.count
98 assert_equal User.find(2), results.first
99 end
100
101 test "like scope should search lastname and firstname" do
102 results = Principal.like('smith joh')
103
104 assert_equal 1, results.count
105 assert_equal User.find(2), results.first
106 end
107
108 def test_like_scope_with_cyrillic_name
109 user = User.generate!(:firstname => 'Соболев', :lastname => 'Денис')
110 results = Principal.like('Собо')
111 assert_equal 1, results.count
112 assert_equal user, results.first
113 end
114 end