annotate .svn/pristine/07/072d65dcf460d00cc4770641f038bc5801ca9243.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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