comparison test/functional/search_custom_fields_visibility_test.rb @ 1526:404aa68d4227

Merge from live branch
author Chris Cannam
date Thu, 11 Sep 2014 12:46:20 +0100
parents e248c7af89ec
children
comparison
equal deleted inserted replaced
1493:a5f2bdf3b486 1526:404aa68d4227
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 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 SearchCustomFieldsVisibilityTest < ActionController::TestCase
21 tests SearchController
22 fixtures :projects,
23 :users,
24 :roles,
25 :members,
26 :member_roles,
27 :issue_statuses,
28 :trackers,
29 :projects_trackers,
30 :enabled_modules,
31 :enumerations,
32 :workflows
33
34 def setup
35 field_attributes = {:field_format => 'string', :is_for_all => true, :is_filter => true, :searchable => true, :trackers => Tracker.all}
36 @fields = []
37 @fields << (@field1 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 1', :visible => true)))
38 @fields << (@field2 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 2', :visible => false, :role_ids => [1, 2])))
39 @fields << (@field3 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 3', :visible => false, :role_ids => [1, 3])))
40 @issue = Issue.generate!(
41 :author_id => 1,
42 :project_id => 1,
43 :tracker_id => 1,
44 :custom_field_values => {@field1.id => 'Value0', @field2.id => 'Value1', @field3.id => 'Value2'}
45 )
46
47 @user_with_role_on_other_project = User.generate!
48 User.add_to_project(@user_with_role_on_other_project, Project.find(2), Role.find(3))
49
50 @users_to_test = {
51 User.find(1) => [@field1, @field2, @field3],
52 User.find(3) => [@field1, @field2],
53 @user_with_role_on_other_project => [@field1], # should see field1 only on Project 1
54 User.generate! => [@field1],
55 User.anonymous => [@field1]
56 }
57
58 Member.where(:project_id => 1).each do |member|
59 member.destroy unless @users_to_test.keys.include?(member.principal)
60 end
61 end
62
63 def test_search_should_search_visible_custom_fields_only
64 @users_to_test.each do |user, fields|
65 @request.session[:user_id] = user.id
66 @fields.each_with_index do |field, i|
67 get :index, :q => "value#{i}"
68 assert_response :success
69 # we should get a result only if the custom field is visible
70 if fields.include?(field)
71 assert_equal 1, assigns(:results).size
72 else
73 assert_equal 0, assigns(:results).size
74 end
75 end
76 end
77 end
78 end