diff --git a/app/jobs/publish_feed_job.rb b/app/jobs/publish_feed_job.rb index 7ecf4cce3..06934f705 100644 --- a/app/jobs/publish_feed_job.rb +++ b/app/jobs/publish_feed_job.rb @@ -15,7 +15,8 @@ def perform(podcast, pub_item) Rails.logger.info("Starting publishing pipeline via PublishFeedJob", {podcast_id: podcast.id, publishing_queue_item_id: pub_item.id}) PublishingPipelineState.start!(podcast) - podcast.feeds.each { |feed| publish_feed(podcast, feed) } + podcast.feeds.each { |feed| publish_apple(podcast, feed) } + podcast.feeds.each { |feed| publish_rss(podcast, feed) } PublishingPipelineState.complete!(podcast) rescue => e PublishingPipelineState.error!(podcast) @@ -25,19 +26,14 @@ def perform(podcast, pub_item) PublishingPipelineState.settle_remaining!(podcast) end - def publish_feed(podcast, feed) - publish_apple(feed) - publish_rss(podcast, feed) - end - - def publish_apple(feed) + def publish_apple(podcast, feed) return unless feed.publish_to_apple? res = PublishAppleJob.perform_now(feed.apple_config) - PublishingPipelineState.publish_apple!(feed.podcast) + PublishingPipelineState.publish_apple!(podcast) res rescue => e NewRelic::Agent.notice_error(e) - res = PublishingPipelineState.error_apple!(feed.podcast) + res = PublishingPipelineState.error_apple!(podcast) raise e if feed.apple_config.sync_blocks_rss? res end diff --git a/app/models/apple/config.rb b/app/models/apple/config.rb index b8acf9969..d37affa66 100644 --- a/app/models/apple/config.rb +++ b/app/models/apple/config.rb @@ -6,32 +6,23 @@ class Config < ApplicationRecord DEFAULT_TITLE = "Apple Delegated Delivery Subscriptions" DEFAULT_AUDIO_FORMAT = {"f" => "flac", "b" => 16, "c" => 2, "s" => 44100}.freeze - belongs_to :podcast, class_name: "Podcast" - belongs_to :public_feed, class_name: "Feed" - belongs_to :private_feed, class_name: "Feed" - belongs_to :key, class_name: "Apple::Key", optional: true + belongs_to :feed + belongs_to :key, class_name: "Apple::Key", optional: true, validate: true, autosave: true - delegate :title, to: :podcast, prefix: "podcast" + validate :podcast_has_one_apple_config + validate :not_default_feed + # backwards-compatible "key" getters delegate :provider_id, to: :key delegate :key_id, to: :key delegate :key_pem, to: :key delegate :key_pem_b64, to: :key - validates_presence_of :podcast - validates_presence_of :public_feed - validates_presence_of :private_feed - - validates_associated :public_feed - validates_associated :private_feed - - validates :podcast, uniqueness: true, allow_nil: false - - validates :public_feed, uniqueness: {scope: :private_feed, - message: "can only have one config per public and private feed"} - validates :public_feed, exclusion: {in: ->(apple_credential) { [apple_credential.private_feed] }} - - validate :feed_podcasts_match + # backwards-compatible associations + delegate :podcast, to: :feed, allow_nil: true + delegate :id, :title, to: :podcast, prefix: true, allow_nil: true + delegate :public_feed, to: :podcast, allow_nil: true + alias_method :private_feed, :feed def self.find_or_build_private_feed(podcast) if (existing = podcast.feeds.find_by(slug: DEFAULT_FEED_SLUG, title: DEFAULT_TITLE)) @@ -64,12 +55,7 @@ def self.build_apple_config(podcast, key) raise "Stopping build_apple_config" if $stdin.gets.chomp.downcase != "y" end - Apple::Config.new( - podcast: podcast, - public_feed: podcast.default_feed, - private_feed: find_or_build_private_feed(podcast), - key: key - ) + Apple::Config.new(feed: find_or_build_private_feed(podcast), key: key) end def self.mark_as_delivered!(apple_publisher) @@ -99,18 +85,21 @@ def self.setup_delegated_delivery(podcast, key: nil, apple_config: nil, apple_sh mark_as_delivered!(pub) end - def feed_podcasts_match - return unless public_feed.present? && private_feed.present? + def not_default_feed + if feed&.default? + errors.add(:feed, "cannot use default feed") + end + end - if (public_feed.podcast_id != podcast_id) || (private_feed.podcast_id != podcast_id) - errors.add(:public_feed, "must belong to the same podcast as the private feed") + def podcast_has_one_apple_config + all_feeds = Feed.where(podcast_id: feed.podcast_id).pluck(:id) + if Apple::Config.where(feed_id: all_feeds).where.not(id: id).any? + errors.add(:feed, "podcast already has an apple config") end end def publish_to_apple? - return false unless key&.valid? - - public_feed.publish_to_apple? + !!key&.valid? && publish_enabled? end def build_publisher diff --git a/app/models/feed.rb b/app/models/feed.rb index 7e6742d8c..1b0ccdd4d 100644 --- a/app/models/feed.rb +++ b/app/models/feed.rb @@ -25,13 +25,7 @@ class Feed < ApplicationRecord alias_attribute :tokens, :feed_tokens accepts_nested_attributes_for :feed_tokens, allow_destroy: true, reject_if: ->(ft) { ft[:token].blank? } - has_one :apple_config, - autosave: true, - class_name: "::Apple::Config", - dependent: :destroy, - foreign_key: :public_feed_id, - inverse_of: :public_feed, - validate: true + has_one :apple_config, class_name: "::Apple::Config", dependent: :destroy, autosave: true, validate: true has_many :feed_images, -> { order("created_at DESC") }, autosave: true, dependent: :destroy, inverse_of: :feed has_many :itunes_images, -> { order("created_at DESC") }, autosave: true, dependent: :destroy, inverse_of: :feed @@ -173,9 +167,7 @@ def normalize_category(cat) end def publish_to_apple? - apple_config.present? && - apple_config.public_feed == self && - apple_config.publish_enabled? + !!apple_config&.publish_to_apple? end def include_tags=(tags) diff --git a/app/models/podcast.rb b/app/models/podcast.rb index 9812c7b2c..0794b96ca 100644 --- a/app/models/podcast.rb +++ b/app/models/podcast.rb @@ -20,7 +20,7 @@ class Podcast < ApplicationRecord serialize :restrictions, JSON has_one :default_feed, -> { default }, class_name: "Feed", validate: true, autosave: true, inverse_of: :podcast - has_one :apple_config, class_name: "::Apple::Config", validate: true, autosave: true, inverse_of: :podcast + alias_method :public_feed, :default_feed has_many :episodes, -> { order("published_at desc") }, dependent: :destroy has_many :feeds, dependent: :destroy @@ -67,6 +67,19 @@ def default_feed super || build_default_feed(podcast: self, private: false) end + def apple_config + if defined?(@apple_config) + @apple_config + else + @apple_config = Apple::Config.where(feed_id: feeds.pluck(:id)).first + end + end + + def reload(options = nil) + remove_instance_variable(:@apple_config) if defined?(@apple_config) + super + end + def explicit=(value) super Podcast::EXPLICIT_ALIASES.fetch(value, value) end diff --git a/db/migrate/20240410212602_simplify_apple_config_foreign_keys.rb b/db/migrate/20240410212602_simplify_apple_config_foreign_keys.rb new file mode 100644 index 000000000..fe375016f --- /dev/null +++ b/db/migrate/20240410212602_simplify_apple_config_foreign_keys.rb @@ -0,0 +1,32 @@ +class SimplifyAppleConfigForeignKeys < ActiveRecord::Migration[7.0] + def up + Apple::Config.find_each do |ac| + unless ac[:public_feed_id] == Podcast.find(ac[:podcast_id]).default_feed.id + raise "Apple::Config[#{ac.id} is not using the podcast.default_feed" + end + end + + remove_column :apple_configs, :podcast_id + remove_column :apple_configs, :public_feed_id + rename_column :apple_configs, :private_feed_id, :feed_id + end + + def down + add_column :apple_configs, :podcast_id, :integer + add_index :apple_configs, [:podcast_id], unique: true + + add_reference :apple_configs, :public_feed, index: true + add_foreign_key :apple_configs, :feeds, column: :public_feed_id + + rename_column :apple_configs, :feed_id, :private_feed_id + + Apple::Config.find_each do |ac| + f = Feed.find(ac.private_feed_id) + ac.podcast_id = f.podcast.id + ac.public_feed_id = f.podcast.default_feed.id + ac.save!(validate: false) + end + + change_column_null :apple_configs, :public_feed_id, false + end +end diff --git a/db/schema.rb b/db/schema.rb index 14b666e6b..726ac6665 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,24 +10,20 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_02_06_213452) do +ActiveRecord::Schema[7.0].define(version: 2024_04_10_212602) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "uuid-ossp" create_table "apple_configs", force: :cascade do |t| - t.bigint "public_feed_id", null: false - t.bigint "private_feed_id", null: false + t.bigint "feed_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "publish_enabled", default: false, null: false t.boolean "sync_blocks_rss", default: false, null: false t.bigint "key_id" - t.integer "podcast_id" + t.index ["feed_id"], name: "index_apple_configs_on_feed_id" t.index ["key_id"], name: "index_apple_configs_on_key_id" - t.index ["podcast_id"], name: "index_apple_configs_on_podcast_id", unique: true - t.index ["private_feed_id"], name: "index_apple_configs_on_private_feed_id" - t.index ["public_feed_id"], name: "index_apple_configs_on_public_feed_id" end create_table "apple_episode_delivery_statuses", force: :cascade do |t| @@ -451,8 +447,7 @@ t.index ["status"], name: "index_tasks_on_status" end - add_foreign_key "apple_configs", "feeds", column: "private_feed_id" - add_foreign_key "apple_configs", "feeds", column: "public_feed_id" + add_foreign_key "apple_configs", "feeds" add_foreign_key "apple_episode_delivery_statuses", "episodes" add_foreign_key "episode_imports", "podcast_imports" add_foreign_key "feed_images", "feeds" diff --git a/test/factories/apple_config_factory.rb b/test/factories/apple_config_factory.rb index 34bc6186e..cd6f17f4e 100644 --- a/test/factories/apple_config_factory.rb +++ b/test/factories/apple_config_factory.rb @@ -3,12 +3,6 @@ publish_enabled { true } sync_blocks_rss { true } key { build(:apple_key) } - podcast - - # set up the private and public feeds - before(:create) do |apple_config, evaluator| - apple_config.public_feed ||= create(:feed, podcast: evaluator.podcast) - apple_config.private_feed ||= create(:feed, podcast: evaluator.podcast) - end + feed end end diff --git a/test/jobs/publish_apple_job_test.rb b/test/jobs/publish_apple_job_test.rb index 80f39f6d0..8fd396277 100644 --- a/test/jobs/publish_apple_job_test.rb +++ b/test/jobs/publish_apple_job_test.rb @@ -3,9 +3,9 @@ describe PublishAppleJob do let(:episode) { create(:episode, prx_uri: "/api/v1/stories/87683") } let(:podcast) { episode.podcast } - let(:feed) { create(:feed, podcast: podcast, slug: "adfree") } + let(:feed) { podcast.default_feed } let(:private_feed) { create(:private_feed, podcast: podcast) } - let(:apple_config) { create(:apple_config, podcast: podcast, public_feed: feed, private_feed: private_feed) } + let(:apple_config) { create(:apple_config, feed: private_feed) } describe "publishing to apple" do it "does not publish to apple unless publish_enabled?" do diff --git a/test/jobs/publish_feed_job_test.rb b/test/jobs/publish_feed_job_test.rb index 7f228565d..a49885157 100644 --- a/test/jobs/publish_feed_job_test.rb +++ b/test/jobs/publish_feed_job_test.rb @@ -82,28 +82,28 @@ describe "publishing to apple" do it "does not schedule publishing to apple if there is no apple config" do - assert_nil feed.apple_config - assert_nil job.publish_apple(feed) + assert_nil private_feed.apple_config + assert_nil job.publish_apple(podcast, private_feed) end describe "when the apple config is present" do - let(:apple_config) { create(:apple_config, podcast: podcast, public_feed: feed, private_feed: private_feed) } + let(:apple_config) { create(:apple_config, feed: private_feed) } it "does not schedule publishing to apple if the config is marked as not publishable" do apple_config.update!(publish_enabled: false) - assert_equal apple_config, feed.apple_config.reload - assert_nil job.publish_apple(feed) + assert_equal apple_config, private_feed.apple_config.reload + assert_nil job.publish_apple(podcast, private_feed) end it "does run the apple publishing if the config is present and marked as publishable" do - assert_equal apple_config, feed.apple_config.reload + assert_equal apple_config, private_feed.apple_config.reload PublishAppleJob.stub(:perform_now, :publishing_apple!) do - assert_equal :publishing_apple!, job.publish_apple(feed) + assert_equal :publishing_apple!, job.publish_apple(podcast, private_feed) end end it "Performs the apple publishing job based regardless of sync_blocks_rss flag" do - assert_equal apple_config, feed.apple_config.reload + assert_equal apple_config, private_feed.apple_config.reload # stub the two possible ways the job can be called # perform_later is not used. @@ -111,11 +111,11 @@ PublishAppleJob.stub(:perform_now, :perform_now) do apple_config.update!(sync_blocks_rss: true) - assert_equal :perform_now, job.publish_apple(feed) + assert_equal :perform_now, job.publish_apple(podcast, private_feed) apple_config.update!(sync_blocks_rss: false) feed.reload - assert_equal :perform_now, job.publish_apple(feed) + assert_equal :perform_now, job.publish_apple(podcast, private_feed) end end end @@ -128,26 +128,26 @@ PublishingPipelineState.start!(feed.podcast) end it "raises an error if the apple publishing fails" do - assert_equal apple_config, feed.apple_config.reload + assert_equal apple_config, private_feed.apple_config.reload PublishAppleJob.stub(:perform_now, ->(*, **) { raise "some apple error" }) do # it raises - assert_raises(RuntimeError) { job.publish_apple(feed) } + assert_raises(RuntimeError) { job.publish_apple(podcast, private_feed) } assert_equal ["created", "started", "error_apple"].sort, PublishingPipelineState.where(podcast: feed.podcast).latest_pipelines.pluck(:status).sort end end it "does not raise an error if the apple publishing is not blocking RSS" do - assert_equal apple_config, feed.apple_config.reload - feed.apple_config.update!(sync_blocks_rss: false) + assert_equal apple_config, private_feed.apple_config.reload + private_feed.apple_config.update!(sync_blocks_rss: false) mock = Minitest::Mock.new mock.expect(:call, nil, [RuntimeError]) PublishAppleJob.stub(:perform_now, ->(*, **) { raise "some apple error" }) do NewRelic::Agent.stub(:notice_error, mock) do - job.publish_apple(feed) + job.publish_apple(podcast, private_feed) end end assert_equal ["created", "started", "error_apple"].sort, PublishingPipelineState.where(podcast: feed.podcast).latest_pipelines.pluck(:status).sort diff --git a/test/models/apple/config_test.rb b/test/models/apple/config_test.rb index 7aabed1e8..27aacace4 100644 --- a/test/models/apple/config_test.rb +++ b/test/models/apple/config_test.rb @@ -2,66 +2,41 @@ describe Apple::Config do describe "#valid?" do - it "requires both a public and private feed" do - pub_f = create(:feed) - priv_f = create(:feed) - - c1 = build(:apple_config, public_feed: pub_f, private_feed: priv_f) + it "is unique to a podcast" do + podcast = create(:podcast) + f1 = create(:feed, podcast: podcast) + c1 = create(:apple_config, feed: f1) assert c1.valid? - c2 = build(:apple_config, public_feed: nil, private_feed: priv_f) + f2 = create(:feed, podcast: podcast) + c2 = build(:apple_config, feed: f2) refute c2.valid? + assert_equal ["podcast already has an apple config"], c2.errors[:feed] - c3 = build(:apple_config, public_feed: pub_f, private_feed: nil) + # can't have 2 on same feed either + c3 = build(:apple_config, feed: f1) refute c3.valid? + assert_equal ["podcast already has an apple config"], c2.errors[:feed] end - it "is unique to a public and private feed" do - podcast1 = create(:podcast) - podcast2 = create(:podcast) - f1 = create(:feed, podcast: podcast1) - f2 = create(:feed, podcast: podcast1) - f3 = create(:feed, podcast: podcast2) - f4 = create(:feed, podcast: podcast2) - - c1 = create(:apple_config, podcast: podcast1, public_feed: f1, private_feed: f2) - assert c1.valid? - - c2 = build(:apple_config, podcast: podcast1, public_feed: f1, private_feed: f2) - refute c2.valid? - - c3 = build(:apple_config, podcast: podcast1, public_feed: f1, private_feed: f3) - refute c3.valid? - - c4 = build(:apple_config, podcast: podcast2, public_feed: f4, private_feed: f2) - refute c4.valid? - - c5 = build(:apple_config, podcast: podcast1, public_feed: f1, private_feed: f1) - refute c5.valid? - - c6 = build(:apple_config, podcast: podcast2, public_feed: f3, private_feed: f4) - assert c6.valid? - - c7 = build(:apple_config, podcast: podcast2, public_feed: f4, private_feed: f3) - assert c7.valid? - - c7 = build(:apple_config, podcast: podcast2, public_feed: f4, private_feed: f4) - refute c7.valid? - end - - it "is unique to a podcast" do + it "cannot be the default feed" do podcast = create(:podcast) - f1 = create(:feed, podcast: podcast) - f2 = create(:feed, podcast: podcast) - f3 = create(:feed, podcast: podcast) - f4 = create(:feed, podcast: podcast) - - c1 = create(:apple_config, podcast: podcast, public_feed: f1, private_feed: f2) - assert c1.valid? - - c2 = build(:apple_config, podcast: podcast, public_feed: f3, private_feed: f4) - refute c2.valid? - assert_equal ["has already been taken"], c2.errors[:podcast] + c1 = build(:apple_config, feed: podcast.default_feed) + refute c1.valid? + assert_equal ["cannot use default feed"], c1.errors[:feed] end end + + it "delegates associations" do + podcast = build_stubbed(:podcast) + public_feed = podcast.default_feed + private_feed = build_stubbed(:private_feed, podcast: podcast) + config = build_stubbed(:apple_config, feed: private_feed) + + assert_equal podcast, config.podcast + assert_equal podcast.id, config.podcast_id + assert_equal podcast.title, config.podcast_title + assert_equal public_feed, config.public_feed + assert_equal private_feed, config.private_feed + end end diff --git a/test/models/apple/episode_test.rb b/test/models/apple/episode_test.rb index 3fefc37f5..6f0e52b9d 100644 --- a/test/models/apple/episode_test.rb +++ b/test/models/apple/episode_test.rb @@ -5,7 +5,7 @@ describe Apple::Episode do let(:podcast) { create(:podcast) } - let(:public_feed) { create(:feed, podcast: podcast, private: false) } + let(:public_feed) { podcast.default_feed } let(:private_feed) { create(:private_feed, podcast: podcast) } let(:apple_config) { build(:apple_config) } diff --git a/test/models/apple/podcast_container_test.rb b/test/models/apple/podcast_container_test.rb index 5f3896bc4..7c07e3b68 100644 --- a/test/models/apple/podcast_container_test.rb +++ b/test/models/apple/podcast_container_test.rb @@ -8,7 +8,7 @@ class Apple::PodcastContainerTest < ActiveSupport::TestCase let(:apple_config) { build(:apple_config) } let(:apple_api) { Apple::Api.from_apple_config(apple_config) } - let(:public_feed) { create(:feed, podcast: podcast, private: false) } + let(:public_feed) { podcast.default_feed } let(:private_feed) { create(:private_feed, podcast: podcast) } let(:apple_show) { Apple::Show.new(api: apple_api, public_feed: public_feed, private_feed: private_feed) } diff --git a/test/models/apple/podcast_delivery_file_test.rb b/test/models/apple/podcast_delivery_file_test.rb index 4a85042ff..41f872224 100644 --- a/test/models/apple/podcast_delivery_file_test.rb +++ b/test/models/apple/podcast_delivery_file_test.rb @@ -71,7 +71,7 @@ class ApplePodcastDeliveryFileTest < ActiveSupport::TestCase } let(:podcast) { create(:podcast) } - let(:public_feed) { create(:feed, podcast: podcast, private: false) } + let(:public_feed) { podcast.default_feed } let(:private_feed) { create(:feed, podcast: podcast, private: true, tokens: [FeedToken.new]) } let(:apple_config) { build(:apple_config) } diff --git a/test/models/apple/publisher_test.rb b/test/models/apple/publisher_test.rb index d1ff13f84..8a26f84bb 100644 --- a/test/models/apple/publisher_test.rb +++ b/test/models/apple/publisher_test.rb @@ -4,7 +4,7 @@ describe Apple::Publisher do let(:podcast) { create(:podcast) } - let(:public_feed) { create(:feed, podcast: podcast, private: false) } + let(:public_feed) { podcast.default_feed } let(:private_feed) { create(:feed, podcast: podcast, private: true) } let(:apple_config) { build(:apple_config) } let(:apple_api) { Apple::Api.from_apple_config(apple_config) } @@ -49,7 +49,7 @@ describe "#filter_episodes_to_sync" do let(:podcast) { create(:podcast) } - let(:public_feed) { create(:feed, podcast: podcast, private: false) } + let(:public_feed) { podcast.default_feed } let(:private_feed) { create(:private_feed, podcast: podcast) } let(:apple_config) { build(:apple_config) } @@ -98,9 +98,9 @@ describe "Archive and Unarchive flows" do let(:podcast) { create(:podcast) } - let(:public_feed) { create(:feed, podcast: podcast, private: false) } + let(:public_feed) { podcast.default_feed } let(:private_feed) { create(:private_feed, podcast: podcast) } - let(:apple_config) { create(:apple_config, podcast: podcast, public_feed: public_feed, private_feed: private_feed) } + let(:apple_config) { create(:apple_config, feed: private_feed) } let(:episode) { create(:episode, podcast: podcast) } let(:apple_episode_api_response) { build(:apple_episode_api_response, apple_episode_id: "123") } let(:apple_publisher) { apple_config.build_publisher } diff --git a/test/models/apple/show_test.rb b/test/models/apple/show_test.rb index e086a7965..3af027d19 100644 --- a/test/models/apple/show_test.rb +++ b/test/models/apple/show_test.rb @@ -5,9 +5,9 @@ describe Apple::Show do let(:podcast) { create(:episode).podcast } let(:apple_api) { Apple::Api.from_apple_config(apple_config) } - let(:public_feed) { create(:feed, podcast: podcast, private: false) } + let(:public_feed) { podcast.default_feed } let(:private_feed) { create(:private_feed, podcast: podcast) } - let(:apple_config) { build(:apple_config, podcast: podcast, public_feed: public_feed, private_feed: private_feed) } + let(:apple_config) { build(:apple_config, feed: private_feed) } let(:apple_show) { Apple::Show.connect_existing("123", apple_config) } before do @@ -158,7 +158,7 @@ end describe ".connect_existing" do - let(:apple_config) { create(:apple_config, podcast: podcast, public_feed: public_feed, private_feed: private_feed) } + let(:apple_config) { create(:apple_config, feed: private_feed) } it "should take in the apple show id an apple credentials object" do apple_config.save! @@ -256,7 +256,7 @@ it "returns an authed url if private" do assert_equal apple_show.feed_published_url, - "https://p.prxu.org/#{public_feed.podcast.path}/#{public_feed.slug}/feed-rss.xml?auth=" + public_feed.tokens.first.token + "https://p.prxu.org/#{public_feed.podcast.path}/feed-rss.xml?auth=" + public_feed.tokens.first.token end it "raises an error when there is no token" do diff --git a/test/models/feed_test.rb b/test/models/feed_test.rb index b966bcc28..a20d76191 100644 --- a/test/models/feed_test.rb +++ b/test/models/feed_test.rb @@ -326,28 +326,27 @@ describe "#apple_configs" do it "has apple credentials" do - creds = create(:apple_config, podcast: podcast, public_feed: feed1, private_feed: feed2) - assert_equal feed1.apple_config, creds - assert_equal feed1.apple_config.private_feed, feed2 + creds = create(:apple_config, feed: feed2) + assert_equal creds, feed2.apple_config + assert_equal feed1, feed2.apple_config.public_feed end end describe "#publish_to_apple?" do it "returns true if the feed has apple credentials" do - create(:apple_config, podcast: podcast, public_feed: feed1, private_feed: feed2, publish_enabled: true) - assert feed1.publish_to_apple? - refute feed2.publish_to_apple? + create(:apple_config, feed: feed2, publish_enabled: true) + refute feed1.publish_to_apple? + assert feed2.publish_to_apple? end it "returns false if the creds are not marked publish_enabled?" do - create(:apple_config, podcast: podcast, public_feed: feed1, private_feed: feed2, publish_enabled: false) - refute feed1.publish_to_apple? + create(:apple_config, feed: feed2, publish_enabled: false) + refute feed2.publish_to_apple? end it "returns false if the feed does not have apple credentials" do - feed1.podcast.apple_config&.destroy - refute feed1.podcast.apple_config - refute feed1.publish_to_apple? + refute feed2.apple_config + refute feed2.publish_to_apple? end end end diff --git a/test/models/imports/podcast_rss_import_test.rb b/test/models/imports/podcast_rss_import_test.rb index ad65fbde6..9905fed08 100644 --- a/test/models/imports/podcast_rss_import_test.rb +++ b/test/models/imports/podcast_rss_import_test.rb @@ -149,9 +149,9 @@ it "looks for an owner" do owner = OpenStruct.new(name: "n", email: "e") - importer.owner(nil).must_equal({}) - importer.owner([]).must_equal({}) - importer.owner([owner]).must_equal({"name" => "n", "email" => "e"}) + _(importer.owner(nil)).must_equal({}) + _(importer.owner([])).must_equal({}) + _(importer.owner([owner])).must_equal({"name" => "n", "email" => "e"}) end it "can make a good guess for an enclosure prefix" do diff --git a/test/models/publishing_pipeline_state_test.rb b/test/models/publishing_pipeline_state_test.rb index c7d109c1b..4239e4e77 100644 --- a/test/models/publishing_pipeline_state_test.rb +++ b/test/models/publishing_pipeline_state_test.rb @@ -252,7 +252,7 @@ describe "error!" do it 'sets the status to "error"' do PublishFeedJob.stub_any_instance(:save_file, nil) do - PublishFeedJob.stub_any_instance(:publish_feed, ->(*args) { raise "error" }) do + PublishFeedJob.stub_any_instance(:publish_apple, ->(*args) { raise "error" }) do assert_raises(RuntimeError) { PublishingPipelineState.attempt!(podcast, perform_later: false) } end end @@ -264,8 +264,10 @@ describe "complete!" do it 'sets the status to "complete"' do PublishFeedJob.stub_any_instance(:save_file, nil) do - PublishFeedJob.stub_any_instance(:publish_feed, "pub!") do - PublishingPipelineState.attempt!(podcast, perform_later: false) + PublishFeedJob.stub_any_instance(:publish_apple, "pub!") do + PublishFeedJob.stub_any_instance(:publish_rss, "pub!") do + PublishingPipelineState.attempt!(podcast, perform_later: false) + end end end @@ -277,8 +279,10 @@ PublishingQueueItem.create!(podcast: podcast) PublishFeedJob.stub_any_instance(:save_file, nil) do - PublishFeedJob.stub_any_instance(:publish_feed, "pub!") do - PublishingPipelineState.attempt!(podcast, perform_later: false) + PublishFeedJob.stub_any_instance(:publish_apple, "pub!") do + PublishFeedJob.stub_any_instance(:publish_rss, "pub!") do + PublishingPipelineState.attempt!(podcast, perform_later: false) + end end end @@ -292,21 +296,13 @@ end describe "Apple publishing" do - before do - 2.times { create(:private_feed, podcast: podcast) } - podcast.reload - - f1, f2, _f3 = podcast.feeds - - create(:apple_config, - podcast: podcast, - public_feed: f1, - private_feed: f2, - publish_enabled: true) - end + let(:f1) { podcast.default_feed } + let(:f2) { create(:private_feed, podcast: podcast) } + let(:f3) { create(:private_feed, podcast: podcast) } + let(:apple_config) { create(:apple_config, feed: f3, publish_enabled: true) } it "can publish via the apple configs" do - assert_equal 3, podcast.reload.feeds.count + assert [f1, f2, f3, apple_config] PublishAppleJob.stub(:perform_now, "published apple!") do PublishFeedJob.stub_any_instance(:save_file, "saved rss!") do