From 379eda7c412a1af320ec78865a70e8116ea51b3e Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 8 Mar 2022 10:44:33 +1100 Subject: [PATCH] Add feature toggle for API v1 use Dev, test and staging need to activate the feature toggle now before it's accessible. --- config/routes/api.rb | 10 ++++------ spec/requests/api/v1/customers_spec.rb | 5 ++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/config/routes/api.rb b/config/routes/api.rb index 9fa70e1d13..2a72d60155 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -87,13 +87,11 @@ Openfoodnetwork::Application.routes.draw do constraints: lambda { |_| Flipper.enabled?(:api_reports) } end - unless Rails.env.production? - namespace :v1 do - resources :customers + namespace :v1, constraints: ->(request) { Flipper.enabled?(:api_v1, request.env["warden"].user) } do + resources :customers - resources :enterprises do - resources :customers, only: :index - end + resources :enterprises do + resources :customers, only: :index end end diff --git a/spec/requests/api/v1/customers_spec.rb b/spec/requests/api/v1/customers_spec.rb index 002c1d5f39..d3a07b001e 100644 --- a/spec/requests/api/v1/customers_spec.rb +++ b/spec/requests/api/v1/customers_spec.rb @@ -17,7 +17,10 @@ describe "Customers", type: :request do let!(:customer2) { create(:customer, enterprise: enterprise1) } let!(:customer3) { create(:customer, enterprise: enterprise2) } - before { login_as enterprise1.owner } + before do + Flipper.enable(:api_v1) + login_as enterprise1.owner + end path "/api/v1/customers" do get "List customers" do