annotate .svn/pristine/26/26a05abc1949808b7bdc82c5b02ef9bf35bb7c86.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1517 19
Chris@1517 20 class TimelogCustomFieldsVisibilityTest < ActionController::TestCase
Chris@1517 21 tests TimelogController
Chris@1517 22 fixtures :projects,
Chris@1517 23 :users,
Chris@1517 24 :roles,
Chris@1517 25 :members,
Chris@1517 26 :member_roles,
Chris@1517 27 :issue_statuses,
Chris@1517 28 :trackers,
Chris@1517 29 :projects_trackers,
Chris@1517 30 :enabled_modules,
Chris@1517 31 :enumerations,
Chris@1517 32 :workflows
Chris@1517 33
Chris@1517 34 def setup
Chris@1517 35 field_attributes = {:field_format => 'string', :is_for_all => true, :is_filter => true, :trackers => Tracker.all}
Chris@1517 36 @fields = []
Chris@1517 37 @fields << (@field1 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 1', :visible => true)))
Chris@1517 38 @fields << (@field2 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 2', :visible => false, :role_ids => [1, 2])))
Chris@1517 39 @fields << (@field3 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 3', :visible => false, :role_ids => [1, 3])))
Chris@1517 40 @issue = Issue.generate!(
Chris@1517 41 :author_id => 1,
Chris@1517 42 :project_id => 1,
Chris@1517 43 :tracker_id => 1,
Chris@1517 44 :custom_field_values => {@field1.id => 'Value0', @field2.id => 'Value1', @field3.id => 'Value2'}
Chris@1517 45 )
Chris@1517 46 TimeEntry.generate!(:issue => @issue)
Chris@1517 47
Chris@1517 48 @user_with_role_on_other_project = User.generate!
Chris@1517 49 User.add_to_project(@user_with_role_on_other_project, Project.find(2), Role.find(3))
Chris@1517 50
Chris@1517 51 @users_to_test = {
Chris@1517 52 User.find(1) => [@field1, @field2, @field3],
Chris@1517 53 User.find(3) => [@field1, @field2],
Chris@1517 54 @user_with_role_on_other_project => [@field1], # should see field1 only on Project 1
Chris@1517 55 User.generate! => [@field1],
Chris@1517 56 User.anonymous => [@field1]
Chris@1517 57 }
Chris@1517 58
Chris@1517 59 Member.where(:project_id => 1).each do |member|
Chris@1517 60 member.destroy unless @users_to_test.keys.include?(member.principal)
Chris@1517 61 end
Chris@1517 62 end
Chris@1517 63
Chris@1517 64 def test_index_should_show_visible_custom_fields_only
Chris@1517 65 @users_to_test.each do |user, fields|
Chris@1517 66 @request.session[:user_id] = user.id
Chris@1517 67 get :index, :project_id => 1, :issue_id => @issue.id, :c => (['hours'] + @fields.map{|f| "issue.cf_#{f.id}"})
Chris@1517 68 @fields.each_with_index do |field, i|
Chris@1517 69 if fields.include?(field)
Chris@1517 70 assert_select 'td', {:text => "Value#{i}", :count => 1}, "User #{user.id} was not able to view #{field.name}"
Chris@1517 71 else
Chris@1517 72 assert_select 'td', {:text => "Value#{i}", :count => 0}, "User #{user.id} was able to view #{field.name}"
Chris@1517 73 end
Chris@1517 74 end
Chris@1517 75 end
Chris@1517 76 end
Chris@1517 77
Chris@1517 78 def test_index_as_csv_should_show_visible_custom_fields_only
Chris@1517 79 @users_to_test.each do |user, fields|
Chris@1517 80 @request.session[:user_id] = user.id
Chris@1517 81 get :index, :project_id => 1, :issue_id => @issue.id, :c => (['hours'] + @fields.map{|f| "issue.cf_#{f.id}"}), :format => 'csv'
Chris@1517 82 @fields.each_with_index do |field, i|
Chris@1517 83 if fields.include?(field)
Chris@1517 84 assert_include "Value#{i}", response.body, "User #{user.id} was not able to view #{field.name} in CSV"
Chris@1517 85 else
Chris@1517 86 assert_not_include "Value#{i}", response.body, "User #{user.id} was able to view #{field.name} in CSV"
Chris@1517 87 end
Chris@1517 88 end
Chris@1517 89 end
Chris@1517 90 end
Chris@1517 91
Chris@1517 92 def test_index_with_partial_custom_field_visibility_should_show_visible_custom_fields_only
Chris@1517 93 Issue.delete_all
Chris@1517 94 TimeEntry.delete_all
Chris@1517 95 p1 = Project.generate!
Chris@1517 96 p2 = Project.generate!
Chris@1517 97 user = User.generate!
Chris@1517 98 User.add_to_project(user, p1, Role.where(:id => [1, 3]).all)
Chris@1517 99 User.add_to_project(user, p2, Role.where(:id => 3).all)
Chris@1517 100 TimeEntry.generate!(
Chris@1517 101 :issue => Issue.generate!(:project => p1, :tracker_id => 1,
Chris@1517 102 :custom_field_values => {@field2.id => 'ValueA'}))
Chris@1517 103 TimeEntry.generate!(
Chris@1517 104 :issue => Issue.generate!(:project => p2, :tracker_id => 1,
Chris@1517 105 :custom_field_values => {@field2.id => 'ValueB'}))
Chris@1517 106 TimeEntry.generate!(
Chris@1517 107 :issue => Issue.generate!(:project => p1, :tracker_id => 1,
Chris@1517 108 :custom_field_values => {@field2.id => 'ValueC'}))
Chris@1517 109 @request.session[:user_id] = user.id
Chris@1517 110 get :index, :c => ["hours", "issue.cf_#{@field2.id}"]
Chris@1517 111 assert_select 'td', :text => 'ValueA'
Chris@1517 112 assert_select 'td', :text => 'ValueB', :count => 0
Chris@1517 113 assert_select 'td', :text => 'ValueC'
Chris@1517 114
Chris@1517 115 get :index, :set_filter => '1', "issue.cf_#{@field2.id}" => '*'
Chris@1517 116 assert_equal %w(ValueA ValueC), assigns(:entries).map{|i| i.issue.custom_field_value(@field2)}.sort
Chris@1517 117 end
Chris@1517 118 end