diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/support/helpers/stubbed_feature.rb | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/support/helpers/stubbed_feature.rb')
-rw-r--r-- | spec/support/helpers/stubbed_feature.rb | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/spec/support/helpers/stubbed_feature.rb b/spec/support/helpers/stubbed_feature.rb index d4e9af7a031..67ceb7d9b35 100644 --- a/spec/support/helpers/stubbed_feature.rb +++ b/spec/support/helpers/stubbed_feature.rb @@ -4,6 +4,14 @@ module StubbedFeature extend ActiveSupport::Concern + prepended do + cattr_reader(:persist_used) do + # persist feature flags in CI + # nil: indicates that we do not want to persist used feature flags + Gitlab::Utils.to_boolean(ENV['CI']) ? {} : nil + end + end + class_methods do # Turn stubbed feature flags on or off. def stub=(stub) @@ -29,10 +37,12 @@ module StubbedFeature end # Replace #enabled? method with the optional stubbed/unstubbed version. - def enabled?(*args) - feature_flag = super(*args) + def enabled?(*args, **kwargs) + feature_flag = super return feature_flag unless stub? + persist_used!(args.first) + # If feature flag is not persisted we mark the feature flag as enabled # We do `m.call` as we want to validate the execution of method arguments # and a feature flag state if it is not persisted @@ -42,5 +52,17 @@ module StubbedFeature feature_flag end + + # This method creates a temporary file in `tmp/feature_flags` + # if feature flag was touched during execution + def persist_used!(name) + return unless persist_used + return if persist_used[name] + + persist_used[name] = true + FileUtils.touch( + Rails.root.join('tmp', 'feature_flags', name.to_s + ".used") + ) + end end end |