about summary refs log tree commit diff
path: root/spec/lib
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-11-04 13:21:06 +0100
committerGitHub <noreply@github.com>2022-11-04 13:21:06 +0100
commit5f9e47be34fcf42ff7fcd5668c7555d4a38e289a (patch)
tree5f0f22a0297e1235b8189d4cbd1a8568089e6f2d /spec/lib
parentb8f6f039563044764336d4c62d87b1d5442d7c8b (diff)
Add caching for payload serialization during fan-out (#19642)
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/status_cache_hydrator_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/lib/status_cache_hydrator_spec.rb b/spec/lib/status_cache_hydrator_spec.rb
new file mode 100644
index 000000000..ad9940a85
--- /dev/null
+++ b/spec/lib/status_cache_hydrator_spec.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe StatusCacheHydrator do
+  let(:status)  { Fabricate(:status) }
+  let(:account) { Fabricate(:account) }
+
+  describe '#hydrate' do
+    subject { described_class.new(status).hydrate(account.id) }
+
+    let(:compare_to_hash) { InlineRenderer.render(status, account, :status) }
+
+    context 'when cache is warm' do
+      before do
+        Rails.cache.write("fan-out/#{status.id}", InlineRenderer.render(status, nil, :status))
+      end
+
+      it 'renders the same attributes as a full render' do
+        expect(subject).to include(compare_to_hash)
+      end
+    end
+
+    context 'when cache is cold' do
+      before do
+        Rails.cache.delete("fan-out/#{status.id}")
+      end
+
+      it 'renders the same attributes as a full render' do
+        expect(subject).to include(compare_to_hash)
+      end
+    end
+
+    context 'when account has favourited status' do
+      before do
+        FavouriteService.new.call(account, status)
+      end
+
+      it 'renders the same attributes as a full render' do
+        expect(subject).to include(compare_to_hash)
+      end
+    end
+
+    context 'when account has reblogged status' do
+      before do
+        ReblogService.new.call(account, status)
+      end
+
+      it 'renders the same attributes as a full render' do
+        expect(subject).to include(compare_to_hash)
+      end
+    end
+  end
+end