Skip to content

Commit 0960e83

Browse files
authored
Merge pull request #1461 from PRX/fix/publish_transcripts
Publish RSS after copying transcript
2 parents c59097a + 53bc5d2 commit 0960e83

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

app/models/transcript.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Transcript < ApplicationRecord
2222
has_many :tasks, as: :owner
2323

2424
before_validation :initialize_attributes, on: :create
25+
after_save :publish!
2526

2627
validates :original_url, presence: true
2728

@@ -98,6 +99,10 @@ def copy_media(force = false)
9899
end
99100
end
100101

102+
def publish!
103+
episode&.publish! if status_complete? && status_previously_changed?
104+
end
105+
101106
def retryable?
102107
if %w[started created processing retrying].include?(status)
103108
last_event = task&.updated_at || updated_at || Time.now

test/models/transcript_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@
5757
end
5858
end
5959

60+
describe "#publish!" do
61+
let(:transcript) { create(:transcript, status: "started") }
62+
63+
it "publishes the episode when complete and status has changed" do
64+
publish = Minitest::Mock.new
65+
publish.expect(:call, nil) { raise "should not have called" }
66+
67+
transcript.episode.stub(:publish!, publish) do
68+
transcript.update(status: "processing")
69+
end
70+
71+
publish = Minitest::Mock.new
72+
publish.expect(:call, nil)
73+
transcript.episode.stub(:publish!, publish) do
74+
transcript.update(status: "complete")
75+
end
76+
77+
assert publish.verify
78+
end
79+
end
80+
6081
describe "rss_mime_type" do
6182
it "returns the mime type for the transcript format" do
6283
assert_equal "text/html", transcript.rss_mime_type

0 commit comments

Comments
 (0)