]> cat aescling's git repositories - mastodon.git/commitdiff
Add spec coverage for regeneration worker (#3143)
authorMatt Jankowski <mjankowski@thoughtbot.com>
Fri, 19 May 2017 14:55:09 +0000 (10:55 -0400)
committerEugen Rochko <eugen@zeonfederated.com>
Fri, 19 May 2017 14:55:09 +0000 (16:55 +0200)
app/workers/regeneration_worker.rb
spec/workers/regeneration_worker_spec.rb [new file with mode: 0644]

index 0cc6b668c4f5023de8b7361f6598188c3ceabd55..8cee21ae1fbe52bb3b73a31ecb083f7d6408efea 100644 (file)
@@ -7,7 +7,8 @@ class RegenerationWorker
 
   def perform(account_id, _ = :home)
     account = Account.find(account_id)
-
     PrecomputeFeedService.new.call(account)
+  rescue ActiveRecord::RecordNotFound
+    true
   end
 end
diff --git a/spec/workers/regeneration_worker_spec.rb b/spec/workers/regeneration_worker_spec.rb
new file mode 100644 (file)
index 0000000..c6bdfa0
--- /dev/null
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe RegenerationWorker do
+  subject { described_class.new }
+
+  describe 'perform' do
+    let(:account) { Fabricate(:account) }
+
+    it 'calls the precompute feed service for the account' do
+      service = double(call: nil)
+      allow(PrecomputeFeedService).to receive(:new).and_return(service)
+      result = subject.perform(account.id)
+
+      expect(result).to be_nil
+      expect(service).to have_received(:call).with(account)
+    end
+
+    it 'fails when account does not exist' do
+      result = subject.perform('aaa')
+
+      expect(result).to eq(true)
+    end
+  end
+end