Spec feed insert worker (#2965)
* Spec for feed insert worker when missing records * more specs! * Refactor feed insert worker
This commit is contained in:
parent
2fba4196ef
commit
cc9a6a710f
2 changed files with 79 additions and 6 deletions
|
@ -3,13 +3,34 @@
|
|||
class FeedInsertWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform(status_id, follower_id)
|
||||
status = Status.find(status_id)
|
||||
follower = Account.find(follower_id)
|
||||
attr_reader :status, :follower
|
||||
|
||||
return if FeedManager.instance.filter?(:home, status, follower.id)
|
||||
def perform(status_id, follower_id)
|
||||
@status = Status.find_by(id: status_id)
|
||||
@follower = Account.find_by(id: follower_id)
|
||||
|
||||
check_and_insert
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_and_insert
|
||||
if records_available?
|
||||
perform_push unless feed_filtered?
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def records_available?
|
||||
status.present? && follower.present?
|
||||
end
|
||||
|
||||
def feed_filtered?
|
||||
FeedManager.instance.filter?(:home, status, follower.id)
|
||||
end
|
||||
|
||||
def perform_push
|
||||
FeedManager.instance.push(:home, follower, status)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue