Commit 815b5120 authored by Shinya Maeda's avatar Shinya Maeda

Fix unleash server side cannot return feature flags

Add changelog

Improve coding style
parent 5c1e5f18
---
title: Fix unleash server side cannot return feature flags
merge_request: 9532
author:
type: fixed
......@@ -70,7 +70,7 @@ module API
end
def feature_flags
if Feature.enabled?(:feature_flags_environment_scope, project: project)
if Feature.enabled?(:feature_flags_environment_scope, project)
return [] unless unleash_app_name.present?
project.operations_feature_flags.for_environment(unleash_app_name)
......
......@@ -82,7 +82,6 @@ describe API::Unleash do
end
before do
stub_feature_flags(feature_flags_environment_scope: true)
create_scope(feature_flag_1, 'production', false)
create_scope(feature_flag_2, 'review/*', true)
end
......@@ -93,6 +92,24 @@ describe API::Unleash do
expect(recorded.count).to be_within(8).of(10)
end
it 'calls for_environment method' do
expect(Operations::FeatureFlag).to receive(:for_environment)
subject
end
context 'when the feature is disabled on the project' do
before do
stub_feature_flags(feature_flags_environment_scope: { enabled: false, thing: project })
end
it 'does not call for_environment method' do
expect(Operations::FeatureFlag).not_to receive(:for_environment)
subject
end
end
context 'when app name is staging' do
let(:headers) { base_headers.merge({ "UNLEASH-APPNAME" => "staging" }) }
......
module StubFeatureFlags
# Stub Feature flags with `flag_name: true/false`
#
# @param [Hash] features where key is feature name and value is boolean whether enabled or not
# @param [Hash] features where key is feature name and value is boolean whether enabled or not.
# Alternatively, you can specify Hash to enable the flag on a specific thing.
#
# Examples
# - `stub_feature_flags(ci_live_trace: false)` ... Disable `ci_live_trace`
# feature flag globally.
# - `stub_feature_flags(ci_live_trace: { enabled: false, thing: project })` ...
# Disable `ci_live_trace` feature flag on the specified project.
def stub_feature_flags(features)
features.each do |feature_name, enabled|
allow(Feature).to receive(:enabled?).with(feature_name, any_args) { enabled }
allow(Feature).to receive(:enabled?).with(feature_name.to_s, any_args) { enabled }
features.each do |feature_name, option|
if option.is_a?(Hash)
enabled, thing = option.values_at(:enabled, :thing)
else
enabled = option
thing = nil
end
if thing
allow(Feature).to receive(:enabled?).with(feature_name, thing, any_args) { enabled }
allow(Feature).to receive(:enabled?).with(feature_name.to_s, thing, any_args) { enabled }
else
allow(Feature).to receive(:enabled?).with(feature_name, any_args) { enabled }
allow(Feature).to receive(:enabled?).with(feature_name.to_s, any_args) { enabled }
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment