Skip to content
代码片段 群组 项目
提交 332dc0aa 编辑于 作者: Vijay Hawoldar's avatar Vijay Hawoldar
浏览文件

Adjusts stub_saas_features to stub defaults

So that we can test flows that result in multiple calls to
Gitlab::Saas.feature_available?, we now stub the default value for all
known SaaS features to false
上级 ccb15d3f
No related branches found
No related tags found
无相关合并请求
...@@ -11,7 +11,10 @@ module StubSaasFeatures ...@@ -11,7 +11,10 @@ module StubSaasFeatures
# - `stub_saas_features(onboarding: true)` ... Enable `onboarding` # - `stub_saas_features(onboarding: true)` ... Enable `onboarding`
# SaaS feature globally. # SaaS feature globally.
def stub_saas_features(features) def stub_saas_features(features)
features.each do |feature_name, value| all_features = ::Gitlab::Saas::FEATURES.index_with { false }
all_features.merge!(features)
all_features.each do |feature_name, value|
raise ArgumentError, 'value must be boolean' unless value.in? [true, false] raise ArgumentError, 'value must be boolean' unless value.in? [true, false]
allow(::Gitlab::Saas).to receive(:feature_available?).with(feature_name).and_return(value) allow(::Gitlab::Saas).to receive(:feature_available?).with(feature_name).and_return(value)
......
...@@ -6,7 +6,12 @@ ...@@ -6,7 +6,12 @@
describe '#stub_saas_features' do describe '#stub_saas_features' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
let(:feature_name) { :some_saas_feature } let(:feature_name) { :feature_one }
let(:all_features) { [feature_name, :feature_two, :feature_three] }
before do
stub_const("Gitlab::Saas::FEATURES", all_features)
end
context 'when checking global state' do context 'when checking global state' do
where(:feature_value) do where(:feature_value) do
...@@ -46,5 +51,15 @@ ...@@ -46,5 +51,15 @@
expect(::Gitlab::Saas.feature_available?(feature_name)).to eq(false) expect(::Gitlab::Saas.feature_available?(feature_name)).to eq(false)
expect(::Gitlab::Saas.feature_available?(:some_new_feature)).to eq(true) expect(::Gitlab::Saas.feature_available?(:some_new_feature)).to eq(true)
end end
context 'when checking multiple features' do
it 'stubs defaults false value for other known features' do
stub_saas_features(feature_one: true)
expect(::Gitlab::Saas.feature_available?(:feature_one)).to eq(true)
expect(::Gitlab::Saas.feature_available?(:feature_two)).to eq(false)
expect(::Gitlab::Saas.feature_available?(:feature_three)).to eq(false)
end
end
end end
end end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册