Extract HasEnvironmentScope tests into shared examples
Summary
During review of https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/30779 / https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/14729, it was suggested to extract the tests for HasEnvironmentScope into shared examples.
This is not entirely trivial to achieve, so it got split into its own issue.
Improvements
Shared examples can be included in the tests of each consuming class, letting us more confidently modify HasEnvironmentScope.
Risks
If done poorly, the tests can end up harder to use and maintain than what we have right now. And by including the shared examples in multiple spec files, the tests will do more work over all, which implies a slower or more expensive test suite.
Involved components
The tests for HasEnvironmentScope and any the tests of any CE/EE modules that prepend it.
Additional details
The reason I found it hard to extract is due to the lack of uniformity between the scope's consumers:
- For
Clusters::Cluster, the scope is applied to the results of different queries depending on the type of the cluster (a cluster can be instance level, group level or project level) - For
Ci::Variable, the environment scopes are project specific - For
Operations::FeatureFlagScope, the environment scope isOperations::FeatureFlag-specific, and the*scope seems to get explicitly built for every feature flag (as opposed to being implicit like it is for variables)