diff options
author | Go MAEDA <maeda@farend.jp> | 2019-08-09 09:31:16 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2019-08-09 09:31:16 +0000 |
commit | 3c91a3d5b2f9a2ce55b941ee68fbaa596b5b3052 (patch) | |
tree | d54cf120aea24f14b4eb7a06f41749f1eacd6e7a /test | |
parent | 433d8a081f29785ac2d21cba36592678f4001511 (diff) | |
download | redmine-3c91a3d5b2f9a2ce55b941ee68fbaa596b5b3052.tar.gz redmine-3c91a3d5b2f9a2ce55b941ee68fbaa596b5b3052.zip |
Per role visibility settings for spent time custom fields (#31859).
Patch by Marius BALTEANU.
git-svn-id: http://svn.redmine.org/redmine/trunk@18358 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/custom_fields_controller_test.rb | 25 | ||||
-rw-r--r-- | test/functional/timelog_custom_fields_visibility_test.rb | 85 | ||||
-rw-r--r-- | test/functional/timelog_report_test.rb | 2 |
3 files changed, 81 insertions, 31 deletions
diff --git a/test/functional/custom_fields_controller_test.rb b/test/functional/custom_fields_controller_test.rb index 9745e2396..e59d408ef 100644 --- a/test/functional/custom_fields_controller_test.rb +++ b/test/functional/custom_fields_controller_test.rb @@ -95,12 +95,37 @@ class CustomFieldsControllerTest < Redmine::ControllerTest assert_select 'option[value=user]', :text => 'User' assert_select 'option[value=version]', :text => 'Version' end + + # Visibility + assert_select 'input[type=radio][name=?]', 'custom_field[visible]', 2 + assert_select 'input[type=checkbox][name=?]', 'custom_field[role_ids][]', 3 + assert_select 'input[type=checkbox][name=?]', 'custom_field[project_ids][]', Project.count assert_select 'input[type=hidden][name=?]', 'custom_field[project_ids][]', 1 assert_select 'input[type=hidden][name=type][value=IssueCustomField]' end end + def test_new_time_entry_custom_field + get :new, :params => { + :type => 'TimeEntryCustomField' + } + assert_response :success + + assert_select 'form#custom_field_form' do + assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]' do + assert_select 'option[value=user]', :text => 'User' + assert_select 'option[value=version]', :text => 'Version' + end + + # Visibility + assert_select 'input[type=radio][name=?]', 'custom_field[visible]', 2 + assert_select 'input[type=checkbox][name=?]', 'custom_field[role_ids][]', 3 + + assert_select 'input[type=hidden][name=type][value=TimeEntryCustomField]' + end + end + def test_new_time_entry_custom_field_should_not_show_trackers_and_projects get :new, :params => { :type => 'TimeEntryCustomField' diff --git a/test/functional/timelog_custom_fields_visibility_test.rb b/test/functional/timelog_custom_fields_visibility_test.rb index 4304e2d6e..d43f3a350 100644 --- a/test/functional/timelog_custom_fields_visibility_test.rb +++ b/test/functional/timelog_custom_fields_visibility_test.rb @@ -34,37 +34,9 @@ class TimelogCustomFieldsVisibilityTest < Redmine::ControllerTest :workflows, :custom_fields, :custom_values, :custom_fields_trackers - def setup - field_attributes = {:field_format => 'string', :is_for_all => true, :is_filter => true, :trackers => Tracker.all} - @fields = [] - @fields << (@field1 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 1', :visible => true))) - @fields << (@field2 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 2', :visible => false, :role_ids => [1, 2]))) - @fields << (@field3 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 3', :visible => false, :role_ids => [1, 3]))) - @issue = Issue.generate!( - :author_id => 1, - :project_id => 1, - :tracker_id => 1, - :custom_field_values => {@field1.id => 'Value0', @field2.id => 'Value1', @field3.id => 'Value2'} - ) - TimeEntry.generate!(:issue => @issue) - - @user_with_role_on_other_project = User.generate! - User.add_to_project(@user_with_role_on_other_project, Project.find(2), Role.find(3)) - - @users_to_test = { - User.find(1) => [@field1, @field2, @field3], - User.find(3) => [@field1, @field2], - @user_with_role_on_other_project => [@field1], # should see field1 only on Project 1 - User.generate! => [@field1], - User.anonymous => [@field1] - } - - Member.where(:project_id => 1).each do |member| - member.destroy unless @users_to_test.keys.include?(member.principal) - end - end - def test_index_should_show_visible_custom_fields_only + prepare_test_data + @users_to_test.each do |user, fields| @request.session[:user_id] = user.id get :index, :params => { @@ -83,6 +55,8 @@ class TimelogCustomFieldsVisibilityTest < Redmine::ControllerTest end def test_index_as_csv_should_show_visible_custom_fields_only + prepare_test_data + @users_to_test.each do |user, fields| @request.session[:user_id] = user.id get :index, :params => { @@ -102,6 +76,8 @@ class TimelogCustomFieldsVisibilityTest < Redmine::ControllerTest end def test_index_with_partial_custom_field_visibility_should_show_visible_custom_fields_only + prepare_test_data + Issue.delete_all TimeEntry.delete_all CustomValue.delete_all @@ -131,4 +107,53 @@ class TimelogCustomFieldsVisibilityTest < Redmine::ControllerTest assert_select 'td', :text => "ValueC" assert_select 'td', :text => "ValueB", :count => 0 end + + def test_edit_should_not_show_custom_fields_not_visible_for_user + time_entry_cf = TimeEntryCustomField.find(10) + time_entry_cf.visible = false + time_entry_cf.role_ids = [2] + time_entry_cf.save! + + @request.session[:user_id] = 2 + + get :edit, :params => { + :id => 3, + :project_id => 1 + } + + assert_response :success + assert_select 'select#time_entry_custom_field_values_10', 0 + end + + private + + def prepare_test_data + field_attributes = {:field_format => 'string', :is_for_all => true, :is_filter => true, :trackers => Tracker.all} + @fields = [] + @fields << (@field1 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 1', :visible => true))) + @fields << (@field2 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 2', :visible => false, :role_ids => [1, 2]))) + @fields << (@field3 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 3', :visible => false, :role_ids => [1, 3]))) + @issue = Issue.generate!( + :author_id => 1, + :project_id => 1, + :tracker_id => 1, + :custom_field_values => {@field1.id => 'Value0', @field2.id => 'Value1', @field3.id => 'Value2'} + ) + TimeEntry.generate!(:issue => @issue) + + @user_with_role_on_other_project = User.generate! + User.add_to_project(@user_with_role_on_other_project, Project.find(2), Role.find(3)) + + @users_to_test = { + User.find(1) => [@field1, @field2, @field3], + User.find(3) => [@field1, @field2], + @user_with_role_on_other_project => [@field1], # should see field1 only on Project 1 + User.generate! => [@field1], + User.anonymous => [@field1] + } + + Member.where(:project_id => 1).each do |member| + member.destroy unless @users_to_test.keys.include?(member.principal) + end + end end diff --git a/test/functional/timelog_report_test.rb b/test/functional/timelog_report_test.rb index 00432302d..a643522d3 100644 --- a/test/functional/timelog_report_test.rb +++ b/test/functional/timelog_report_test.rb @@ -138,7 +138,7 @@ class TimelogReportTest < Redmine::ControllerTest def test_hidden_custom_fields_should_not_be_proposed TimeEntryCustomField.create!(name: 'shown', field_format: 'list', possible_values: ['value1', 'value2'], visible: true) - TimeEntryCustomField.create!(name: 'Hidden', field_format: 'list', possible_values: ['value1', 'value2'], visible: false) + TimeEntryCustomField.create!(name: 'Hidden', field_format: 'list', possible_values: ['value1', 'value2'], visible: false, role_ids: [3]) get :report, :params => {:project_id => 1} assert_response :success |