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_namespaceof the associatedmembercould differ from themember_namespaceon theMemberApprovalitself. - 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_namespaceis aProjectNamespace, thememberis aproject_memberof that project. - If it’s a
Group, thememberis agroup_memberof that group.
- If
- Adds a fallback in
after(:build)to automatically alignmember_namespaceto the namespace of the createdmemberif one wasn't explicitly passed.
References
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_namespaceis same asm.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