diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-30 21:08:47 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-30 21:08:47 +0000 |
commit | c8f773a8593926f4f2dec6f446a3b3e59e9c9909 (patch) | |
tree | 4e5ea1d3b861ff99015f6112da567de7873868aa /spec/graphql/types/base_field_spec.rb | |
parent | 929b887e5391dea7cb53b88b77b9a35351c87d99 (diff) | |
download | gitlab-ce-c8f773a8593926f4f2dec6f446a3b3e59e9c9909.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql/types/base_field_spec.rb')
-rw-r--r-- | spec/graphql/types/base_field_spec.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/graphql/types/base_field_spec.rb b/spec/graphql/types/base_field_spec.rb index 77ef8933717..1f82f316aa7 100644 --- a/spec/graphql/types/base_field_spec.rb +++ b/spec/graphql/types/base_field_spec.rb @@ -111,5 +111,70 @@ describe Types::BaseField do end end end + + describe '#visible?' do + context 'and has a feature_flag' do + let(:flag) { :test_feature } + let(:field) { described_class.new(name: 'test', type: GraphQL::STRING_TYPE, feature_flag: flag, null: false) } + let(:context) { {} } + + 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 + + context 'falsey feature_flag values' do + using RSpec::Parameterized::TableSyntax + + where(:flag, :feature_value, :visible) do + '' | false | true + '' | true | true + nil | false | true + nil | true | true + end + + with_them do + it 'returns the correct value' do + stub_feature_flags(flag => feature_value) + + expect(field.visible?(context)).to eq(visible) + end + end + end + end + end + + describe '#description' do + context 'feature flag given' do + let(:field) { described_class.new(name: 'test', type: GraphQL::STRING_TYPE, feature_flag: flag, null: false, description: 'Test description') } + let(:flag) { :test_flag } + + it 'prepends the description' do + expect(field.description). to eq 'Test description. Available only when feature flag test_flag is enabled.' + end + + context 'falsey feature_flag values' do + using RSpec::Parameterized::TableSyntax + + where(:flag, :feature_value) do + '' | false + '' | true + nil | false + nil | true + end + + with_them do + it 'returns the correct description' do + expect(field.description).to eq('Test description') + end + end + end + end + end end end |