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__
2020-08-03 18:02:04 +03:00
class UserTest < Additionals :: TestCase
2020-08-06 09:27:43 +03:00
fixtures :users , :groups_users , :email_addresses ,
:members , :projects , :roles , :member_roles , :auth_sources ,
2020-08-03 18:02:04 +03:00
:trackers , :issue_statuses ,
:projects_trackers ,
:watchers ,
:issue_categories , :enumerations , :issues ,
:journals , :journal_details ,
:enabled_modules ,
2020-08-06 09:27:43 +03:00
:tokens , :user_preferences ,
:dashboards , :dashboard_roles
2020-08-03 18:02:04 +03:00
def setup
prepare_tests
2020-08-06 09:30:21 +03:00
User . current = users :users_002
2020-08-03 18:02:04 +03:00
end
def test_with_permission
2021-04-18 14:34:55 +03:00
admin_user = User . generate! admin : true
2020-08-03 18:02:04 +03:00
2021-04-18 14:34:55 +03:00
users = User . visible . active . with_permission :save_dashboards
2020-08-03 18:02:04 +03:00
assert_equal 5 , users . count
assert users . exists? ( id : admin_user )
end
def test_with_permission_on_project
assert_equal 3 , User . visible . active . with_permission ( :save_dashboards , projects ( :projects_001 ) ) . count
end
2020-08-31 10:46:22 +03:00
def test_admin_should_can_be_admin
assert User . where ( admin : true ) . first . can_be_admin?
end
def test_non_admin_should_can_not_be_admin
assert_not User . where ( admin : false ) . first . can_be_admin?
end
def test_sudoer_should_can_be_admin
2021-09-20 13:44:10 +03:00
skip 'Skip redmine_sudo test, because redmine_contacts is not installed' unless AdditionalsPlugin . active_sudo?
2020-08-31 10:46:22 +03:00
user = users :users_001
user . sudoer = true
user . save!
user . reload
assert user . sudoer
assert user . admin
assert User . where ( sudoer : true ) . first . can_be_admin?
user . admin = false
user . save!
user . reload
assert user . sudoer
assert_not user . admin
assert User . where ( sudoer : true ) . first . can_be_admin?
end
2020-09-08 10:40:06 +03:00
def test_non_sudoer_without_admin_can_not_be_admin
2021-09-20 13:44:10 +03:00
skip 'Skip redmine_sudo test, because redmine_contacts is not installed' unless AdditionalsPlugin . active_sudo?
2020-08-31 10:46:22 +03:00
assert_not User . where ( sudoer : false , admin : false ) . first . can_be_admin?
end
2020-08-03 18:02:04 +03:00
end