docbrown/spec/requests/api/v0/feature_flags_spec.rb
Mac Siri 842e6880b8
Routine rubocop fix on /spec (#19217)
* Softrun rubocop

* Hardrun rubocop (-A)

* Change a rubocop rule

* Add missing cops

* Undo & redo rubocop -A
2023-03-21 09:55:26 -04:00

64 lines
1.8 KiB
Ruby

require "rails_helper"
RSpec.describe "Api::V0::FeatureFlagsController" do
let(:flag) { "test_flag" }
let(:params) { { flag: flag } }
it "is not available in the production environment" do
# We really need an ActiveSupport::StringInquirer here
# rubocop:disable Rails/Inquiry
allow(Rails).to receive(:env).and_return("production".inquiry)
# rubocop:enable Rails/Inquiry
expect do
post api_feature_flags_path, params: params
end.to raise_error(ActionController::RoutingError)
end
context "when toggling feature flags" do
before { FeatureFlag.add(flag) }
after { FeatureFlag.remove(flag) }
it "can enable a disabled feature flag" do
FeatureFlag.disable(flag)
expect do
post api_feature_flags_path, params: params
end.to change { FeatureFlag.enabled?(flag) }.from(false).to(true)
end
it "keeps the flag enabled when it was already enabled" do
FeatureFlag.enable(flag)
expect do
post api_feature_flags_path, params: params
end.not_to change { FeatureFlag.enabled?(flag) }.from(true)
end
it "can disable an enabled feature flag" do
FeatureFlag.enable(flag)
expect do
delete api_feature_flags_path, params: params
end.to change { FeatureFlag.enabled?(flag) }.from(true).to(false)
end
it "keeps the flag disabled when it was already disabled" do
FeatureFlag.disable(flag)
expect do
delete api_feature_flags_path, params: params
end.not_to change { FeatureFlag.enabled?(flag) }.from(false)
end
it "shows the current value of a feature flag" do
FeatureFlag.enable(flag)
get api_feature_flags_path(flag: flag)
parsed_response = response.parsed_body
expect(parsed_response[flag]).to be true
end
end
end