Fix flaky Deployments quota spec by resolving limits through namespace
What does this MR do and why?
Fixes a flaky test in spec/lib/gitlab/ci/pipeline/quota/deployments_spec.rb that was blocking the 18.9 release.
Root cause
let_it_be(:plan_limits) caches the Ruby object across examples. When the DB transaction rolls back between examples, the DB row reverts to the column default (500), but the in-memory object retains the old value. When the before block calls plan_limits.update!(ci_pipeline_deployments: 1), ActiveRecord sees the attribute is already 1 in-memory and skips the SQL UPDATE — leaving the DB at 500.
Fix
- Replace
plan_limits.update!(...)withnamespace.actual_plan.actual_limits.update!(...)which loads a fresh AR object from the DB each time, ensuringupdate!always issues a real SQL UPDATE. - Remove the now-unused
let_it_be(:plan_limits). - Use
Plan.newin the "when limit does not exist" context to get a plan with no persisted limits, sobuild_limitsreturns a fresh PlanLimits with the DB column default of 500.
References
- Failed pipeline: https://gitlab.com/gitlab-org/security/gitlab/-/jobs/13152193708
- Heinrich's debug MR: !223854 (closed)
Edited by Radamanthus Batnag