diff --git a/lib/open_food_network/feature_toggle.rb b/lib/open_food_network/feature_toggle.rb index 59f4b51c41..dd45753b16 100644 --- a/lib/open_food_network/feature_toggle.rb +++ b/lib/open_food_network/feature_toggle.rb @@ -3,15 +3,14 @@ module OpenFoodNetwork # Feature toggles are configured via Flipper. # - # We define features in the initializer and then it can be customised via the - # web interface on each server. - # # - config/initializers/flipper.rb # - http://localhost:3000/admin/feature-toggle/features # module FeatureToggle def self.enabled?(feature_name, user = nil) - Flipper.enabled?(feature_name, user) + feature = Flipper.feature(feature_name) + feature.add unless feature.exist? + feature.enabled?(user) end end end diff --git a/spec/lib/open_food_network/feature_toggle_spec.rb b/spec/lib/open_food_network/feature_toggle_spec.rb index 97e41108a6..ce18fb5bba 100644 --- a/spec/lib/open_food_network/feature_toggle_spec.rb +++ b/spec/lib/open_food_network/feature_toggle_spec.rb @@ -13,6 +13,13 @@ module OpenFoodNetwork Flipper.enable(:foo) expect(FeatureToggle.enabled?(:foo)).to be true end + + it "adds features to the database for easy admin in the UI" do + feature = Flipper.feature(:sparkling_new) + + expect { FeatureToggle.enabled?(:sparkling_new) }. + to change { feature.exist? }.from(false).to(true) + end end end end