diff options
author | Robert Speicher <rspeicher@gmail.com> | 2018-12-10 21:47:43 +0000 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2018-12-10 21:47:43 +0000 |
commit | ec76f4fd905c04706447dffee4f8061a2b8d4e1e (patch) | |
tree | 23abbeb02c46615370b2c309be32e48ac469a620 /spec | |
parent | bea8e0626ddd18ad9a2059c65e9005632fb48921 (diff) | |
parent | cde78f7f4eaec2740c6e91c7d225d701d0097ec0 (diff) | |
download | gitlab-ce-ec76f4fd905c04706447dffee4f8061a2b8d4e1e.tar.gz |
Merge branch 'sh-json-serialize-broadcast-messages' into 'master'
Avoid caching BroadcastMessage as an ActiveRecord object
Closes #55034
See merge request gitlab-org/gitlab-ce!23662
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/broadcast_message_spec.rb | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb index 5326f9cb8c0..d6e5b557870 100644 --- a/spec/models/broadcast_message_spec.rb +++ b/spec/models/broadcast_message_spec.rb @@ -58,6 +58,12 @@ describe BroadcastMessage do end end + it 'does not create new records' do + create(:broadcast_message) + + expect { described_class.current }.not_to change { described_class.count } + end + it 'includes messages that need to be displayed in the future' do create(:broadcast_message) @@ -77,9 +83,37 @@ describe BroadcastMessage do it 'does not clear the cache if only a future message should be displayed' do create(:broadcast_message, :future) - expect(Rails.cache).not_to receive(:delete) + expect(Rails.cache).not_to receive(:delete).with(described_class::CACHE_KEY) expect(described_class.current.length).to eq(0) end + + it 'clears the legacy cache key' do + create(:broadcast_message, :future) + + expect(Rails.cache).to receive(:delete).with(described_class::LEGACY_CACHE_KEY) + expect(described_class.current.length).to eq(0) + end + + it 'gracefully handles bad cache entry' do + allow(described_class).to receive(:current_and_future_messages).and_return('{') + + expect(described_class.current).to be_empty + end + + it 'gracefully handles an empty hash' do + allow(described_class).to receive(:current_and_future_messages).and_return('{}') + + expect(described_class.current).to be_empty + end + + it 'gracefully handles unknown attributes' do + message = create(:broadcast_message) + + allow(described_class).to receive(:current_and_future_messages) + .and_return([{ bad_attr: 1 }, message]) + + expect(described_class.current).to eq([message]) + end end describe '#active?' do @@ -143,6 +177,7 @@ describe BroadcastMessage do message = create(:broadcast_message) expect(Rails.cache).to receive(:delete).with(described_class::CACHE_KEY) + expect(Rails.cache).to receive(:delete).with(described_class::LEGACY_CACHE_KEY) message.flush_redis_cache end |