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