Refactor Feature.flipper method
* Fix typo in context 'when request store is active' * Rearrange test since the instance variable always gets set now, even if RequestStore is active
This commit is contained in:
parent
a54a5d9f39
commit
74ae135888
|
@ -72,11 +72,7 @@ class Feature
|
||||||
end
|
end
|
||||||
|
|
||||||
def flipper
|
def flipper
|
||||||
if Gitlab::SafeRequestStore.active?
|
@flipper ||= (Gitlab::SafeRequestStore[:flipper] ||= build_flipper_instance)
|
||||||
Gitlab::SafeRequestStore[:flipper] ||= build_flipper_instance
|
|
||||||
else
|
|
||||||
@flipper ||= build_flipper_instance
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_flipper_instance
|
def build_flipper_instance
|
||||||
|
|
|
@ -91,7 +91,11 @@ describe Feature do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.flipper' do
|
describe '.flipper' do
|
||||||
shared_examples 'a memoized Flipper instance' do
|
before do
|
||||||
|
described_class.instance_variable_set(:@flipper, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when request store is inactive' do
|
||||||
it 'memoizes the Flipper instance' do
|
it 'memoizes the Flipper instance' do
|
||||||
expect(Flipper).to receive(:new).once.and_call_original
|
expect(Flipper).to receive(:new).once.and_call_original
|
||||||
|
|
||||||
|
@ -101,16 +105,14 @@ describe Feature do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when request store is inactive' do
|
context 'when request store is active', :request_store do
|
||||||
before do
|
it 'memoizes the Flipper instance' do
|
||||||
|
expect(Flipper).to receive(:new).once.and_call_original
|
||||||
|
|
||||||
|
described_class.flipper
|
||||||
described_class.instance_variable_set(:@flipper, nil)
|
described_class.instance_variable_set(:@flipper, nil)
|
||||||
|
described_class.flipper
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'a memoized Flipper instance'
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when request store is inactive', :request_store do
|
|
||||||
it_behaves_like 'a memoized Flipper instance'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue