mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
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:
committed by
Jean-Baptiste Bellet
parent
b045a59685
commit
7a0912d5a4
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user