mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add used feature toggles to appear in the admin UI
The admin UI shows only features which were added to the database. We always had to look up a feature's name add it manually before we could enable it. Now it will appear in the UI after some code asked if it was enabled. This only adds a database query once when the feature doesn't exist yet. The `feature.exist?` call only performs an in-memory lookup in the memoizer.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user