From 56667f61427edded589a0279d94b6325b0e1fa3f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 27 Oct 2022 15:32:05 +1100 Subject: [PATCH] Simplify test setup with enabled features If a feature is activated or not depends on the database which is reset after each test scenario. So enabling a feature doesn't leak into other scenarios. Just enabling the feature is less code and more realistic than mocking a method call. --- .../payment_gateways/stripe_controller_spec.rb | 5 +---- spec/controllers/split_checkout_controller_spec.rb | 5 +---- spec/system/consumer/shopping/checkout_auth_spec.rb | 3 +-- spec/system/consumer/split_checkout_spec.rb | 3 +-- spec/system/consumer/split_checkout_tax_incl_spec.rb | 10 ++-------- .../consumer/split_checkout_tax_not_incl_spec.rb | 10 ++-------- 6 files changed, 8 insertions(+), 28 deletions(-) diff --git a/spec/controllers/payment_gateways/stripe_controller_spec.rb b/spec/controllers/payment_gateways/stripe_controller_spec.rb index 60f95abd39..3644ccb70a 100644 --- a/spec/controllers/payment_gateways/stripe_controller_spec.rb +++ b/spec/controllers/payment_gateways/stripe_controller_spec.rb @@ -88,10 +88,7 @@ module PaymentGateways context "using split checkout" do before do - allow(OpenFoodNetwork::FeatureToggle). - to receive(:enabled?).with(:split_checkout) { true } - allow(OpenFoodNetwork::FeatureToggle). - to receive(:enabled?).with(:split_checkout, anything) { true } + Flipper.enable(:split_checkout) 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 1b3e71c73a..40c1f0b354 100644 --- a/spec/controllers/split_checkout_controller_spec.rb +++ b/spec/controllers/split_checkout_controller_spec.rb @@ -16,10 +16,7 @@ describe SplitCheckoutController, type: :controller do let(:shipping_method) { distributor.shipping_methods.first } before do - allow(OpenFoodNetwork::FeatureToggle). - to receive(:enabled?).with(:split_checkout) { true } - allow(OpenFoodNetwork::FeatureToggle). - to receive(:enabled?).with(:split_checkout, anything) { true } + Flipper.enable(:split_checkout) 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 389c5a4eaf..d9aa53581a 100644 --- a/spec/system/consumer/shopping/checkout_auth_spec.rb +++ b/spec/system/consumer/shopping/checkout_auth_spec.rb @@ -83,8 +83,7 @@ describe "As a consumer I want to check out my cart", js: true do context "split checkout" do before do - allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(:split_checkout) { true } - allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(:split_checkout, anything) { true } + Flipper.enable(:split_checkout) 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 b5e21b83ce..038a2667ca 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -65,8 +65,7 @@ describe "As a consumer, I want to checkout my order", js: true do } before do - 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) + Flipper.enable(:split_checkout) 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 96199c4a2a..146104e824 100644 --- a/spec/system/consumer/split_checkout_tax_incl_spec.rb +++ b/spec/system/consumer/split_checkout_tax_incl_spec.rb @@ -111,10 +111,7 @@ describe "As a consumer, I want to see adjustment breakdown" do context "on split-checkout" do before do - 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) + Flipper.enable(:split_checkout) set_order order_within_zone login_as(user_within_zone) @@ -171,10 +168,7 @@ describe "As a consumer, I want to see adjustment breakdown" do context "on split-checkout" do before do - 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) + Flipper.enable(:split_checkout) 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 ac376980a7..340063c0fd 100644 --- a/spec/system/consumer/split_checkout_tax_not_incl_spec.rb +++ b/spec/system/consumer/split_checkout_tax_not_incl_spec.rb @@ -118,10 +118,7 @@ describe "As a consumer, I want to see adjustment breakdown" do context "on split-checkout" do before do - 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) + Flipper.enable(:split_checkout) set_order order_within_zone login_as(user_within_zone) @@ -181,10 +178,7 @@ describe "As a consumer, I want to see adjustment breakdown" do context "on split-checkout" do before do - 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) + Flipper.enable(:split_checkout) set_order order_outside_zone login_as(user_outside_zone)