Mercurial > hg > soundsoftware-site
comparison .svn/pristine/07/072d65dcf460d00cc4770641f038bc5801ca9243.svn-base @ 1295:622f24f53b42 redmine-2.3
Update to Redmine SVN revision 11972 on 2.3-stable branch
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:02:21 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1294:3e4c3460b6ca | 1295:622f24f53b42 |
---|---|
1 # encoding: utf-8 | |
2 # | |
3 # Redmine - project management software | |
4 # Copyright (C) 2006-2012 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 context "#like" do | |
53 setup do | |
54 Principal.create!(:login => 'login') | |
55 Principal.create!(:login => 'login2') | |
56 | |
57 Principal.create!(:firstname => 'firstname') | |
58 Principal.create!(:firstname => 'firstname2') | |
59 | |
60 Principal.create!(:lastname => 'lastname') | |
61 Principal.create!(:lastname => 'lastname2') | |
62 | |
63 Principal.create!(:mail => 'mail@example.com') | |
64 Principal.create!(:mail => 'mail2@example.com') | |
65 | |
66 @palmer = Principal.create!(:firstname => 'David', :lastname => 'Palmer') | |
67 end | |
68 | |
69 should "search login" do | |
70 results = Principal.like('login') | |
71 | |
72 assert_equal 2, results.count | |
73 assert results.all? {|u| u.login.match(/login/) } | |
74 end | |
75 | |
76 should "search firstname" do | |
77 results = Principal.like('firstname') | |
78 | |
79 assert_equal 2, results.count | |
80 assert results.all? {|u| u.firstname.match(/firstname/) } | |
81 end | |
82 | |
83 should "search lastname" do | |
84 results = Principal.like('lastname') | |
85 | |
86 assert_equal 2, results.count | |
87 assert results.all? {|u| u.lastname.match(/lastname/) } | |
88 end | |
89 | |
90 should "search mail" do | |
91 results = Principal.like('mail') | |
92 | |
93 assert_equal 2, results.count | |
94 assert results.all? {|u| u.mail.match(/mail/) } | |
95 end | |
96 | |
97 should "search firstname and lastname" do | |
98 results = Principal.like('david palm') | |
99 | |
100 assert_equal 1, results.count | |
101 assert_equal @palmer, results.first | |
102 end | |
103 | |
104 should "search lastname and firstname" do | |
105 results = Principal.like('palmer davi') | |
106 | |
107 assert_equal 1, results.count | |
108 assert_equal @palmer, results.first | |
109 end | |
110 end | |
111 | |
112 def test_like_scope_with_cyrillic_name | |
113 user = User.generate!(:firstname => 'Соболев', :lastname => 'Денис') | |
114 results = Principal.like('Собо') | |
115 assert_equal 1, results.count | |
116 assert_equal user, results.first | |
117 end | |
118 end |