summaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/issue_priority_test.rb16
-rw-r--r--test/unit/member_test.rb33
2 files changed, 49 insertions, 0 deletions
diff --git a/test/unit/issue_priority_test.rb b/test/unit/issue_priority_test.rb
index e076afe67..80dc11e1c 100644
--- a/test/unit/issue_priority_test.rb
+++ b/test/unit/issue_priority_test.rb
@@ -156,4 +156,20 @@ class IssuePriorityTest < ActiveSupport::TestCase
IssuePriority.find_by_position_name('highest').destroy
assert_equal %w(lowest default high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
end
+
+ def test_high_should_return_false_when_no_default_priority_and_no_active_priorities
+ IssuePriority.update_all(active: false, is_default: false)
+ priority = IssuePriority.order(:position).last # Highest priority
+ assert_nothing_raised do
+ assert_equal false, priority.high?
+ end
+ end
+
+ def test_low_should_return_false_when_no_default_priority_and_no_active_priorities
+ IssuePriority.update_all(active: false, is_default: false)
+ priority = IssuePriority.order(:position).first # Lowest priority
+ assert_nothing_raised do
+ assert_equal false, priority.low?
+ end
+ end
end
diff --git a/test/unit/member_test.rb b/test/unit/member_test.rb
index a7b1843dc..f92841b76 100644
--- a/test/unit/member_test.rb
+++ b/test/unit/member_test.rb
@@ -58,6 +58,39 @@ class MemberTest < ActiveSupport::TestCase
assert_equal 2, @jsmith.reload.roles.size
end
+ def test_update_roles_with_inherited_roles
+ User.current = User.find(1)
+
+ project = Project.find(1)
+ group_a = Group.generate!
+ group_b = Group.generate!
+ test_user = User.generate!
+ group_a.users << test_user
+ group_b.users << test_user
+
+ # Verify that inherited roles are correctly assigned
+ group_a_member = Member.new(project: project, user_id: group_a.id)
+ group_a_member.set_editable_role_ids([1]) # Add Manager role to Group A
+ group_b_member = Member.new(project: project, user_id: group_b.id)
+ group_b_member.set_editable_role_ids([1, 2]) # Add Manager and Developer roles to Group B
+ project.members << [group_a_member, group_b_member]
+ test_user_member = test_user.members.find_by(project_id: project.id)
+ assert_equal [ # [role_id, inherited_from]
+ [1, group_a_member.member_roles.find_by(role_id: 1).id],
+ [1, group_b_member.member_roles.find_by(role_id: 1).id],
+ [2, group_b_member.member_roles.find_by(role_id: 2).id],
+ ], test_user_member.member_roles.map{|r| [r.role_id, r.inherited_from]}
+
+ # Verify that a new non-inherited role is added and inherited roles are maintained
+ test_user_member.set_editable_role_ids([3]) # Add Reporter role to test_user
+ assert_equal [ # [role_id, inherited_from]
+ [1, group_a_member.member_roles.find_by(role_id: 1).id],
+ [1, group_b_member.member_roles.find_by(role_id: 1).id],
+ [2, group_b_member.member_roles.find_by(role_id: 2).id],
+ [3, nil]
+ ], test_user_member.member_roles.map{|r| [r.role_id, r.inherited_from]}
+ end
+
def test_validate
member = Member.new(:project_id => 1, :user_id => 2, :role_ids => [2])
# same use cannot have more than one membership for a project