Chris@1464
|
1 # Redmine - project management software
|
Chris@1494
|
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
|
Chris@1464
|
3 #
|
Chris@1464
|
4 # This program is free software; you can redistribute it and/or
|
Chris@1464
|
5 # modify it under the terms of the GNU General Public License
|
Chris@1464
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@1464
|
7 # of the License, or (at your option) any later version.
|
Chris@1464
|
8 #
|
Chris@1464
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@1464
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@1464
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@1464
|
12 # GNU General Public License for more details.
|
Chris@1464
|
13 #
|
Chris@1464
|
14 # You should have received a copy of the GNU General Public License
|
Chris@1464
|
15 # along with this program; if not, write to the Free Software
|
Chris@1464
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@1464
|
17
|
Chris@1464
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@1464
|
19
|
Chris@1464
|
20 class SearchCustomFieldsVisibilityTest < ActionController::TestCase
|
Chris@1464
|
21 tests SearchController
|
Chris@1464
|
22 fixtures :projects,
|
Chris@1464
|
23 :users,
|
Chris@1464
|
24 :roles,
|
Chris@1464
|
25 :members,
|
Chris@1464
|
26 :member_roles,
|
Chris@1464
|
27 :issue_statuses,
|
Chris@1464
|
28 :trackers,
|
Chris@1464
|
29 :projects_trackers,
|
Chris@1464
|
30 :enabled_modules,
|
Chris@1464
|
31 :enumerations,
|
Chris@1464
|
32 :workflows
|
Chris@1464
|
33
|
Chris@1464
|
34 def setup
|
Chris@1464
|
35 field_attributes = {:field_format => 'string', :is_for_all => true, :is_filter => true, :searchable => true, :trackers => Tracker.all}
|
Chris@1464
|
36 @fields = []
|
Chris@1464
|
37 @fields << (@field1 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 1', :visible => true)))
|
Chris@1464
|
38 @fields << (@field2 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 2', :visible => false, :role_ids => [1, 2])))
|
Chris@1464
|
39 @fields << (@field3 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 3', :visible => false, :role_ids => [1, 3])))
|
Chris@1464
|
40 @issue = Issue.generate!(
|
Chris@1464
|
41 :author_id => 1,
|
Chris@1464
|
42 :project_id => 1,
|
Chris@1464
|
43 :tracker_id => 1,
|
Chris@1464
|
44 :custom_field_values => {@field1.id => 'Value0', @field2.id => 'Value1', @field3.id => 'Value2'}
|
Chris@1464
|
45 )
|
Chris@1464
|
46
|
Chris@1464
|
47 @user_with_role_on_other_project = User.generate!
|
Chris@1464
|
48 User.add_to_project(@user_with_role_on_other_project, Project.find(2), Role.find(3))
|
Chris@1464
|
49
|
Chris@1464
|
50 @users_to_test = {
|
Chris@1464
|
51 User.find(1) => [@field1, @field2, @field3],
|
Chris@1464
|
52 User.find(3) => [@field1, @field2],
|
Chris@1464
|
53 @user_with_role_on_other_project => [@field1], # should see field1 only on Project 1
|
Chris@1464
|
54 User.generate! => [@field1],
|
Chris@1464
|
55 User.anonymous => [@field1]
|
Chris@1464
|
56 }
|
Chris@1464
|
57
|
Chris@1464
|
58 Member.where(:project_id => 1).each do |member|
|
Chris@1464
|
59 member.destroy unless @users_to_test.keys.include?(member.principal)
|
Chris@1464
|
60 end
|
Chris@1464
|
61 end
|
Chris@1464
|
62
|
Chris@1464
|
63 def test_search_should_search_visible_custom_fields_only
|
Chris@1464
|
64 @users_to_test.each do |user, fields|
|
Chris@1464
|
65 @request.session[:user_id] = user.id
|
Chris@1464
|
66 @fields.each_with_index do |field, i|
|
Chris@1464
|
67 get :index, :q => "value#{i}"
|
Chris@1464
|
68 assert_response :success
|
Chris@1464
|
69 # we should get a result only if the custom field is visible
|
Chris@1464
|
70 if fields.include?(field)
|
Chris@1464
|
71 assert_equal 1, assigns(:results).size
|
Chris@1464
|
72 else
|
Chris@1464
|
73 assert_equal 0, assigns(:results).size
|
Chris@1464
|
74 end
|
Chris@1464
|
75 end
|
Chris@1464
|
76 end
|
Chris@1464
|
77 end
|
Chris@1464
|
78 end
|