Skip to content

Ensure project can always be called on ProtectedRefAccess objects

Joe Woodward requested to merge chore/461213-ensure-project-callable into master

What does this MR do and why?

Ensure project can always be called on ProtectedRefAccess objects

In ProtectedBranchAccess, ProtectedTagAccess, and ProtectedBranch::UnprotectAccessLevel we delegate project to the protected ref e.g.

delegate :project, to: :protected_branch
delegate :project, to: :protected_tag

If the protected_branch or protected_tag is nil a NoMethodError will be raised when calling #project.

This change adds allow_nil: true to the delegations and covers the issue in a spec.

This change will allow us to refactor the validations for ProtectedRefAccess and allow us to group the validations that are skipped when we are importing. Without allowing the protected ref to be nil, we can raise an error during validation which incorrectly rejects valid records during import. if: -> { !importing? && something } only calls something if !importing? is true, however, unless: :importing?, if: :something will call something even if importing? is true.

Related to branchRuleUpdate mutation bug - unexpected Acc... (#461213 - closed)

MR acceptance checklist

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

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Edited by Joe Woodward

Merge request reports