Use Flipper within the OFN FeatureToggle interface

This ensures that we keep the same interface as before and can migrate
to Flipper in a backwards-compatible way.
This commit is contained in:
Maikel Linke
2021-04-06 15:59:15 +10:00
committed by Jean-Baptiste Bellet
parent b045a59685
commit 7a0912d5a4
2 changed files with 17 additions and 2 deletions

View File

@@ -40,8 +40,12 @@ module OpenFoodNetwork
end
def enabled?(feature_name, user)
feature = features.fetch(feature_name, DefaultFeature.new(feature_name))
feature.enabled?(user)
if Flipper[feature_name].exist?
Flipper.enabled?(feature_name, user)
else
feature = features.fetch(feature_name, DefaultFeature.new(feature_name))
feature.enabled?(user)
end
end
private

View File

@@ -24,6 +24,17 @@ module OpenFoodNetwork
expect(FeatureToggle.enabled?(:foo)).to be false
end
it "uses Flipper configuration" do
Flipper.enable(:foo)
expect(FeatureToggle.enabled?(:foo)).to be true
end
it "uses Flipper over static config" do
Flipper.enable(:foo, false)
stub_foo("true")
expect(FeatureToggle.enabled?(:foo)).to be false
end
def stub_foo(value)
allow(ENV).to receive(:fetch).with("OFN_FEATURE_FOO", nil).and_return(value)
end