annotate .svn/pristine/50/50a66d1b900fdb625b2a02845d439f18a4409cf7.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 e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1494 19
Chris@1494 20 class SearchTest < ActiveSupport::TestCase
Chris@1494 21 fixtures :users,
Chris@1494 22 :members,
Chris@1494 23 :member_roles,
Chris@1494 24 :projects,
Chris@1494 25 :roles,
Chris@1494 26 :enabled_modules,
Chris@1494 27 :issues,
Chris@1494 28 :trackers,
Chris@1494 29 :journals,
Chris@1494 30 :journal_details,
Chris@1494 31 :repositories,
Chris@1494 32 :changesets
Chris@1494 33
Chris@1494 34 def setup
Chris@1494 35 @project = Project.find(1)
Chris@1494 36 @issue_keyword = '%unable to print recipes%'
Chris@1494 37 @issue = Issue.find(1)
Chris@1494 38 @changeset_keyword = '%very first commit%'
Chris@1494 39 @changeset = Changeset.find(100)
Chris@1494 40 end
Chris@1494 41
Chris@1494 42 def test_search_by_anonymous
Chris@1494 43 User.current = nil
Chris@1494 44
Chris@1494 45 r = Issue.search(@issue_keyword).first
Chris@1494 46 assert r.include?(@issue)
Chris@1494 47 r = Changeset.search(@changeset_keyword).first
Chris@1494 48 assert r.include?(@changeset)
Chris@1494 49
Chris@1494 50 # Removes the :view_changesets permission from Anonymous role
Chris@1494 51 remove_permission Role.anonymous, :view_changesets
Chris@1494 52 User.current = nil
Chris@1494 53
Chris@1494 54 r = Issue.search(@issue_keyword).first
Chris@1494 55 assert r.include?(@issue)
Chris@1494 56 r = Changeset.search(@changeset_keyword).first
Chris@1494 57 assert !r.include?(@changeset)
Chris@1494 58
Chris@1494 59 # Make the project private
Chris@1494 60 @project.update_attribute :is_public, false
Chris@1494 61 r = Issue.search(@issue_keyword).first
Chris@1494 62 assert !r.include?(@issue)
Chris@1494 63 r = Changeset.search(@changeset_keyword).first
Chris@1494 64 assert !r.include?(@changeset)
Chris@1494 65 end
Chris@1494 66
Chris@1494 67 def test_search_by_user
Chris@1494 68 User.current = User.find_by_login('rhill')
Chris@1494 69 assert User.current.memberships.empty?
Chris@1494 70
Chris@1494 71 r = Issue.search(@issue_keyword).first
Chris@1494 72 assert r.include?(@issue)
Chris@1494 73 r = Changeset.search(@changeset_keyword).first
Chris@1494 74 assert r.include?(@changeset)
Chris@1494 75
Chris@1494 76 # Removes the :view_changesets permission from Non member role
Chris@1494 77 remove_permission Role.non_member, :view_changesets
Chris@1494 78 User.current = User.find_by_login('rhill')
Chris@1494 79
Chris@1494 80 r = Issue.search(@issue_keyword).first
Chris@1494 81 assert r.include?(@issue)
Chris@1494 82 r = Changeset.search(@changeset_keyword).first
Chris@1494 83 assert !r.include?(@changeset)
Chris@1494 84
Chris@1494 85 # Make the project private
Chris@1494 86 @project.update_attribute :is_public, false
Chris@1494 87 r = Issue.search(@issue_keyword).first
Chris@1494 88 assert !r.include?(@issue)
Chris@1494 89 r = Changeset.search(@changeset_keyword).first
Chris@1494 90 assert !r.include?(@changeset)
Chris@1494 91 end
Chris@1494 92
Chris@1494 93 def test_search_by_allowed_member
Chris@1494 94 User.current = User.find_by_login('jsmith')
Chris@1494 95 assert User.current.projects.include?(@project)
Chris@1494 96
Chris@1494 97 r = Issue.search(@issue_keyword).first
Chris@1494 98 assert r.include?(@issue)
Chris@1494 99 r = Changeset.search(@changeset_keyword).first
Chris@1494 100 assert r.include?(@changeset)
Chris@1494 101
Chris@1494 102 # Make the project private
Chris@1494 103 @project.update_attribute :is_public, false
Chris@1494 104 r = Issue.search(@issue_keyword).first
Chris@1494 105 assert r.include?(@issue)
Chris@1494 106 r = Changeset.search(@changeset_keyword).first
Chris@1494 107 assert r.include?(@changeset)
Chris@1494 108 end
Chris@1494 109
Chris@1494 110 def test_search_by_unallowed_member
Chris@1494 111 # Removes the :view_changesets permission from user's and non member role
Chris@1494 112 remove_permission Role.find(1), :view_changesets
Chris@1494 113 remove_permission Role.non_member, :view_changesets
Chris@1494 114
Chris@1494 115 User.current = User.find_by_login('jsmith')
Chris@1494 116 assert User.current.projects.include?(@project)
Chris@1494 117
Chris@1494 118 r = Issue.search(@issue_keyword).first
Chris@1494 119 assert r.include?(@issue)
Chris@1494 120 r = Changeset.search(@changeset_keyword).first
Chris@1494 121 assert !r.include?(@changeset)
Chris@1494 122
Chris@1494 123 # Make the project private
Chris@1494 124 @project.update_attribute :is_public, false
Chris@1494 125 r = Issue.search(@issue_keyword).first
Chris@1494 126 assert r.include?(@issue)
Chris@1494 127 r = Changeset.search(@changeset_keyword).first
Chris@1494 128 assert !r.include?(@changeset)
Chris@1494 129 end
Chris@1494 130
Chris@1494 131 def test_search_issue_with_multiple_hits_in_journals
Chris@1494 132 i = Issue.find(1)
Chris@1494 133 assert_equal 2, i.journals.where("notes LIKE '%notes%'").count
Chris@1494 134
Chris@1494 135 r = Issue.search('%notes%').first
Chris@1494 136 assert_equal 1, r.size
Chris@1494 137 assert_equal i, r.first
Chris@1494 138 end
Chris@1494 139
Chris@1494 140 private
Chris@1494 141
Chris@1494 142 def remove_permission(role, permission)
Chris@1494 143 role.permissions = role.permissions - [ permission ]
Chris@1494 144 role.save
Chris@1494 145 end
Chris@1494 146 end