Add FeatureFlag.all (#16496)

This commit is contained in:
Michael Kohl 2022-02-11 13:38:17 +07:00 committed by GitHub
parent 12b9aa4fc8
commit a91e505051
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View file

@ -44,5 +44,13 @@ module FeatureFlag
enabled?(feature_flag_name, *args)
end
# Retrieve a list of all currently defined flags and their status. This is
# primarily intended for development and wraps +Flipper.features+.
#
# @return [Hash<Symbol, Symbol>] the defined flags with their status (+:on+ or +:off+).
def all
Flipper.features.to_h { |feature| [feature.name.to_sym, feature.state] }
end
end
end

View file

@ -99,4 +99,14 @@ describe FeatureFlag, type: :service do
end
end
end
describe ".all", :aggregate_failures do
it "returns a hash with all feature flags and their status" do
described_class.enable(:flag1)
expect(described_class.all).to eq({ flag1: :on })
described_class.disable(:flag2)
expect(described_class.all).to eq({ flag1: :on, flag2: :off })
end
end
end