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