about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-10 14:32:05 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-10 20:32:05 +0200
commitcc9a6a710f6cf6d193589778570a13f89f7d18f4 (patch)
tree445c65ee448f43ccc2ea2d77c170b673e68c2f07 /spec
parent2fba4196efd594bcd8922ab479569ac614b9beea (diff)
Spec feed insert worker (#2965)
* Spec for feed insert worker when missing records

* more specs!

* Refactor feed insert worker
Diffstat (limited to 'spec')
-rw-r--r--spec/workers/feed_insert_worker_spec.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/workers/feed_insert_worker_spec.rb b/spec/workers/feed_insert_worker_spec.rb
new file mode 100644
index 000000000..71a3dea00
--- /dev/null
+++ b/spec/workers/feed_insert_worker_spec.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe FeedInsertWorker do
+  subject { described_class.new }
+
+  describe 'perform' do
+    let(:follower) { Fabricate(:account) }
+    let(:status) { Fabricate(:status) }
+
+    context 'when there are no records' do
+      it 'skips push with missing status' do
+        instance = double(push: nil)
+        allow(FeedManager).to receive(:instance).and_return(instance)
+        result = subject.perform(nil, follower.id)
+
+        expect(result).to eq true
+        expect(instance).not_to have_received(:push)
+      end
+
+      it 'skips push with missing account' do
+        instance = double(push: nil)
+        allow(FeedManager).to receive(:instance).and_return(instance)
+        result = subject.perform(status.id, nil)
+
+        expect(result).to eq true
+        expect(instance).not_to have_received(:push)
+      end
+    end
+
+    context 'when there are real records' do
+      it 'skips the push when there is a filter' do
+        instance = double(push: nil, filter?: true)
+        allow(FeedManager).to receive(:instance).and_return(instance)
+        result = subject.perform(status.id, follower.id)
+
+        expect(result).to be_nil
+        expect(instance).not_to have_received(:push)
+      end
+
+      it 'pushes the status onto the home timeline without filter' do
+        instance = double(push: nil, filter?: false)
+        allow(FeedManager).to receive(:instance).and_return(instance)
+        result = subject.perform(status.id, follower.id)
+
+        expect(result).to be_nil
+        expect(instance).to have_received(:push).with(:home, follower, status)
+      end
+    end
+  end
+end