-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtranscript_test.rb
More file actions
97 lines (78 loc) · 2.42 KB
/
Copy pathtranscript_test.rb
File metadata and controls
97 lines (78 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require "test_helper"
describe Transcript do
let(:episode) { build_stubbed(:episode) }
let(:url) { "http://sample/url/transcript.html" }
let(:transcript) { build_stubbed(:transcript, episode: episode) }
describe "#valid?" do
before do
assert transcript.valid?
end
it "requires an original_url" do
transcript.original_url = nil
refute transcript.valid?
end
it "must have a format" do
transcript.format = nil
refute transcript.valid?
end
end
describe "#copy_media" do
it "creates a task" do
task = Tasks::CopyTranscriptTask.new
create_task = ->(&block) do
block.call(task)
task
end
Tasks::CopyTranscriptTask.stub(:create!, create_task) do
task.stub(:start!, true) do
transcript.status = "created"
transcript.task = nil
transcript.copy_media
assert_equal transcript, task.owner
end
end
end
it "skips creating task if complete" do
transcript.task = nil
assert transcript.status_complete?
transcript.copy_media
assert_nil transcript.task
end
it "skips creating task if one exists" do
task = Tasks::CopyTranscriptTask.new
transcript.status = "created"
transcript.task = task
transcript.copy_media
assert_equal task, transcript.task
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
transcript.format = "json"
assert_equal "application/json", transcript.rss_mime_type
transcript.format = nil
assert_nil transcript.rss_mime_type
# pretend bad data got into the db somehow
transcript.stub(:format, "whatev") do
assert_nil transcript.rss_mime_type
end
end
end
end