annotate .svn/pristine/46/46d157fdde953abdb8fd47b6462689e9852d2071.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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