##// END OF EJS Templates
Use create!....
Jean-Philippe Lang -
r9334:4a3f03859592
parent child
Show More
@@ -1,109 +1,109
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class PrincipalTest < ActiveSupport::TestCase
21 21 fixtures :users, :projects, :members, :member_roles
22 22
23 23 def test_active_scope_should_return_groups_and_active_users
24 24 result = Principal.active.all
25 25 assert_include Group.first, result
26 26 assert_not_nil result.detect {|p| p.is_a?(User)}
27 27 assert_nil result.detect {|p| p.is_a?(User) && !p.active?}
28 28 assert_nil result.detect {|p| p.is_a?(AnonymousUser)}
29 29 end
30 30
31 31 def test_member_of_scope_should_return_the_union_of_all_members
32 32 projects = Project.find_all_by_id(1, 2)
33 33 assert_equal projects.map(&:principals).flatten.sort, Principal.member_of(projects).sort
34 34 end
35 35
36 36 def test_member_of_scope_should_be_empty_for_no_projects
37 37 assert_equal [], Principal.member_of([]).sort
38 38 end
39 39
40 40 def test_not_member_of_scope_should_return_users_that_have_no_memberships
41 41 projects = Project.find_all_by_id(1, 2)
42 42 expected = (Principal.all - projects.map(&:memberships).flatten.map(&:principal)).sort
43 43 assert_equal expected, Principal.not_member_of(projects).sort
44 44 end
45 45
46 46 def test_not_member_of_scope_should_be_empty_for_no_projects
47 47 assert_equal [], Principal.not_member_of([]).sort
48 48 end
49 49
50 50 context "#like" do
51 51 setup do
52 Principal.generate!(:login => 'login')
53 Principal.generate!(:login => 'login2')
52 Principal.create!(:login => 'login')
53 Principal.create!(:login => 'login2')
54 54
55 Principal.generate!(:firstname => 'firstname')
56 Principal.generate!(:firstname => 'firstname2')
55 Principal.create!(:firstname => 'firstname')
56 Principal.create!(:firstname => 'firstname2')
57 57
58 Principal.generate!(:lastname => 'lastname')
59 Principal.generate!(:lastname => 'lastname2')
58 Principal.create!(:lastname => 'lastname')
59 Principal.create!(:lastname => 'lastname2')
60 60
61 Principal.generate!(:mail => 'mail@example.com')
62 Principal.generate!(:mail => 'mail2@example.com')
61 Principal.create!(:mail => 'mail@example.com')
62 Principal.create!(:mail => 'mail2@example.com')
63 63
64 @palmer = Principal.generate!(:firstname => 'David', :lastname => 'Palmer')
64 @palmer = Principal.create!(:firstname => 'David', :lastname => 'Palmer')
65 65 end
66 66
67 67 should "search login" do
68 68 results = Principal.like('login')
69 69
70 70 assert_equal 2, results.count
71 71 assert results.all? {|u| u.login.match(/login/) }
72 72 end
73 73
74 74 should "search firstname" do
75 75 results = Principal.like('firstname')
76 76
77 77 assert_equal 2, results.count
78 78 assert results.all? {|u| u.firstname.match(/firstname/) }
79 79 end
80 80
81 81 should "search lastname" do
82 82 results = Principal.like('lastname')
83 83
84 84 assert_equal 2, results.count
85 85 assert results.all? {|u| u.lastname.match(/lastname/) }
86 86 end
87 87
88 88 should "search mail" do
89 89 results = Principal.like('mail')
90 90
91 91 assert_equal 2, results.count
92 92 assert results.all? {|u| u.mail.match(/mail/) }
93 93 end
94 94
95 95 should "search firstname and lastname" do
96 96 results = Principal.like('david palm')
97 97
98 98 assert_equal 1, results.count
99 99 assert_equal @palmer, results.first
100 100 end
101 101
102 102 should "search lastname and firstname" do
103 103 results = Principal.like('palmer davi')
104 104
105 105 assert_equal 1, results.count
106 106 assert_equal @palmer, results.first
107 107 end
108 108 end
109 109 end
General Comments 0
You need to be logged in to leave comments. Login now