diff options
author | Rémy Coutable <remy@rymai.me> | 2018-07-23 10:11:12 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-07-23 10:11:12 +0000 |
commit | cc540bb2a2177825ed52adbaff468566826279ad (patch) | |
tree | 6c010408b3972f9a3b133f5da4d77d42b7f57907 | |
parent | e3dac36b71f33751fee3fbd1034688da933bf1b4 (diff) | |
parent | 06e03f6e4d3d60e30b38fe218a27c3907a3911cc (diff) | |
download | gitlab-ce-cc540bb2a2177825ed52adbaff468566826279ad.tar.gz |
Merge branch 'da-feature-flags' into 'master'
Allow feature flag names to be a symbol
See merge request gitlab-org/gitlab-ce!20728
-rw-r--r-- | lib/feature.rb | 2 | ||||
-rw-r--r-- | spec/lib/feature_spec.rb | 32 |
2 files changed, 26 insertions, 8 deletions
diff --git a/lib/feature.rb b/lib/feature.rb index 314ae224d90..d27b2b0e72f 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -39,7 +39,7 @@ class Feature # Flipper creates on-memory features when asked for a not-yet-created one. # If we want to check if a feature has been actually set, we look for it # on the persisted features list. - persisted_names.include?(feature.name) + persisted_names.include?(feature.name.to_s) end def enabled?(key, thing = nil) diff --git a/spec/lib/feature_spec.rb b/spec/lib/feature_spec.rb index 6eb10497428..f313e675654 100644 --- a/spec/lib/feature_spec.rb +++ b/spec/lib/feature_spec.rb @@ -39,18 +39,36 @@ describe Feature do end describe '.persisted?' do - it 'returns true for a persisted feature' do - Feature::FlipperFeature.create!(key: 'foo') + context 'when the feature is persisted' do + it 'returns true when feature name is a string' do + Feature::FlipperFeature.create!(key: 'foo') + + feature = double(:feature, name: 'foo') + + expect(described_class.persisted?(feature)).to eq(true) + end + + it 'returns true when feature name is a symbol' do + Feature::FlipperFeature.create!(key: 'foo') - feature = double(:feature, name: 'foo') + feature = double(:feature, name: :foo) - expect(described_class.persisted?(feature)).to eq(true) + expect(described_class.persisted?(feature)).to eq(true) + end end - it 'returns false for a feature that is not persisted' do - feature = double(:feature, name: 'foo') + context 'when the feature is not persisted' do + it 'returns false when feature name is a string' do + feature = double(:feature, name: 'foo') + + expect(described_class.persisted?(feature)).to eq(false) + end - expect(described_class.persisted?(feature)).to eq(false) + it 'returns false when feature name is a symbol' do + feature = double(:feature, name: :bar) + + expect(described_class.persisted?(feature)).to eq(false) + end end end |