From 52e934ec2b9173e161aa9b4b728e4151fbb8f4ea Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 6 Oct 2022 09:33:58 +1100 Subject: [PATCH] Consistently use our FeatureToggle module Direct calls to Flipper have the downside that we can't add any new functionality like storing the feature in the database when used. --- app/controllers/api/v1/base_controller.rb | 2 +- app/controllers/concerns/order_stock_check.rb | 2 +- app/models/spree/order.rb | 4 ++-- config/routes/api.rb | 2 +- .../payment_gateways/stripe_controller_spec.rb | 6 ++++-- spec/controllers/split_checkout_controller_spec.rb | 6 ++++-- spec/system/consumer/shopping/checkout_auth_spec.rb | 4 ++-- spec/system/consumer/split_checkout_spec.rb | 4 ++-- spec/system/consumer/split_checkout_tax_incl_spec.rb | 12 ++++++++---- .../consumer/split_checkout_tax_not_incl_spec.rb | 12 ++++++++---- 10 files changed, 33 insertions(+), 21 deletions(-) diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index a0fbfad70d..e01fe3aab3 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -40,7 +40,7 @@ module Api end def restrict_feature - not_found unless Flipper.enabled?(:api_v1, @current_api_user) + not_found unless OpenFoodNetwork::FeatureToggle.enabled?(:api_v1, @current_api_user) end def current_ability diff --git a/app/controllers/concerns/order_stock_check.rb b/app/controllers/concerns/order_stock_check.rb index b0301c3608..4b00877e92 100644 --- a/app/controllers/concerns/order_stock_check.rb +++ b/app/controllers/concerns/order_stock_check.rb @@ -39,7 +39,7 @@ module OrderStockCheck end def reset_order_to_cart - return if Flipper.enabled? :split_checkout, spree_current_user + return if OpenFoodNetwork::FeatureToggle.enabled? :split_checkout, spree_current_user OrderCheckoutRestart.new(@order).call end diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 2c2df175cd..53172c01d9 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -25,7 +25,7 @@ module Spree order.payment_required? } go_to_state :confirmation, if: ->(order) { - Flipper.enabled? :split_checkout, order.created_by + OpenFoodNetwork::FeatureToggle.enabled? :split_checkout, order.created_by } go_to_state :complete end @@ -311,7 +311,7 @@ module Spree # Creates new tax charges if there are any applicable rates. If prices already # include taxes then price adjustments are created instead. def create_tax_charge! - return if state.in?(["cart", "address", "delivery"]) && Flipper.enabled?(:split_checkout) + return if state.in?(["cart", "address", "delivery"]) && OpenFoodNetwork::FeatureToggle.enabled?(:split_checkout) clear_legacy_taxes! diff --git a/config/routes/api.rb b/config/routes/api.rb index f7bc47085e..0a830a60f2 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -84,7 +84,7 @@ Openfoodnetwork::Application.routes.draw do end get '/reports/:report_type(/:report_subtype)', to: 'reports#show', - constraints: lambda { |_| Flipper.enabled?(:api_reports) } + constraints: lambda { |_| OpenFoodNetwork::FeatureToggle.enabled?(:api_reports) } end namespace :v1 do diff --git a/spec/controllers/payment_gateways/stripe_controller_spec.rb b/spec/controllers/payment_gateways/stripe_controller_spec.rb index fe68206148..60f95abd39 100644 --- a/spec/controllers/payment_gateways/stripe_controller_spec.rb +++ b/spec/controllers/payment_gateways/stripe_controller_spec.rb @@ -88,8 +88,10 @@ module PaymentGateways context "using split checkout" do before do - allow(Flipper).to receive(:enabled?).with(:split_checkout) { true } - allow(Flipper).to receive(:enabled?).with(:split_checkout, anything) { true } + allow(OpenFoodNetwork::FeatureToggle). + to receive(:enabled?).with(:split_checkout) { true } + allow(OpenFoodNetwork::FeatureToggle). + to receive(:enabled?).with(:split_checkout, anything) { true } order.update_attribute :state, "confirmation" end diff --git a/spec/controllers/split_checkout_controller_spec.rb b/spec/controllers/split_checkout_controller_spec.rb index 13120a8d09..1b3e71c73a 100644 --- a/spec/controllers/split_checkout_controller_spec.rb +++ b/spec/controllers/split_checkout_controller_spec.rb @@ -16,8 +16,10 @@ describe SplitCheckoutController, type: :controller do let(:shipping_method) { distributor.shipping_methods.first } before do - allow(Flipper).to receive(:enabled?).with(:split_checkout) { true } - allow(Flipper).to receive(:enabled?).with(:split_checkout, anything) { true } + allow(OpenFoodNetwork::FeatureToggle). + to receive(:enabled?).with(:split_checkout) { true } + allow(OpenFoodNetwork::FeatureToggle). + to receive(:enabled?).with(:split_checkout, anything) { true } exchange.variants << order.line_items.first.variant allow(controller).to receive(:current_order) { order } diff --git a/spec/system/consumer/shopping/checkout_auth_spec.rb b/spec/system/consumer/shopping/checkout_auth_spec.rb index 747a6d2413..389c5a4eaf 100644 --- a/spec/system/consumer/shopping/checkout_auth_spec.rb +++ b/spec/system/consumer/shopping/checkout_auth_spec.rb @@ -83,8 +83,8 @@ describe "As a consumer I want to check out my cart", js: true do context "split checkout" do before do - allow(Flipper).to receive(:enabled?).with(:split_checkout) { true } - allow(Flipper).to receive(:enabled?).with(:split_checkout, anything) { true } + allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(:split_checkout) { true } + allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(:split_checkout, anything) { true } end include_examples "with different checkout types", "split_checkout" end diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index ab6568c2f0..b5e21b83ce 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -65,8 +65,8 @@ describe "As a consumer, I want to checkout my order", js: true do } before do - allow(Flipper).to receive(:enabled?).with(:split_checkout).and_return(true) - allow(Flipper).to receive(:enabled?).with(:split_checkout, anything).and_return(true) + allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(:split_checkout).and_return(true) + allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(:split_checkout, anything).and_return(true) add_enterprise_fee enterprise_fee set_order order diff --git a/spec/system/consumer/split_checkout_tax_incl_spec.rb b/spec/system/consumer/split_checkout_tax_incl_spec.rb index 909e564a68..96199c4a2a 100644 --- a/spec/system/consumer/split_checkout_tax_incl_spec.rb +++ b/spec/system/consumer/split_checkout_tax_incl_spec.rb @@ -111,8 +111,10 @@ describe "As a consumer, I want to see adjustment breakdown" do context "on split-checkout" do before do - allow(Flipper).to receive(:enabled?).with(:split_checkout).and_return(true) - allow(Flipper).to receive(:enabled?).with(:split_checkout, anything).and_return(true) + allow(OpenFoodNetwork::FeatureToggle). + to receive(:enabled?).with(:split_checkout).and_return(true) + allow(OpenFoodNetwork::FeatureToggle). + to receive(:enabled?).with(:split_checkout, anything).and_return(true) set_order order_within_zone login_as(user_within_zone) @@ -169,8 +171,10 @@ describe "As a consumer, I want to see adjustment breakdown" do context "on split-checkout" do before do - allow(Flipper).to receive(:enabled?).with(:split_checkout).and_return(true) - allow(Flipper).to receive(:enabled?).with(:split_checkout, anything).and_return(true) + allow(OpenFoodNetwork::FeatureToggle). + to receive(:enabled?).with(:split_checkout).and_return(true) + allow(OpenFoodNetwork::FeatureToggle). + to receive(:enabled?).with(:split_checkout, anything).and_return(true) set_order order_outside_zone login_as(user_outside_zone) diff --git a/spec/system/consumer/split_checkout_tax_not_incl_spec.rb b/spec/system/consumer/split_checkout_tax_not_incl_spec.rb index 1d0d24ec08..ac376980a7 100644 --- a/spec/system/consumer/split_checkout_tax_not_incl_spec.rb +++ b/spec/system/consumer/split_checkout_tax_not_incl_spec.rb @@ -118,8 +118,10 @@ describe "As a consumer, I want to see adjustment breakdown" do context "on split-checkout" do before do - allow(Flipper).to receive(:enabled?).with(:split_checkout).and_return(true) - allow(Flipper).to receive(:enabled?).with(:split_checkout, anything).and_return(true) + allow(OpenFoodNetwork::FeatureToggle). + to receive(:enabled?).with(:split_checkout).and_return(true) + allow(OpenFoodNetwork::FeatureToggle). + to receive(:enabled?).with(:split_checkout, anything).and_return(true) set_order order_within_zone login_as(user_within_zone) @@ -179,8 +181,10 @@ describe "As a consumer, I want to see adjustment breakdown" do context "on split-checkout" do before do - allow(Flipper).to receive(:enabled?).with(:split_checkout).and_return(true) - allow(Flipper).to receive(:enabled?).with(:split_checkout, anything).and_return(true) + allow(OpenFoodNetwork::FeatureToggle). + to receive(:enabled?).with(:split_checkout).and_return(true) + allow(OpenFoodNetwork::FeatureToggle). + to receive(:enabled?).with(:split_checkout, anything).and_return(true) set_order order_outside_zone login_as(user_outside_zone)