From 231887f48f9ef8a794b78412d70d8a75111da86e Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro <noreply@pedro.pombei.ro> Date: Mon, 12 Jul 2021 11:30:08 +0200 Subject: [PATCH] Use YAML default state in GraphQL feature flags --- app/graphql/types/base_field.rb | 2 +- spec/graphql/features/feature_flag_spec.rb | 21 +++++++++++++++----- spec/graphql/types/base_field_spec.rb | 23 ++++++++++++++++------ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/app/graphql/types/base_field.rb b/app/graphql/types/base_field.rb index 47caf83eb1c9..ce2f184bcb44 100644 --- a/app/graphql/types/base_field.rb +++ b/app/graphql/types/base_field.rb @@ -65,7 +65,7 @@ def constant_complexity? end def visible?(context) - return false if feature_flag.present? && !Feature.enabled?(feature_flag) + return false if feature_flag.present? && !Feature.enabled?(feature_flag, default_enabled: :yaml) super end diff --git a/spec/graphql/features/feature_flag_spec.rb b/spec/graphql/features/feature_flag_spec.rb index 30238cf9cb34..e5560fccf894 100644 --- a/spec/graphql/features/feature_flag_spec.rb +++ b/spec/graphql/features/feature_flag_spec.rb @@ -28,14 +28,25 @@ end end - it 'returns the value when feature is enabled' do - expect(subject['item']).to eq('name' => test_object.name) + it 'checks YAML definition for default_enabled' do + # Exception is indicative of a check for YAML definition + expect { subject }.to raise_error(Feature::InvalidFeatureFlagError, /The feature flag YAML definition for '#{feature_flag}' does not exist/) end - it 'returns nil when the feature is disabled' do - stub_feature_flags(feature_flag => false) + context 'skipping YAML check' do + before do + skip_default_enabled_yaml_check + end + + it 'returns the value when feature is enabled' do + expect(subject['item']).to eq('name' => test_object.name) + end - expect(subject).to be_nil + it 'returns nil when the feature is disabled' do + stub_feature_flags(feature_flag => false) + + expect(subject).to be_nil + end end end end diff --git a/spec/graphql/types/base_field_spec.rb b/spec/graphql/types/base_field_spec.rb index 54b59317b558..ebdb3299bc91 100644 --- a/spec/graphql/types/base_field_spec.rb +++ b/spec/graphql/types/base_field_spec.rb @@ -130,14 +130,25 @@ def self.complexity_multiplier(args) skip_feature_flags_yaml_validation end - it 'returns false if the feature is not enabled' do - stub_feature_flags(flag => false) - - expect(field.visible?(context)).to eq(false) + it 'checks YAML definition for default_enabled' do + # Exception is indicative of a check for YAML definition + expect { field.visible?(context) }.to raise_error(Feature::InvalidFeatureFlagError, /The feature flag YAML definition for '#{flag}' does not exist/) end - it 'returns true if the feature is enabled' do - expect(field.visible?(context)).to eq(true) + context 'skipping YAML check' do + before do + skip_default_enabled_yaml_check + end + + it 'returns false if the feature is not enabled' do + stub_feature_flags(flag => false) + + expect(field.visible?(context)).to eq(false) + end + + it 'returns true if the feature is enabled' do + expect(field.visible?(context)).to eq(true) + end end end end -- GitLab