additionals/test/unit/project_test.rb

119 lines
3.4 KiB
Ruby
Raw Normal View History

# 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
project = Project.find 5
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
project = Project.find 5
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
project = projects :projects_005
2019-11-15 20:27:16 +03:00
assert_equal 3, project.visible_users.count
end
def test_visible_principals
project = projects :projects_005
2019-11-15 20:27:16 +03:00
assert_equal 4, project.visible_principals.count
end
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
end
def test_principals_by_role
principals_by_role = Project.find(1).principals_by_role
2021-05-06 13:51:56 +03:00
assert_kind_of Hash, principals_by_role
role = Role.find 1
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)
end
def test_principals_by_role_with_hidden_role
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
principals_by_role = Project.find(1).principals_by_role
assert_equal 1, principals_by_role.count
User.current = User.find 1
principals_by_role = Project.find(1).principals_by_role
assert_equal 2, principals_by_role.count
end
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