fix(flipper): don't clone features globally enabled

This commit is contained in:
Colin Darie 2024-03-02 16:38:00 +01:00
parent 3519e5eef1
commit dbf04c63a4
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
2 changed files with 20 additions and 7 deletions

View file

@ -561,9 +561,10 @@ class Procedure < ApplicationRecord
procedure.update!(defaut_groupe_instructeur: new_defaut_groupe)
Flipper.features.each do |feature|
if feature_enabled?(feature.key)
Flipper.enable(feature.key, procedure)
end
next if feature.enabled? # don't clone features globally enabled
next unless feature_enabled?(feature.key)
Flipper.enable(feature.key, procedure)
end
procedure

View file

@ -871,21 +871,33 @@ describe Procedure do
describe 'feature flag' do
context 'with a feature flag enabled' do
before do
Flipper.enable(:procedure_routage_api, procedure)
Flipper.enable(:dossier_pdf_vide, procedure)
end
it 'should enable feature' do
expect(subject.feature_enabled?(:procedure_routage_api)).to be true
expect(subject.feature_enabled?(:dossier_pdf_vide)).to be true
expect(Flipper.feature(:dossier_pdf_vide).enabled_gate_names).to include(:actor)
end
end
context 'with feature flag is fully enabled' do
before do
Flipper.enable(:dossier_pdf_vide)
end
it 'should not clone feature for actor' do
expect(subject.feature_enabled?(:dossier_pdf_vide)).to be true
expect(Flipper.feature(:dossier_pdf_vide).enabled_gate_names).not_to include(:actor)
end
end
context 'with a feature flag disabled' do
before do
Flipper.disable(:procedure_routage_api, procedure)
Flipper.disable(:dossier_pdf_vide, procedure)
end
it 'should not enable feature' do
expect(subject.feature_enabled?(:procedure_routage_api)).to be false
expect(subject.feature_enabled?(:dossier_pdf_vide)).to be false
end
end
end