mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Merge pull request #9806 from mkllnk/feature-constraint
Generalise feature toggle constraint
This commit is contained in:
15
app/constraints/feature_toggle_constraint.rb
Normal file
15
app/constraints/feature_toggle_constraint.rb
Normal 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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user