Fixes member_approval factory association

What does this MR do and why?

Context

While using the factory for GitlabSubscriptions::MemberManagement::MemberApproval, we observed a mismatch between:

  • member_approval.member_namespace_id
  • and member_approval.member.member_namespace_id

when we created the factory like FactoryBot.create(:gitlab_subscription_member_management_member_approval), or even when we did FactoryBot.create(:gitlab_subscription_member_management_member_approval, member_namespace: grp) the member_namespace of the member object does not match with the member_namespace of the member_approval.

Problem

The factory did not ensure that the member created belongs to the same member_namespace that was passed (or built). As a result:

  • The member_namespace of the associated member could differ from the member_namespace on the MemberApproval itself.
  • This caused confusing test behavior and potential false positives in tests relying on this association.

What This MR Does

  • Aligns the created member's namespace with the provided (or generated) member_namespace.
  • Adds logic to ensure:
    • If member_namespace is a ProjectNamespace, the member is a project_member of that project.
    • If it’s a Group, the member is a group_member of that group.
  • Adds a fallback in after(:build) to automatically align member_namespace to the namespace of the created member if one wasn't explicitly passed.

References

#475095 (closed)

Screenshots or screen recordings

Before After

How to set up and validate locally

  • In rails console, run
     m = FactoryBot.create(:gitlab_subscription_member_management_member_approval)
     # or
     grp = FactoryBot.create(:group)
     m = FactoryBot.create(:gitlab_subscription_member_management_member_approval, member_namespace: grp)
  • Verify m.member.member_namespace is same as m.member_namespace
  • Verify that on master, ^ is not the case.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Suraj Tripathi

Merge request reports

Loading