Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/models/transcript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Transcript < ApplicationRecord
has_many :tasks, as: :owner

before_validation :initialize_attributes, on: :create
after_save :publish!

validates :original_url, presence: true

Expand Down Expand Up @@ -98,6 +99,10 @@ def copy_media(force = false)
end
end

def publish!
episode&.publish! if status_complete? && status_previously_changed?
end

def retryable?
if %w[started created processing retrying].include?(status)
last_event = task&.updated_at || updated_at || Time.now
Expand Down
21 changes: 21 additions & 0 deletions test/models/transcript_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@
end
end

describe "#publish!" do
let(:transcript) { create(:transcript, status: "started") }

it "publishes the episode when complete and status has changed" do
publish = Minitest::Mock.new
publish.expect(:call, nil) { raise "should not have called" }

transcript.episode.stub(:publish!, publish) do
transcript.update(status: "processing")
end

publish = Minitest::Mock.new
publish.expect(:call, nil)
transcript.episode.stub(:publish!, publish) do
transcript.update(status: "complete")
end

assert publish.verify
end
end

describe "rss_mime_type" do
it "returns the mime type for the transcript format" do
assert_equal "text/html", transcript.rss_mime_type
Expand Down
Loading