Merge pull request #9889 from mkllnk/dfc-products

Activate DfcProvider with feature toggle, not prod
This commit is contained in:
Sigmund Petersen
2022-11-16 12:26:44 +01:00
committed by GitHub
11 changed files with 12 additions and 46 deletions

View File

@@ -1,5 +1,7 @@
# frozen_string_literal: true
require "open_food_network/feature_toggle"
class FeatureToggleConstraint
def initialize(feature_name)
@feature = feature_name
@@ -10,6 +12,6 @@ class FeatureToggleConstraint
end
def current_user(request)
request.env['warden'].user
request.env['warden']&.user
end
end

View File

@@ -117,7 +117,7 @@ Openfoodnetwork::Application.routes.draw do
get 'sitemap.xml', to: 'sitemap#index', defaults: { format: 'xml' }
unless Rails.env.production?
constraints FeatureToggleConstraint.new(:dfc_provider) do
# Mount DFC API endpoints
mount DfcProvider::Engine, at: '/'
end

View File

@@ -129,7 +129,6 @@ RSpec.configure do |config|
config.include Spree::UrlHelpers
config.include Spree::MoneyHelper
config.include PreferencesHelper
config.include OpenFoodNetwork::FeatureToggleHelper
config.include OpenFoodNetwork::FiltersHelper
config.include OpenFoodNetwork::EnterpriseGroupsHelper
config.include OpenFoodNetwork::ProductsHelper

View File

@@ -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

View File

@@ -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 }

View File

@@ -3,10 +3,6 @@
require "spec_helper"
describe "routing for Stripe return URLS", type: :routing do
before do
allow_any_instance_of(FeatureToggleConstraint).to receive(:current_user) { build(:user) }
end
context "checkout return URLs" do
it "routes /checkout to checkout#edit" do
expect(get: "checkout").

View File

@@ -1,11 +0,0 @@
# frozen_string_literal: true
module OpenFoodNetwork
module FeatureToggleHelper
def set_feature_toggle(feature, status)
features = OpenFoodNetwork::FeatureToggle.features
features[feature] = status
allow(OpenFoodNetwork::FeatureToggle).to receive(:features) { features }
end
end
end

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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)