diff options
author | Rémy Coutable <remy@rymai.me> | 2018-05-31 19:12:48 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-06-01 18:51:40 +0300 |
commit | e1ffd6a271e352a725aa0394b654e9250f2d8240 (patch) | |
tree | b4cb954e6042950cd63ce9a51c6832c59f90558b /spec/lib | |
parent | c5f89e5bd7f9371882de8b6ad62d24467b22937b (diff) |
Use RequestStore to memoize Flipper features so that memoized values are cleared between requests
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/feature_spec.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/lib/feature_spec.rb b/spec/lib/feature_spec.rb index 10020511bf8..6eb10497428 100644 --- a/spec/lib/feature_spec.rb +++ b/spec/lib/feature_spec.rb @@ -64,4 +64,28 @@ describe Feature do expect(described_class.all).to eq(features.to_a) end end + + describe '.flipper' do + shared_examples 'a memoized Flipper instance' do + it 'memoizes the Flipper instance' do + expect(Flipper).to receive(:new).once.and_call_original + + 2.times do + described_class.flipper + end + end + end + + context 'when request store is inactive' do + before do + described_class.instance_variable_set(:@flipper, nil) + 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 |