diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/lib/feature_spec.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/lib/feature_spec.rb')
-rw-r--r-- | spec/lib/feature_spec.rb | 99 |
1 files changed, 46 insertions, 53 deletions
diff --git a/spec/lib/feature_spec.rb b/spec/lib/feature_spec.rb index 37f8d3ad47d..acd7d97ac85 100644 --- a/spec/lib/feature_spec.rb +++ b/spec/lib/feature_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Feature, stub_feature_flags: false do +RSpec.describe Feature, stub_feature_flags: false do before do # reset Flipper AR-engine Feature.reset @@ -21,66 +21,29 @@ describe Feature, stub_feature_flags: false do end describe '.persisted_names' do - context 'when FF_LEGACY_PERSISTED_NAMES=false' do - before do - stub_env('FF_LEGACY_PERSISTED_NAMES', 'false') - end - - it 'returns the names of the persisted features' do - Feature.enable('foo') - - expect(described_class.persisted_names).to contain_exactly('foo') - end - - it 'returns an empty Array when no features are presisted' do - expect(described_class.persisted_names).to be_empty - end - - it 'caches the feature names when request store is active', - :request_store, :use_clean_rails_memory_store_caching do - Feature.enable('foo') + it 'returns the names of the persisted features' do + Feature.enable('foo') - expect(Gitlab::ProcessMemoryCache.cache_backend) - .to receive(:fetch) - .once - .with('flipper/v1/features', expires_in: 1.minute) - .and_call_original + expect(described_class.persisted_names).to contain_exactly('foo') + end - 2.times do - expect(described_class.persisted_names).to contain_exactly('foo') - end - end + it 'returns an empty Array when no features are presisted' do + expect(described_class.persisted_names).to be_empty end - context 'when FF_LEGACY_PERSISTED_NAMES=true' do - before do - stub_env('FF_LEGACY_PERSISTED_NAMES', 'true') - end + it 'caches the feature names when request store is active', + :request_store, :use_clean_rails_memory_store_caching do + Feature.enable('foo') - it 'returns the names of the persisted features' do - Feature.enable('foo') + expect(Gitlab::ProcessMemoryCache.cache_backend) + .to receive(:fetch) + .once + .with('flipper/v1/features', expires_in: 1.minute) + .and_call_original + 2.times do expect(described_class.persisted_names).to contain_exactly('foo') end - - it 'returns an empty Array when no features are presisted' do - expect(described_class.persisted_names).to be_empty - end - - it 'caches the feature names when request store is active', - :request_store, :use_clean_rails_memory_store_caching do - Feature.enable('foo') - - expect(Gitlab::ProcessMemoryCache.cache_backend) - .to receive(:fetch) - .once - .with('flipper:persisted_names', expires_in: 1.minute) - .and_call_original - - 2.times do - expect(described_class.persisted_names).to contain_exactly('foo') - end - end end it 'fetches all flags once in a single query', :request_store do @@ -279,6 +242,36 @@ describe Feature, stub_feature_flags: false do end end end + + context 'validates usage of feature flag with YAML definition' do + let(:definition) do + Feature::Definition.new('development/my_feature_flag.yml', + name: 'my_feature_flag', + type: 'development', + default_enabled: false + ).tap(&:validate!) + end + + before do + allow(Feature::Definition).to receive(:definitions) do + { definition.key => definition } + end + end + + it 'when usage is correct' do + expect { described_class.enabled?(:my_feature_flag) }.not_to raise_error + end + + it 'when invalid type is used' do + expect { described_class.enabled?(:my_feature_flag, type: :licensed) } + .to raise_error(/The `type:` of/) + end + + it 'when invalid default_enabled is used' do + expect { described_class.enabled?(:my_feature_flag, default_enabled: true) } + .to raise_error(/The `default_enabled:` of/) + end + end end describe '.disable?' do |