Extract HasEnvironmentScope tests into shared examples
## Summary <!-- Please briefly describe what part of the code base needs to be refactored. --> 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 <!-- Explain the benefits of refactoring this code. See also https://about.gitlab.com/handbook/values/index.html#say-why-not-just-what --> Shared examples can be included in the tests of each consuming class, letting us more confidently modify `HasEnvironmentScope`. ## Risks <!-- Please list features that can break because of this refactoring and how you intend to solve that. --> 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 is `Operations::FeatureFlag`-specific, and the `*` scope seems to get explicitly built for every feature flag (as opposed to being implicit like it is for variables)
issue