diff --git a/app/models/apple/podcast_container.rb b/app/models/apple/podcast_container.rb index f1ecf6e50..212afbb5b 100644 --- a/app/models/apple/podcast_container.rb +++ b/app/models/apple/podcast_container.rb @@ -249,7 +249,8 @@ def missing_podcast_audio? end def delivered? - return false if podcast_delivery_files.length == 0 + # because we cannot infer if the podcast delivery files have expired + return true if podcast_delivery_files.length == 0 (podcast_delivery_files.all?(&:delivered?) && podcast_delivery_files.all?(&:processed?)) @@ -262,15 +263,9 @@ def processed_errors? end def delivery_settled? - return false if podcast_delivery_files.length == 0 - delivered? && !processed_errors? end - def skip_delivery? - container_upload_satisfied? - end - def container_upload_satisfied? # Sets us up for a retry if something prevented the audio from being # marked as uploaded and then processed and validated. Assuming that we @@ -279,6 +274,10 @@ def container_upload_satisfied? has_podcast_audio? && delivery_settled? end + def skip_delivery? + container_upload_satisfied? + end + def needs_delivery? !skip_delivery? end diff --git a/test/models/apple/episode_test.rb b/test/models/apple/episode_test.rb index 3372e33a0..86719675d 100644 --- a/test/models/apple/episode_test.rb +++ b/test/models/apple/episode_test.rb @@ -91,9 +91,9 @@ assert_equal true, apple_episode.waiting_for_asset_state? end - it "should be false if there are no podcast delivery files" do + it "should be true if there are no podcast delivery files and the asset state is UNSPECIFIED" do apple_episode.podcast_container.stub(:podcast_delivery_files, []) do - assert_equal false, apple_episode.waiting_for_asset_state? + assert_equal true, apple_episode.waiting_for_asset_state? end end diff --git a/test/models/apple/podcast_container_test.rb b/test/models/apple/podcast_container_test.rb index a8dfa7024..784f23085 100644 --- a/test/models/apple/podcast_container_test.rb +++ b/test/models/apple/podcast_container_test.rb @@ -256,6 +256,31 @@ class Apple::PodcastContainerTest < ActiveSupport::TestCase end end + describe "retry sentinals and gatekeeping" do + let(:container) { Apple::PodcastContainer.new } + describe "#delivery_settled?" do + it "should be settled if there are no delivery files" do + container.stub(:podcast_delivery_files, []) do + assert container.delivery_settled? + assert container.delivered? + end + end + end + + describe "#container_upload_satisfied?" do + it "should be satisfied with podcast files and a settled delivery" do + container.stub(:files, [ + {status: Apple::PodcastContainer::FILE_STATUS_SUCCESS, + assetRole: Apple::PodcastContainer::FILE_ASSET_ROLE_PODCAST_AUDIO}.with_indifferent_access + ]) do + container.stub(:podcast_delivery_files, []) do + assert container.container_upload_satisfied? + end + end + end + end + end + describe "#destroy" do it "should destroy the podcast container and cascade to the delivery and delivery file" do apple_episode.stub(:apple_id, apple_episode_id) do