Chris@909
|
1 # Redmine - project management software
|
Chris@909
|
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@909
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@909
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@119
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19
|
Chris@0
|
20 class PrincipalTest < ActiveSupport::TestCase
|
Chris@929
|
21 fixtures :users, :projects, :members, :member_roles
|
Chris@929
|
22
|
Chris@929
|
23 def test_not_member_of_scope_should_return_users_that_have_no_memberships
|
Chris@929
|
24 projects = Project.find_all_by_id(1, 2)
|
Chris@929
|
25 expected = (Principal.all - projects.map(&:memberships).flatten.map(&:principal)).sort
|
Chris@929
|
26 assert_equal expected, Principal.not_member_of(projects).sort
|
Chris@929
|
27 end
|
Chris@0
|
28
|
Chris@0
|
29 context "#like" do
|
Chris@0
|
30 setup do
|
Chris@0
|
31 Principal.generate!(:login => 'login')
|
Chris@0
|
32 Principal.generate!(:login => 'login2')
|
Chris@0
|
33
|
Chris@0
|
34 Principal.generate!(:firstname => 'firstname')
|
Chris@0
|
35 Principal.generate!(:firstname => 'firstname2')
|
Chris@0
|
36
|
Chris@0
|
37 Principal.generate!(:lastname => 'lastname')
|
Chris@0
|
38 Principal.generate!(:lastname => 'lastname2')
|
Chris@0
|
39
|
Chris@0
|
40 Principal.generate!(:mail => 'mail@example.com')
|
Chris@0
|
41 Principal.generate!(:mail => 'mail2@example.com')
|
Chris@0
|
42 end
|
Chris@909
|
43
|
Chris@0
|
44 should "search login" do
|
Chris@0
|
45 results = Principal.like('login')
|
Chris@0
|
46
|
Chris@0
|
47 assert_equal 2, results.count
|
Chris@0
|
48 assert results.all? {|u| u.login.match(/login/) }
|
Chris@0
|
49 end
|
Chris@0
|
50
|
Chris@0
|
51 should "search firstname" do
|
Chris@0
|
52 results = Principal.like('firstname')
|
Chris@0
|
53
|
Chris@0
|
54 assert_equal 2, results.count
|
Chris@0
|
55 assert results.all? {|u| u.firstname.match(/firstname/) }
|
Chris@0
|
56 end
|
Chris@0
|
57
|
Chris@0
|
58 should "search lastname" do
|
Chris@0
|
59 results = Principal.like('lastname')
|
Chris@0
|
60
|
Chris@0
|
61 assert_equal 2, results.count
|
Chris@0
|
62 assert results.all? {|u| u.lastname.match(/lastname/) }
|
Chris@0
|
63 end
|
Chris@0
|
64
|
Chris@0
|
65 should "search mail" do
|
Chris@0
|
66 results = Principal.like('mail')
|
Chris@0
|
67
|
Chris@0
|
68 assert_equal 2, results.count
|
Chris@0
|
69 assert results.all? {|u| u.mail.match(/mail/) }
|
Chris@0
|
70 end
|
Chris@0
|
71 end
|
Chris@909
|
72
|
Chris@0
|
73 end
|