Merge pull request #9806 from mkllnk/feature-constraint

Generalise feature toggle constraint
This commit is contained in:
jibees
2022-10-20 17:27:46 +02:00
committed by GitHub
4 changed files with 17 additions and 13 deletions

View File

@@ -0,0 +1,15 @@
# frozen_string_literal: true
class FeatureToggleConstraint
def initialize(feature_name)
@feature = feature_name
end
def matches?(request)
OpenFoodNetwork::FeatureToggle.enabled?(@feature, current_user(request))
end
def current_user(request)
request.env['warden'].user
end
end

View File

@@ -1,11 +0,0 @@
# frozen_string_literal: true
class SplitCheckoutConstraint
def matches?(request)
OpenFoodNetwork::FeatureToggle.enabled? :split_checkout, current_user(request)
end
def current_user(request)
request.env['warden'].user
end
end

View File

@@ -84,7 +84,7 @@ Openfoodnetwork::Application.routes.draw do
get "/stripe/authorize/:order_number", to: "stripe#authorize", as: :authorize_stripe
end
constraints SplitCheckoutConstraint.new do
constraints FeatureToggleConstraint.new(:split_checkout) do
get '/checkout', to: 'split_checkout#edit'
constraints step: /(details|payment|summary)/ do

View File

@@ -4,7 +4,7 @@ require "spec_helper"
describe "routing for Stripe return URLS", type: :routing do
before do
allow_any_instance_of(SplitCheckoutConstraint).to receive(:current_user) { build(:user) }
allow_any_instance_of(FeatureToggleConstraint).to receive(:current_user) { build(:user) }
end
context "checkout return URLs" do