Replace Flipper's built-in test helper

It fails in CI and features are not seen as enabled. So we copy the
important part of the test helper into our code, which works.

It's probably about the point in time when the adapter is instantiated.
This commit is contained in:
Maikel Linke
2024-04-23 15:02:45 +10:00
parent 75f343b42f
commit ea0558c70e
2 changed files with 17 additions and 2 deletions

View File

@@ -2,8 +2,23 @@ require "flipper"
require "flipper/adapters/active_record"
require "open_food_network/feature_toggle"
Flipper.register(:admins) { |actor| actor.respond_to?(:admin?) && actor.admin? }
Rails.application.configure do
# Disable Flipper's built-in test helper.
# It fails in CI and feature don't get activated.
config.flipper.test_help = false
end
Flipper.configure do |flipper|
# Still use recommended test setup with faster memory adapter:
if Rails.env.test?
# Use a shared Memory adapter for all tests. The adapter is instantiated
# outside of the block so the same instance is returned in new threads.
adapter = Flipper::Adapters::Memory.new
flipper.adapter { adapter }
end
end
Flipper.register(:admins) { |actor| actor.respond_to?(:admin?) && actor.admin? }
Flipper::UI.configure do |config|
config.descriptions_source = ->(_keys) do
# return has to be hash of {String key => String description}

View File

@@ -102,7 +102,7 @@ RSpec.configure do |config|
end
# Reset all feature toggles to prevent leaking.
config.before(:suite) do
config.before(:each) do
Flipper.features.each(&:remove)
OpenFoodNetwork::FeatureToggle.setup!
end