2021-04-18 14:34:55 +03:00
# frozen_string_literal: true
2020-08-08 18:53:49 +03:00
require File . expand_path '../../test_helper' , __FILE__
2019-11-15 20:27:16 +03:00
class ProjectTest < Additionals :: TestCase
fixtures :projects , :trackers , :issue_statuses , :issues ,
:journals , :journal_details ,
:enumerations , :users , :issue_categories ,
:projects_trackers ,
:custom_fields ,
:custom_fields_projects ,
:custom_fields_trackers ,
:custom_values ,
:roles ,
:member_roles ,
:members ,
:enabled_modules ,
:groups_users ,
:repositories ,
:workflows ,
:attachments
def setup
User . current = nil
end
def test_assignable_users_amount
with_settings issue_group_assignment : '1' do
2021-04-18 14:34:55 +03:00
project = Project . find 5
2022-01-30 16:21:43 +03:00
assert_equal project . assignable_users . count , project . assignable_principals . count
2019-11-15 20:27:16 +03:00
end
with_settings issue_group_assignment : '0' do
2021-04-18 14:34:55 +03:00
project = Project . find 5
2022-01-30 16:21:43 +03:00
assert_not_equal project . assignable_users . count , project . assignable_principals . count
2019-11-15 20:27:16 +03:00
end
end
def test_visible_users
2020-07-31 09:35:08 +03:00
project = projects :projects_005
2019-11-15 20:27:16 +03:00
assert_equal 3 , project . visible_users . count
end
def test_visible_principals
2020-07-31 09:35:08 +03:00
project = projects :projects_005
2019-11-15 20:27:16 +03:00
assert_equal 4 , project . visible_principals . count
end
2020-07-31 09:35:08 +03:00
def test_destroy_project
User . current = users :users_001
@ecookbook = projects :projects_001
# dashboards
assert @ecookbook . dashboards . any?
2022-01-10 20:02:26 +03:00
assert_difference 'Dashboard.count' , - 2 do
@ecookbook . destroy
# make sure that the project non longer exists
assert_raise ( ActiveRecord :: RecordNotFound ) { Project . find @ecookbook . id }
# make sure related data was removed
assert_nil Dashboard . where ( project_id : @ecookbook . id ) . first
end
2020-07-31 09:35:08 +03:00
end
2020-08-03 16:08:33 +03:00
2022-04-04 20:00:53 +03:00
def test_principals_by_role
principals_by_role = Project . find ( 1 ) . principals_by_role
2021-05-06 13:51:56 +03:00
2022-04-04 20:00:53 +03:00
assert_kind_of Hash , principals_by_role
2021-04-18 14:34:55 +03:00
role = Role . find 1
2022-04-04 20:00:53 +03:00
assert_kind_of Array , principals_by_role [ role ]
2022-04-11 17:12:56 +03:00
assert_includes principals_by_role [ role ] , User . find ( 2 )
2020-08-03 16:08:33 +03:00
end
2022-04-04 20:00:53 +03:00
def test_principals_by_role_with_hidden_role
2020-08-03 16:08:33 +03:00
Role . update_all users_visibility : 'members_of_visible_projects'
role = Role . find 2
role . hide = 1
role . save!
assert_equal 0 , Role . where . not ( users_visibility : 'members_of_visible_projects' ) . count
assert role . hide
# User.current = User.find 2
2022-04-04 20:00:53 +03:00
principals_by_role = Project . find ( 1 ) . principals_by_role
assert_equal 1 , principals_by_role . count
2020-08-03 16:08:33 +03:00
User . current = User . find 1
2022-04-04 20:00:53 +03:00
principals_by_role = Project . find ( 1 ) . principals_by_role
assert_equal 2 , principals_by_role . count
2020-08-03 16:08:33 +03:00
end
2022-04-07 21:19:19 +03:00
def test_active_new_ticket_message
with_plugin_settings 'additionals' , new_ticket_message : 'foo' do
project = projects :projects_001
assert_equal 'foo' , project . active_new_ticket_message
end
end
def test_active_new_ticket_message_and_disabled
project = projects :projects_001
project . update_attribute :enable_new_ticket_message , '0'
with_plugin_settings 'additionals' , new_ticket_message : 'foo' do
assert_equal '' , project . active_new_ticket_message
end
end
def test_active_new_ticket_message_with_project_message
project = projects :projects_001
project . update_attribute :enable_new_ticket_message , '2'
project . update_attribute :new_ticket_message , 'bar'
with_plugin_settings 'additionals' , new_ticket_message : 'foo' do
assert_equal 'bar' , project . active_new_ticket_message
end
end
2019-11-15 20:27:16 +03:00
end