diff --git a/app/workers/feeds/import_articles_worker.rb b/app/workers/feeds/import_articles_worker.rb index 0a9dfce22..f027043a7 100644 --- a/app/workers/feeds/import_articles_worker.rb +++ b/app/workers/feeds/import_articles_worker.rb @@ -16,6 +16,7 @@ module Feeds # the last time a feed was fetched at earlier_than = nil else + users_scope = users_scope.where(id: Users::Setting.with_feed.select(:user_id)) earlier_than ||= 4.hours.ago end diff --git a/spec/workers/feeds/import_articles_worker_spec.rb b/spec/workers/feeds/import_articles_worker_spec.rb index 343b95653..1a8d72b80 100644 --- a/spec/workers/feeds/import_articles_worker_spec.rb +++ b/spec/workers/feeds/import_articles_worker_spec.rb @@ -2,46 +2,43 @@ require "rails_helper" RSpec.describe Feeds::ImportArticlesWorker, type: :worker, sidekiq: :inline do let(:worker) { subject } + let(:feed_url) { "https://medium.com/feed/@vaidehijoshi" } include_examples "#enqueues_on_correct_queue", "medium_priority" describe "#perform" do - it "calls the Feeds::Import defaulting to 4 hours ago" do + it "processes jobs for users with feeds" do allow(Feeds::Import).to receive(:call) alice = create(:user) bob = create(:user) + bob.setting.update_columns(feed_url: feed_url) + + # bob has a feed, and alice doesn't, so we only enqueued for bob Timecop.freeze(Time.current) do worker.perform - # Each user is run separately. Note that this will not be run - # sequentially like this in production. This only works like this due - # to the `sidekiq: :inline` tag on the `RSpec.describe` block - expect(Feeds::Import) - .to have_received(:call) - .with(users_scope: User.where(id: [alice.id]), earlier_than: 4.hours.ago.iso8601) expect(Feeds::Import) .to have_received(:call) .with(users_scope: User.where(id: [bob.id]), earlier_than: 4.hours.ago.iso8601) + expect(Feeds::Import) + .not_to have_received(:call) + .with(users_scope: User.where(id: [alice.id]), earlier_than: 4.hours.ago.iso8601) end end - it "calls the Feeds::Import with the given time" do + it "enqueues job for user with the given time" do allow(Feeds::Import).to receive(:call) - alice = create(:user) - bob = create(:user) + user = create(:user) + user.setting.update_columns(feed_url: feed_url) - Timecop.freeze(Time.current) do - worker.perform([], 1.minute.ago) + earlier_than = 1.minute.ago + worker.perform([], earlier_than) - # Each user is run separately - expect(Feeds::Import) - .to have_received(:call) - .with(users_scope: User.where(id: [alice.id]), earlier_than: 1.minute.ago.iso8601) - expect(Feeds::Import) - .to have_received(:call) - .with(users_scope: User.where(id: [bob.id]), earlier_than: 1.minute.ago.iso8601) - end + expect(Feeds::Import).to have_received(:call).with( + users_scope: User.where(id: user.id), + earlier_than: earlier_than.iso8601, + ) end it "calls Feeds::Import with the users from the given user ids and no time" do