diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-08-18 14:52:11 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-08-21 17:58:37 +0200 |
commit | e0b589f16166a88d18e58fbc154e0cf165732acb (patch) | |
tree | 4e329dd6f9ebe75a13d5a2985962042b9390b514 /spec/models/broadcast_message_spec.rb | |
parent | 646aae3e4f0f9c547397fdf55cc2205b0171b565 (diff) | |
download | gitlab-ce-e0b589f16166a88d18e58fbc154e0cf165732acb.tar.gz |
Fix caching of future broadcast messagesfix-broadcast-message-caching
This changes the caching mechanism so we cache both current _and_ future
broadcast messages, then manually filter out those we don't want to
display. This ensures we don't need any additional queries while still
being able to display the right messages at the right time.
Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/36661
Diffstat (limited to 'spec/models/broadcast_message_spec.rb')
-rw-r--r-- | spec/models/broadcast_message_spec.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb index 3369aef1d3e..461e754dc1f 100644 --- a/spec/models/broadcast_message_spec.rb +++ b/spec/models/broadcast_message_spec.rb @@ -53,6 +53,29 @@ describe BroadcastMessage do 2.times { described_class.current } end + + it 'includes messages that need to be displayed in the future' do + create(:broadcast_message) + + future = create( + :broadcast_message, + starts_at: Time.now + 10.minutes, + ends_at: Time.now + 20.minutes + ) + + expect(described_class.current.length).to eq(1) + + Timecop.travel(future.starts_at) do + expect(described_class.current.length).to eq(2) + end + end + + 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(described_class.current.length).to eq(0) + end end describe '#active?' do |