@@ -1,134 +1,134 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | |
|
20 | 20 | class SearchTest < Test::Unit::TestCase |
|
21 | 21 | fixtures :users, |
|
22 | 22 | :members, |
|
23 | 23 | :projects, |
|
24 | 24 | :roles, |
|
25 | 25 | :enabled_modules, |
|
26 | 26 | :issues, |
|
27 | 27 | :trackers, |
|
28 | 28 | :journals, |
|
29 | 29 | :journal_details, |
|
30 | 30 | :repositories, |
|
31 | 31 | :changesets |
|
32 | 32 | |
|
33 | 33 | def setup |
|
34 | 34 | @project = Project.find(1) |
|
35 |
@issue_keyword = '% |
|
|
35 | @issue_keyword = '%unable to print recipes%' | |
|
36 | 36 | @issue = Issue.find(1) |
|
37 | 37 | @changeset_keyword = '%very first commit%' |
|
38 | 38 | @changeset = Changeset.find(100) |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def test_search_by_anonymous |
|
42 | 42 | User.current = nil |
|
43 | 43 | |
|
44 | 44 | r = Issue.search(@issue_keyword) |
|
45 | 45 | assert r.include?(@issue) |
|
46 | 46 | r = Changeset.search(@changeset_keyword) |
|
47 | 47 | assert r.include?(@changeset) |
|
48 | 48 | |
|
49 | 49 | # Removes the :view_changesets permission from Anonymous role |
|
50 | 50 | remove_permission Role.anonymous, :view_changesets |
|
51 | 51 | |
|
52 | 52 | r = Issue.search(@issue_keyword) |
|
53 | 53 | assert r.include?(@issue) |
|
54 | 54 | r = Changeset.search(@changeset_keyword) |
|
55 | 55 | assert !r.include?(@changeset) |
|
56 | 56 | |
|
57 | 57 | # Make the project private |
|
58 | 58 | @project.update_attribute :is_public, false |
|
59 | 59 | r = Issue.search(@issue_keyword) |
|
60 | 60 | assert !r.include?(@issue) |
|
61 | 61 | r = Changeset.search(@changeset_keyword) |
|
62 | 62 | assert !r.include?(@changeset) |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | def test_search_by_user |
|
66 | 66 | User.current = User.find_by_login('rhill') |
|
67 | 67 | assert User.current.memberships.empty? |
|
68 | 68 | |
|
69 | 69 | r = Issue.search(@issue_keyword) |
|
70 | 70 | assert r.include?(@issue) |
|
71 | 71 | r = Changeset.search(@changeset_keyword) |
|
72 | 72 | assert r.include?(@changeset) |
|
73 | 73 | |
|
74 | 74 | # Removes the :view_changesets permission from Non member role |
|
75 | 75 | remove_permission Role.non_member, :view_changesets |
|
76 | 76 | |
|
77 | 77 | r = Issue.search(@issue_keyword) |
|
78 | 78 | assert r.include?(@issue) |
|
79 | 79 | r = Changeset.search(@changeset_keyword) |
|
80 | 80 | assert !r.include?(@changeset) |
|
81 | 81 | |
|
82 | 82 | # Make the project private |
|
83 | 83 | @project.update_attribute :is_public, false |
|
84 | 84 | r = Issue.search(@issue_keyword) |
|
85 | 85 | assert !r.include?(@issue) |
|
86 | 86 | r = Changeset.search(@changeset_keyword) |
|
87 | 87 | assert !r.include?(@changeset) |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | 90 | def test_search_by_allowed_member |
|
91 | 91 | User.current = User.find_by_login('jsmith') |
|
92 | 92 | assert User.current.projects.include?(@project) |
|
93 | 93 | |
|
94 | 94 | r = Issue.search(@issue_keyword) |
|
95 | 95 | assert r.include?(@issue) |
|
96 | 96 | r = Changeset.search(@changeset_keyword) |
|
97 | 97 | assert r.include?(@changeset) |
|
98 | 98 | |
|
99 | 99 | # Make the project private |
|
100 | 100 | @project.update_attribute :is_public, false |
|
101 | 101 | r = Issue.search(@issue_keyword) |
|
102 | 102 | assert r.include?(@issue) |
|
103 | 103 | r = Changeset.search(@changeset_keyword) |
|
104 | 104 | assert r.include?(@changeset) |
|
105 | 105 | end |
|
106 | 106 | |
|
107 | 107 | def test_search_by_unallowed_member |
|
108 | 108 | # Removes the :view_changesets permission from user's and non member role |
|
109 | 109 | remove_permission Role.find(1), :view_changesets |
|
110 | 110 | remove_permission Role.non_member, :view_changesets |
|
111 | 111 | |
|
112 | 112 | User.current = User.find_by_login('jsmith') |
|
113 | 113 | assert User.current.projects.include?(@project) |
|
114 | 114 | |
|
115 | 115 | r = Issue.search(@issue_keyword) |
|
116 | 116 | assert r.include?(@issue) |
|
117 | 117 | r = Changeset.search(@changeset_keyword) |
|
118 | 118 | assert !r.include?(@changeset) |
|
119 | 119 | |
|
120 | 120 | # Make the project private |
|
121 | 121 | @project.update_attribute :is_public, false |
|
122 | 122 | r = Issue.search(@issue_keyword) |
|
123 | 123 | assert r.include?(@issue) |
|
124 | 124 | r = Changeset.search(@changeset_keyword) |
|
125 | 125 | assert !r.include?(@changeset) |
|
126 | 126 | end |
|
127 | 127 | |
|
128 | 128 | private |
|
129 | 129 | |
|
130 | 130 | def remove_permission(role, permission) |
|
131 | 131 | role.permissions = role.permissions - [ permission ] |
|
132 | 132 | role.save |
|
133 | 133 | end |
|
134 | 134 | end |
General Comments 0
You need to be logged in to leave comments.
Login now