Project

General

Profile

Defect #42106 ยป add_test.diff

Mizuki ISHIKAWA, 2025-01-17 07:06

View differences:

test/unit/member_test.rb
58 58
    assert_equal 2, @jsmith.reload.roles.size
59 59
  end
60 60

  
61
  def test_update_roles_with_inherited_roles
62
  User.current = User.find(1)
63

  
64
  project = Project.find(1)
65
  group_a = Group.generate!
66
  group_b = Group.generate!
67
  test_user = User.generate!
68
  group_a.users << test_user
69
  group_b.users << test_user
70

  
71
  # Verify that inherited roles are correctly assigned
72
  group_a_member = Member.new(project: project, user_id: group_a.id)
73
  group_a_member.set_editable_role_ids([1]) # Add Manager role to Group A
74
  group_b_member = Member.new(project: project, user_id: group_b.id)
75
  group_b_member.set_editable_role_ids([1, 2]) # Add Manager and Developer roles to Group B
76
  project.members << [group_a_member, group_b_member]
77
  test_user_member = test_user.members.find_by(project_id: project.id)
78
  assert_equal [ # [role_id, inherited_from]
79
    [1, group_a_member.member_roles.find_by(role_id: 1).id],
80
    [1, group_b_member.member_roles.find_by(role_id: 1).id],
81
    [2, group_b_member.member_roles.find_by(role_id: 2).id],
82
  ], test_user_member.member_roles.map{|r| [r.role_id, r.inherited_from]}
83

  
84
  # Verify that a new non-inherited role is added and inherited roles are maintained
85
  test_user_member.set_editable_role_ids([3]) # Add Reporter role to test_user
86
  assert_equal [ # [role_id, inherited_from]
87
    [1, group_a_member.member_roles.find_by(role_id: 1).id],
88
    [1, group_b_member.member_roles.find_by(role_id: 1).id],
89
    [2, group_b_member.member_roles.find_by(role_id: 2).id],
90
    [3, nil]
91
  ], test_user_member.member_roles.map{|r| [r.role_id, r.inherited_from]}
92
  end
93

  
61 94
  def test_validate
62 95
    member = Member.new(:project_id => 1, :user_id => 2, :role_ids => [2])
63 96
    # same use cannot have more than one membership for a project
    (1-1/1)