From 7558df0aed821c0faeca1ba3adc02d90c323ffc8 Mon Sep 17 00:00:00 2001 From: Andrew Kuklewicz Date: Thu, 19 Sep 2024 17:57:23 -0400 Subject: [PATCH] Add job to republish public feed when adding Apple feed --- app/jobs/publish_public_feed_job.rb | 17 +++++++++++++++++ app/models/feeds/apple_subscription.rb | 6 +++--- test/jobs/publish_public_feed_job_test.rb | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 app/jobs/publish_public_feed_job.rb create mode 100644 test/jobs/publish_public_feed_job_test.rb diff --git a/app/jobs/publish_public_feed_job.rb b/app/jobs/publish_public_feed_job.rb new file mode 100644 index 000000000..0f74414a1 --- /dev/null +++ b/app/jobs/publish_public_feed_job.rb @@ -0,0 +1,17 @@ +require "builder" + +class PublishPublicFeedJob < ApplicationJob + queue_as :feeder_publishing + + include PodcastsHelper + + attr_writer :publish_feed_job + + def perform(podcast) + publish_feed_job.save_file(podcast, podcast.public_feed) + end + + def publish_feed_job + @publish_feed_job ||= PublishFeedJob.new + end +end diff --git a/app/models/feeds/apple_subscription.rb b/app/models/feeds/apple_subscription.rb index 681fc74a3..6473bbe02 100644 --- a/app/models/feeds/apple_subscription.rb +++ b/app/models/feeds/apple_subscription.rb @@ -6,7 +6,7 @@ class Feeds::AppleSubscription < Feed after_initialize :set_defaults - after_create :publish_feeds + after_create :republish_public_feed has_one :apple_config, class_name: "::Apple::Config", dependent: :destroy, autosave: true, validate: true, inverse_of: :feed @@ -33,8 +33,8 @@ def self.model_name Feed.model_name end - def publish_feeds - podcast&.publish! + def republish_public_feed + PublishPublicFeedJob.perform_later(podcast) end def unchanged_defaults diff --git a/test/jobs/publish_public_feed_job_test.rb b/test/jobs/publish_public_feed_job_test.rb new file mode 100644 index 000000000..132b20d65 --- /dev/null +++ b/test/jobs/publish_public_feed_job_test.rb @@ -0,0 +1,17 @@ +require "test_helper" + +describe PublishPublicFeedJob do + let(:podcast) { create(:podcast) } + + let(:job) { PublishPublicFeedJob.new } + + describe "saving the public rss file" do + let(:stub_client) { Aws::S3::Client.new(stub_responses: true) } + + it "can call save_file on PublishFeedJob" do + job.publish_feed_job.stub(:s3_client, stub_client) do + refute_nil job.perform(podcast) + end + end + end +end