diff --git a/db/migrate/20231129222807_enable_feature_backround_reports.rb b/db/migrate/20231129222807_enable_feature_backround_reports.rb new file mode 100644 index 0000000000..a0688cb66c --- /dev/null +++ b/db/migrate/20231129222807_enable_feature_backround_reports.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class EnableFeatureBackroundReports < ActiveRecord::Migration[7.0] + def up + Flipper.enable("background_reports") + end +end diff --git a/lib/open_food_network/feature_toggle.rb b/lib/open_food_network/feature_toggle.rb index ccced3415c..f1a075ef8f 100644 --- a/lib/open_food_network/feature_toggle.rb +++ b/lib/open_food_network/feature_toggle.rb @@ -10,6 +10,17 @@ module OpenFoodNetwork # Please add your new feature here to appear in the Flipper UI. # We way move this to a YAML file when it becomes too awkward. # **WARNING:** Features not in this list will be removed. + # + # Once the feature is ready for general production use, + # copy the feature declaration to ACTIVE_BY_DEFAULT below and + # activate it for all instances with a migration: + # + # ./bin/rails generate migration EnableFeatureDragonMode + # + # Replace the `change` method with an `up` method and add this line: + # + # Flipper.enable("dragon_mode") + # CURRENT_FEATURES = { "admin_style_v3" => <<~DESC, Test the work-in-progress design updates. @@ -38,10 +49,23 @@ module OpenFoodNetwork DESC }.freeze + # Features you would like to be enabled to start with. + # + # Copy features here that were activated in a migration so that new + # instances, development and test environments have the feature active. + ACTIVE_BY_DEFAULT = { + "background_reports" => <<~DESC, + Generate reports in a background process to limit memory consumption. + DESC + }.freeze + def self.setup! CURRENT_FEATURES.each_key do |name| feature = Flipper.feature(name) - feature.add unless feature.exist? + unless feature.exist? + feature.add + feature.enable if ACTIVE_BY_DEFAULT[name] + end end Flipper.features.each do |feature| diff --git a/spec/base_spec_helper.rb b/spec/base_spec_helper.rb index ad026026ed..36895456dd 100644 --- a/spec/base_spec_helper.rb +++ b/spec/base_spec_helper.rb @@ -88,6 +88,33 @@ RSpec.configure do |config| expectations.syntax = :expect end + # Reset all feature toggles to prevent leaking. + config.before(:suite) do + Flipper.features.each(&:remove) + OpenFoodNetwork::FeatureToggle.setup! + end + + config.before(:each) do |example| + Flipper.disable(:background_reports) if example.file_path.in?( + [ + # rubocop:disable Layout/LineLength + "./spec/controllers/admin/reports_controller_spec.rb", + "./spec/system/admin/reports/enterprise_fee_summaries_spec.rb", + "./spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_order_spec.rb", + "./spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb", + "./spec/system/admin/reports/orders_and_fulfillment_spec.rb", + "./spec/system/admin/reports/packing_report_spec.rb", + "./spec/system/admin/reports/payments_report_spec.rb", + "./spec/system/admin/reports/revenues_by_hub_spec.rb", + "./spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb", + "./spec/system/admin/reports/sales_tax/sales_tax_totals_by_producer_spec.rb", + "./spec/system/admin/reports/users_and_enterprises_spec.rb", + "./spec/system/admin/reports_spec.rb", + # rubocop:enable Layout/LineLength + ] + ) + end + config.before(:each, :feature) do |example| feature = example.metadata[:feature].to_s