active_encode 1.2.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +1 -0
  3. data/active_encode.gemspec +1 -2
  4. data/lib/active_encode/engine_adapters/pass_through_adapter.rb +28 -7
  5. data/lib/active_encode/version.rb +1 -1
  6. metadata +4 -274
  7. data/spec/controllers/encode_record_controller_spec.rb +0 -53
  8. data/spec/fixtures//"file_with_double_quote/".low.mp4 +0 -0
  9. data/spec/fixtures//"file_with_double_quote/".mp4 +0 -0
  10. data/spec/fixtures/'file_with_single_quote'.low.mp4 +0 -0
  11. data/spec/fixtures/'file_with_single_quote'.mp4 +0 -0
  12. data/spec/fixtures/@/341/213/210/341/213/263/341/214/205/341/210/205 /341/210/233/341/210/255 /341/211/242. /341/210/206/341/212/225 /341/214/250/341/210/255/341/210/265. /341/210/205 /341/212/240/341/211/265/341/210/213/341/210/260!@#$^^&$%&.low.mov +0 -0
  13. data/spec/fixtures/@/341/213/210/341/213/263/341/214/205/341/210/205 /341/210/233/341/210/255 /341/211/242. /341/210/206/341/212/225 /341/214/250/341/210/255/341/210/265. /341/210/205 /341/212/240/341/211/265/341/210/213/341/210/260!@#$^^&$%&.mov +0 -0
  14. data/spec/fixtures/Bars_512kb.mp4 +0 -0
  15. data/spec/fixtures/elastic_transcoder/input_completed.json +0 -1
  16. data/spec/fixtures/elastic_transcoder/input_generic.json +0 -1
  17. data/spec/fixtures/elastic_transcoder/input_progressing.json +0 -1
  18. data/spec/fixtures/elastic_transcoder/job_canceled.json +0 -1
  19. data/spec/fixtures/elastic_transcoder/job_completed.json +0 -1
  20. data/spec/fixtures/elastic_transcoder/job_created.json +0 -1
  21. data/spec/fixtures/elastic_transcoder/job_failed.json +0 -1
  22. data/spec/fixtures/elastic_transcoder/job_progressing.json +0 -1
  23. data/spec/fixtures/elastic_transcoder/output_canceled.json +0 -1
  24. data/spec/fixtures/elastic_transcoder/output_completed.json +0 -1
  25. data/spec/fixtures/elastic_transcoder/output_failed.json +0 -1
  26. data/spec/fixtures/elastic_transcoder/output_progressing.json +0 -1
  27. data/spec/fixtures/elastic_transcoder/output_submitted.json +0 -1
  28. data/spec/fixtures/ffmpeg/cancelled-id/cancelled +0 -0
  29. data/spec/fixtures/ffmpeg/cancelled-id/error.log +0 -0
  30. data/spec/fixtures/ffmpeg/cancelled-id/exit_status.code +0 -1
  31. data/spec/fixtures/ffmpeg/cancelled-id/input_metadata +0 -90
  32. data/spec/fixtures/ffmpeg/cancelled-id/pid +0 -1
  33. data/spec/fixtures/ffmpeg/cancelled-id/progress +0 -11
  34. data/spec/fixtures/ffmpeg/completed-id/error.log +0 -0
  35. data/spec/fixtures/ffmpeg/completed-id/exit_status.code +0 -1
  36. data/spec/fixtures/ffmpeg/completed-id/input_metadata +0 -102
  37. data/spec/fixtures/ffmpeg/completed-id/output_metadata-high +0 -90
  38. data/spec/fixtures/ffmpeg/completed-id/output_metadata-low +0 -90
  39. data/spec/fixtures/ffmpeg/completed-id/pid +0 -1
  40. data/spec/fixtures/ffmpeg/completed-id/progress +0 -11
  41. data/spec/fixtures/ffmpeg/completed-id/video-high.mp4 +0 -0
  42. data/spec/fixtures/ffmpeg/completed-id/video-low.mp4 +0 -0
  43. data/spec/fixtures/ffmpeg/completed-with-warnings-id/error.log +0 -3
  44. data/spec/fixtures/ffmpeg/completed-with-warnings-id/exit_status.code +0 -1
  45. data/spec/fixtures/ffmpeg/completed-with-warnings-id/input_metadata +0 -102
  46. data/spec/fixtures/ffmpeg/completed-with-warnings-id/output_metadata-high +0 -90
  47. data/spec/fixtures/ffmpeg/completed-with-warnings-id/output_metadata-low +0 -90
  48. data/spec/fixtures/ffmpeg/completed-with-warnings-id/pid +0 -1
  49. data/spec/fixtures/ffmpeg/completed-with-warnings-id/progress +0 -11
  50. data/spec/fixtures/ffmpeg/completed-with-warnings-id/video-high.mp4 +0 -0
  51. data/spec/fixtures/ffmpeg/completed-with-warnings-id/video-low.mp4 +0 -0
  52. data/spec/fixtures/ffmpeg/failed-id/error.log +0 -1
  53. data/spec/fixtures/ffmpeg/failed-id/exit_status.code +0 -1
  54. data/spec/fixtures/ffmpeg/failed-id/input_metadata +0 -90
  55. data/spec/fixtures/ffmpeg/failed-id/pid +0 -1
  56. data/spec/fixtures/ffmpeg/failed-id/progress +0 -11
  57. data/spec/fixtures/ffmpeg/incomplete-id/error.log +0 -0
  58. data/spec/fixtures/ffmpeg/incomplete-id/exit_status.code +0 -1
  59. data/spec/fixtures/ffmpeg/incomplete-id/input_metadata +0 -102
  60. data/spec/fixtures/ffmpeg/incomplete-id/output_metadata-high +0 -90
  61. data/spec/fixtures/ffmpeg/incomplete-id/output_metadata-low +0 -90
  62. data/spec/fixtures/ffmpeg/incomplete-id/pid +0 -1
  63. data/spec/fixtures/ffmpeg/incomplete-id/progress +0 -11
  64. data/spec/fixtures/ffmpeg/incomplete-id/video-high.mp4 +0 -0
  65. data/spec/fixtures/ffmpeg/incomplete-id/video-low.mp4 +0 -0
  66. data/spec/fixtures/ffmpeg/running-id/error.log +0 -0
  67. data/spec/fixtures/ffmpeg/running-id/input_metadata +0 -90
  68. data/spec/fixtures/ffmpeg/running-id/pid +0 -1
  69. data/spec/fixtures/ffmpeg/running-id/progress +0 -11
  70. data/spec/fixtures/file with space.low.mp4 +0 -0
  71. data/spec/fixtures/file with space.mp4 +0 -0
  72. data/spec/fixtures/file.with :=+%sp3c!l-ch4cts().mp4 +0 -0
  73. data/spec/fixtures/file.with...periods.mp4 +0 -0
  74. data/spec/fixtures/file_without_metadata.low.webm +0 -0
  75. data/spec/fixtures/file_without_metadata.mp4 +0 -0
  76. data/spec/fixtures/file_without_metadata.webm +0 -0
  77. data/spec/fixtures/fireworks.low.mp4 +0 -0
  78. data/spec/fixtures/fireworks.mp4 +0 -0
  79. data/spec/fixtures/matterhorn/cancelled_response.xml +0 -323
  80. data/spec/fixtures/matterhorn/completed_response.xml +0 -4
  81. data/spec/fixtures/matterhorn/create_response.xml +0 -300
  82. data/spec/fixtures/matterhorn/delete_track_response.xml +0 -2
  83. data/spec/fixtures/matterhorn/failed_response.xml +0 -4
  84. data/spec/fixtures/matterhorn/purged_response.xml +0 -342
  85. data/spec/fixtures/matterhorn/running_response.xml +0 -1
  86. data/spec/fixtures/matterhorn/stop_completed_response.xml +0 -228
  87. data/spec/fixtures/matterhorn/stop_running_response.xml +0 -339
  88. data/spec/fixtures/media_convert/endpoints.json +0 -1
  89. data/spec/fixtures/media_convert/job_canceled.json +0 -412
  90. data/spec/fixtures/media_convert/job_canceling.json +0 -1
  91. data/spec/fixtures/media_convert/job_completed.json +0 -359
  92. data/spec/fixtures/media_convert/job_completed_detail.json +0 -1
  93. data/spec/fixtures/media_convert/job_completed_detail_query.json +0 -1
  94. data/spec/fixtures/media_convert/job_completed_empty_detail.json +0 -1
  95. data/spec/fixtures/media_convert/job_created.json +0 -408
  96. data/spec/fixtures/media_convert/job_failed.json +0 -406
  97. data/spec/fixtures/media_convert/job_progressing.json +0 -414
  98. data/spec/fixtures/pass_through/cancelled-id/cancelled +0 -0
  99. data/spec/fixtures/pass_through/cancelled-id/input_metadata +0 -90
  100. data/spec/fixtures/pass_through/completed-id/completed +0 -0
  101. data/spec/fixtures/pass_through/completed-id/input_metadata +0 -102
  102. data/spec/fixtures/pass_through/completed-id/output_metadata-high +0 -90
  103. data/spec/fixtures/pass_through/completed-id/output_metadata-low +0 -90
  104. data/spec/fixtures/pass_through/completed-id/video-high.mp4 +0 -0
  105. data/spec/fixtures/pass_through/completed-id/video-low.mp4 +0 -0
  106. data/spec/fixtures/pass_through/failed-id/error.log +0 -1
  107. data/spec/fixtures/pass_through/failed-id/input_metadata +0 -90
  108. data/spec/fixtures/pass_through/running-id/input_metadata +0 -90
  109. data/spec/fixtures/zencoder/job_create.json +0 -1
  110. data/spec/fixtures/zencoder/job_details_cancelled.json +0 -1
  111. data/spec/fixtures/zencoder/job_details_completed.json +0 -1
  112. data/spec/fixtures/zencoder/job_details_create.json +0 -1
  113. data/spec/fixtures/zencoder/job_details_failed.json +0 -73
  114. data/spec/fixtures/zencoder/job_details_running.json +0 -1
  115. data/spec/fixtures/zencoder/job_progress_cancelled.json +0 -13
  116. data/spec/fixtures/zencoder/job_progress_completed.json +0 -13
  117. data/spec/fixtures/zencoder/job_progress_create.json +0 -1
  118. data/spec/fixtures/zencoder/job_progress_failed.json +0 -13
  119. data/spec/fixtures/zencoder/job_progress_running.json +0 -1
  120. data/spec/integration/elastic_transcoder_adapter_spec.rb +0 -218
  121. data/spec/integration/ffmpeg_adapter_spec.rb +0 -535
  122. data/spec/integration/matterhorn_adapter_spec.rb +0 -130
  123. data/spec/integration/media_convert_adapter_spec.rb +0 -321
  124. data/spec/integration/pass_through_adapter_spec.rb +0 -293
  125. data/spec/integration/zencoder_adapter_spec.rb +0 -391
  126. data/spec/rails_helper.rb +0 -25
  127. data/spec/routing/encode_record_controller_routing_spec.rb +0 -10
  128. data/spec/spec_helper.rb +0 -20
  129. data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -16
  130. data/spec/units/callbacks_spec.rb +0 -66
  131. data/spec/units/core_spec.rb +0 -160
  132. data/spec/units/engine_adapter_spec.rb +0 -67
  133. data/spec/units/file_locator_spec.rb +0 -129
  134. data/spec/units/filename_sanitizer_spec.rb +0 -20
  135. data/spec/units/global_id_spec.rb +0 -50
  136. data/spec/units/input_spec.rb +0 -40
  137. data/spec/units/output_spec.rb +0 -42
  138. data/spec/units/persistence_spec.rb +0 -61
  139. data/spec/units/polling_job_spec.rb +0 -87
  140. data/spec/units/polling_spec.rb +0 -23
  141. data/spec/units/status_spec.rb +0 -81
@@ -1,160 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
-
4
- describe ActiveEncode::Core do
5
- before do
6
- class CustomEncode < ActiveEncode::Base
7
- end
8
- end
9
- after do
10
- Object.send(:remove_const, :CustomEncode)
11
- end
12
-
13
- let(:encode_class) { ActiveEncode::Base }
14
-
15
- describe 'attributes' do
16
- subject { encode_class.new(nil) }
17
-
18
- it { is_expected.to respond_to(:id, :input, :output, :options, :percent_complete, :current_operations) }
19
-
20
- context 'with an ActiveEncode::Base subclass' do
21
- let(:encode_class) { CustomEncode }
22
-
23
- it { is_expected.to respond_to(:id, :input, :output, :options, :percent_complete, :current_operations) }
24
- end
25
- end
26
-
27
- describe 'find' do
28
- subject { encode_class.find(id) }
29
- let(:id) { encode_class.create(nil).id }
30
-
31
- it { is_expected.to be_a encode_class }
32
- it { expect(subject.id).to eq id }
33
-
34
- context 'with no id' do
35
- let(:id) { nil }
36
-
37
- it 'raises an error' do
38
- expect { subject }.to raise_error(ArgumentError)
39
- end
40
- end
41
-
42
- context 'with an ActiveEncode::Base subclass' do
43
- let(:encode_class) { CustomEncode }
44
-
45
- it { is_expected.to be_a encode_class }
46
- it { expect(subject.id).to eq id }
47
-
48
- context 'casting' do
49
- let(:id) { ActiveEncode::Base.create(nil).id }
50
-
51
- it { is_expected.to be_a encode_class }
52
- it { expect(subject.id).to eq id }
53
- end
54
- end
55
- end
56
-
57
- describe 'create' do
58
- subject { encode_class.create(nil) }
59
-
60
- it { is_expected.to be_a encode_class }
61
- it { expect(subject.id).not_to be nil }
62
- it { expect(subject.state).not_to be nil }
63
-
64
- context 'with an ActiveEncode::Base subclass' do
65
- let(:encode_class) { CustomEncode }
66
-
67
- it { is_expected.to be_a encode_class }
68
- it { expect(subject.id).not_to be nil }
69
- it { expect(subject.state).not_to be nil }
70
- end
71
- end
72
-
73
- describe '#create!' do
74
- subject { encode.create! }
75
- let(:encode) { encode_class.new(nil) }
76
-
77
- it { is_expected.to equal encode }
78
- it { is_expected.to be_a encode_class }
79
- it { expect(subject.id).not_to be nil }
80
- it { expect(subject.state).not_to be nil }
81
-
82
- context 'with an ActiveEncode::Base subclass' do
83
- let(:encode_class) { CustomEncode }
84
-
85
- it { is_expected.to equal encode }
86
- it { is_expected.to be_a encode_class }
87
- it { expect(subject.id).not_to be nil }
88
- it { expect(subject.state).not_to be nil }
89
- end
90
- end
91
-
92
- describe '#cancel!' do
93
- subject { encode.cancel! }
94
- let(:encode) { encode_class.create(nil) }
95
-
96
- it { is_expected.to equal encode }
97
- it { is_expected.to be_a encode_class }
98
- it { expect(subject.id).not_to be nil }
99
- it { is_expected.to be_cancelled }
100
-
101
- context 'with an ActiveEncode::Base subclass' do
102
- let(:encode_class) { CustomEncode }
103
-
104
- it { is_expected.to equal encode }
105
- it { is_expected.to be_a encode_class }
106
- it { expect(subject.id).not_to be nil }
107
- it { is_expected.to be_cancelled }
108
- end
109
- end
110
-
111
- describe '#reload' do
112
- subject { encode.reload }
113
- let(:encode) { encode_class.create(nil) }
114
-
115
- it { is_expected.to equal encode }
116
- it { is_expected.to be_a encode_class }
117
- it { expect(subject.id).not_to be nil }
118
- it { expect(subject.state).not_to be nil }
119
-
120
- context 'with an ActiveEncode::Base subclass' do
121
- let(:encode_class) { CustomEncode }
122
-
123
- it { is_expected.to equal encode }
124
- it { is_expected.to be_a encode_class }
125
- it { expect(subject.id).not_to be nil }
126
- it { expect(subject.state).not_to be nil }
127
- end
128
- end
129
-
130
- describe '#new' do
131
- subject { encode.options }
132
- before do
133
- class DefaultOptionsEncode < ActiveEncode::Base
134
- def self.default_options(_input_url)
135
- { preset: 'video' }
136
- end
137
- end
138
- end
139
- after do
140
- Object.send(:remove_const, :DefaultOptionsEncode)
141
- end
142
-
143
- let(:encode_class) { DefaultOptionsEncode }
144
- let(:default_options) { { preset: 'video' } }
145
- let(:options) { { output: [{ label: 'high', ffmpeg_opt: "640x480" }] } }
146
- let(:encode) { encode_class.new(nil, options) }
147
-
148
- it 'merges default options and options parameter' do
149
- expect(subject).to include default_options
150
- expect(subject).to include options
151
- end
152
-
153
- context 'with collisions' do
154
- let(:options) { { preset: 'avalon' } }
155
- it 'prefers options parameter' do
156
- expect(subject[:preset]).to eq 'avalon'
157
- end
158
- end
159
- end
160
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
-
4
- describe ActiveEncode::EngineAdapter do
5
- before do
6
- module ActiveEncode
7
- module EngineAdapters
8
- class StubOneAdapter
9
- def create(_); end
10
-
11
- def find(_, _ = {}); end
12
-
13
- def cancel(_encode); end
14
- end
15
-
16
- class StubTwoAdapter
17
- def create(_encode); end
18
-
19
- def find(_id, _opts = {}); end
20
-
21
- def cancel(_encode); end
22
- end
23
- end
24
- end
25
- end
26
-
27
- after do
28
- ActiveEncode::EngineAdapters.send(:remove_const, :StubOneAdapter)
29
- ActiveEncode::EngineAdapters.send(:remove_const, :StubTwoAdapter)
30
- end
31
-
32
- it 'does not allow classes as arguments' do
33
- expect { ActiveEncode::Base.engine_adapter = ActiveEncode::EngineAdapters::StubOneAdapter }.to raise_error(ArgumentError)
34
- end
35
-
36
- it 'does not allow arguments that are not engine adapters' do
37
- expect { ActiveEncode::Base.engine_adapter = Mutex.new }.to raise_error(ArgumentError)
38
- end
39
-
40
- context 'overriding' do
41
- let(:base_engine_adapter) { ActiveEncode::Base.engine_adapter }
42
-
43
- it 'does not affect the parent' do
44
- child_encode_one = Class.new(ActiveEncode::Base)
45
- child_encode_one.engine_adapter = :stub_one
46
-
47
- expect(child_encode_one.engine_adapter).not_to eq base_engine_adapter
48
- expect(child_encode_one.engine_adapter).to be_kind_of ActiveEncode::EngineAdapters::StubOneAdapter
49
- expect(ActiveEncode::Base.engine_adapter).to eq base_engine_adapter
50
- end
51
-
52
- it 'does not affect its sibling' do
53
- child_encode_one = Class.new(ActiveEncode::Base)
54
- child_encode_one.engine_adapter = :stub_one
55
- child_encode_two = Class.new(ActiveEncode::Base)
56
- child_encode_two.engine_adapter = :stub_two
57
-
58
- expect(child_encode_two.engine_adapter).not_to eq base_engine_adapter
59
- expect(child_encode_two.engine_adapter).to be_kind_of ActiveEncode::EngineAdapters::StubTwoAdapter
60
- # child_encode_one's engine adapter should remain unchanged
61
- expect(child_encode_one.engine_adapter).to be_kind_of ActiveEncode::EngineAdapters::StubOneAdapter
62
- expect(ActiveEncode::Base.engine_adapter).to eq base_engine_adapter
63
- # new encodes should not be affected
64
- expect(Class.new(ActiveEncode::Base).engine_adapter).to eq base_engine_adapter
65
- end
66
- end
67
- end
@@ -1,129 +0,0 @@
1
- # frozen_string_literal: true
2
- # Copyright 2011-2018, The Trustees of Indiana University and Northwestern
3
- # University. Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- #
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software distributed
11
- # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
- # CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
- # specific language governing permissions and limitations under the License.
14
- # --- END LICENSE_HEADER BLOCK ---
15
- require 'aws-sdk-s3'
16
- require 'rails_helper'
17
-
18
- describe FileLocator, type: :service do
19
- before do
20
- Aws.config[:stub_responses] = true
21
- end
22
-
23
- describe 'S3File Class' do
24
- let(:bucket) { "mybucket" }
25
- let(:key) { "mykey.mp4" }
26
- let(:s3file) { FileLocator::S3File.new("s3://#{bucket}/#{key}") }
27
-
28
- it "is able to initialize from an S3 URI" do
29
- expect(s3file.bucket).to eq bucket
30
- expect(s3file.key).to eq key
31
- end
32
-
33
- it "returns an S3 Object" do
34
- s3_object = s3file.object
35
- expect(s3_object).to be_an Aws::S3::Object
36
- expect(s3_object.bucket_name).to eq bucket
37
- expect(s3_object.key).to eq key
38
- end
39
- end
40
-
41
- describe "Local file" do
42
- let(:path) { "/path/to/file.mp4" }
43
- let(:source) { "file://#{path}" }
44
- let(:locator) { described_class.new(source) }
45
-
46
- it "returns the correct uri" do
47
- expect(locator.uri).to eq Addressable::URI.parse(source)
48
- end
49
-
50
- it "returns the correct location" do
51
- expect(locator.location).to eq path
52
- end
53
-
54
- it "tells if file exists" do
55
- allow(File).to receive(:exist?).with(path) { true }
56
- expect(locator.exist?).to be_truthy
57
- end
58
-
59
- context "return file" do
60
- let(:file) { double(File) }
61
- before do
62
- allow(File).to receive(:open).and_return file
63
- end
64
-
65
- it "returns reader" do
66
- expect(locator.reader).to eq file
67
- end
68
-
69
- it "returns attachment" do
70
- expect(locator.attachment).to eq file
71
- end
72
- end
73
- end
74
-
75
- describe "s3 file" do
76
- let(:bucket) { "mybucket" }
77
- let(:key) { "mykey.mp4" }
78
- let(:source) { "s3://#{bucket}/#{key}" }
79
- let(:locator) { described_class.new(source) }
80
-
81
- it "returns the correct uri" do
82
- expect(locator.uri).to eq Addressable::URI.parse(source)
83
- end
84
-
85
- it "returns the correct location" do
86
- expect(locator.location).to start_with "https://#{bucket}.s3.us-stubbed-1.amazonaws.com/#{key}"
87
- end
88
-
89
- it "tells if file exists" do
90
- expect(locator.exist?).to be_truthy
91
- end
92
-
93
- it "returns reader" do
94
- expect(locator.reader).to be_a StringIO
95
- end
96
-
97
- it "returns attachment" do
98
- expect(locator.attachment).to eq Addressable::URI.parse(source)
99
- end
100
- end
101
-
102
- describe "Other file" do
103
- let(:path) { "/path/to/file.mp4" }
104
- let(:source) { "bogus://#{path}" }
105
- let(:locator) { described_class.new(source) }
106
-
107
- it "returns the correct uri" do
108
- expect(locator.uri).to eq Addressable::URI.parse(source)
109
- end
110
-
111
- it "returns the correct location" do
112
- expect(locator.location).to eq source
113
- end
114
-
115
- it "tells if file exists" do
116
- expect(locator.exist?).to be_falsy
117
- end
118
-
119
- it "returns reader" do
120
- io = double(IO)
121
- allow(Kernel).to receive(:open).and_return io
122
- expect(locator.reader).to eq io
123
- end
124
-
125
- it "returns attachment" do
126
- expect(locator.attachment).to eq locator.location
127
- end
128
- end
129
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
- require 'addressable'
4
-
5
- describe ActiveEncode::FilenameSanitizer do
6
- describe '#sanitize_uri' do
7
- it 'removes file scheme' do
8
- uri = "file:///path/to/file"
9
- expect(ActiveEncode.sanitize_uri(uri)).to eq "/path/to/file"
10
- end
11
- it 'relativizes s3 uris' do
12
- uri = "s3://mybucket/guitar.mp4"
13
- expect(ActiveEncode.sanitize_uri(uri)).to eq "/guitar.mp4"
14
- end
15
- it 'does nothing for http(s) uris' do
16
- uri = "https://www.googleapis.com/drive/v3/files/1WkWJ12WecI9hX-PmEbuKDGLPK_mN3kYP?alt=media"
17
- expect(ActiveEncode.sanitize_uri(uri)).to eq uri
18
- end
19
- end
20
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
-
4
- describe ActiveEncode::GlobalID do
5
- before do
6
- class CustomEncode < ActiveEncode::Base
7
- end
8
- end
9
-
10
- after do
11
- Object.send(:remove_const, :CustomEncode)
12
- end
13
-
14
- describe '#to_global_id' do
15
- subject { encode.to_global_id }
16
- let(:encode_class) { ActiveEncode::Base }
17
- let(:encode) { encode_class.create(nil) }
18
-
19
- it { is_expected.to be_a GlobalID }
20
- it { expect(subject.model_class).to eq encode_class }
21
- it { expect(subject.model_id).to eq encode.id }
22
- it { expect(subject.app).to eq 'ActiveEncode' }
23
-
24
- context 'with an ActiveEncode::Base subclass' do
25
- let(:encode_class) { CustomEncode }
26
-
27
- it { is_expected.to be_a GlobalID }
28
- it { expect(subject.model_class).to eq encode_class }
29
- it { expect(subject.model_id).to eq encode.id }
30
- it { expect(subject.app).to eq 'ActiveEncode' }
31
- end
32
- end
33
-
34
- describe 'GlobalID::Locator#locate' do
35
- subject { GlobalID::Locator.locate(global_id) }
36
- let(:encode_class) { ActiveEncode::Base }
37
- let(:encode) { encode_class.create(nil) }
38
- let(:global_id) { encode.to_global_id }
39
-
40
- it { is_expected.to be_a encode_class }
41
- it { expect(subject.id).to eq encode.id }
42
-
43
- context 'with an ActiveEncode::Base subclass' do
44
- let(:encode_class) { CustomEncode }
45
-
46
- it { is_expected.to be_a encode_class }
47
- it { expect(subject.id).to eq encode.id }
48
- end
49
- end
50
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
-
4
- describe ActiveEncode::Input do
5
- subject { described_class.new }
6
-
7
- describe 'attributes' do
8
- it { is_expected.to respond_to(:id, :url) }
9
- it { is_expected.to respond_to(:state, :errors, :created_at, :updated_at) }
10
- it {
11
- is_expected.to respond_to(:width, :height, :frame_rate, :checksum,
12
- :audio_codec, :video_codec, :audio_bitrate, :video_bitrate)
13
- }
14
- end
15
-
16
- describe '#valid?' do
17
- let(:valid_input) do
18
- described_class.new.tap do |obj|
19
- obj.id = "1"
20
- obj.url = "file:///tmp/video.mp4"
21
- obj.created_at = Time.now.utc
22
- obj.updated_at = Time.now.utc
23
- end
24
- end
25
-
26
- it 'returns true when conditions met' do
27
- expect(valid_input).to be_valid
28
- end
29
-
30
- it 'returns false when conditions not met' do
31
- expect(valid_input.tap { |obj| obj.id = nil }).not_to be_valid
32
- expect(valid_input.tap { |obj| obj.url = nil }).not_to be_valid
33
- expect(valid_input.tap { |obj| obj.created_at = nil }).not_to be_valid
34
- expect(valid_input.tap { |obj| obj.created_at = "today" }).not_to be_valid
35
- expect(valid_input.tap { |obj| obj.updated_at = nil }).not_to be_valid
36
- expect(valid_input.tap { |obj| obj.updated_at = "today" }).not_to be_valid
37
- expect(valid_input.tap { |obj| obj.created_at = Time.now.utc }).not_to be_valid
38
- end
39
- end
40
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
-
4
- describe ActiveEncode::Output do
5
- subject { described_class.new }
6
-
7
- describe 'attributes' do
8
- it { is_expected.to respond_to(:id, :url, :label) }
9
- it { is_expected.to respond_to(:state, :errors, :created_at, :updated_at) }
10
- it {
11
- is_expected.to respond_to(:width, :height, :frame_rate, :checksum,
12
- :audio_codec, :video_codec, :audio_bitrate, :video_bitrate)
13
- }
14
- end
15
-
16
- describe '#valid?' do
17
- let(:valid_output) do
18
- described_class.new.tap do |obj|
19
- obj.id = "1"
20
- obj.url = "file:///tmp/video.mp4"
21
- obj.label = "HD"
22
- obj.created_at = Time.now.utc
23
- obj.updated_at = Time.now.utc
24
- end
25
- end
26
-
27
- it 'returns true when conditions met' do
28
- expect(valid_output).to be_valid
29
- end
30
-
31
- it 'returns false when conditions not met' do
32
- expect(valid_output.tap { |obj| obj.id = nil }).not_to be_valid
33
- expect(valid_output.tap { |obj| obj.url = nil }).not_to be_valid
34
- expect(valid_output.tap { |obj| obj.label = nil }).not_to be_valid
35
- expect(valid_output.tap { |obj| obj.created_at = nil }).not_to be_valid
36
- expect(valid_output.tap { |obj| obj.created_at = "today" }).not_to be_valid
37
- expect(valid_output.tap { |obj| obj.updated_at = nil }).not_to be_valid
38
- expect(valid_output.tap { |obj| obj.updated_at = "today" }).not_to be_valid
39
- expect(valid_output.tap { |obj| obj.created_at = Time.now.utc }).not_to be_valid
40
- end
41
- end
42
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'rails_helper'
3
-
4
- describe ActiveEncode::Persistence, db_clean: true do
5
- before do
6
- class CustomEncode < ActiveEncode::Base
7
- include ActiveEncode::Persistence
8
- end
9
- end
10
-
11
- after do
12
- Object.send(:remove_const, :CustomEncode)
13
- end
14
-
15
- describe 'find' do
16
- subject { ActiveEncode::EncodeRecord.find_by(global_id: encode.to_global_id.to_s) }
17
- let(:encode) { CustomEncode.create(nil) }
18
-
19
- it 'persists changes on find' do
20
- expect { CustomEncode.find(encode.id) }.to change { subject.reload.updated_at }
21
- end
22
- end
23
-
24
- describe 'create' do
25
- subject { ActiveEncode::EncodeRecord.find_by(global_id: encode.to_global_id.to_s) }
26
- let(:create_options) { { option: 'value' } }
27
- let(:encode) { CustomEncode.create(nil, create_options) }
28
-
29
- it 'creates a record' do
30
- expect { encode }.to change { ActiveEncode::EncodeRecord.count }.by(1)
31
- end
32
-
33
- it { expect(subject.global_id).to eq encode.to_global_id.to_s }
34
- it { expect(subject.state).to eq encode.state.to_s }
35
- it { expect(subject.adapter).to eq encode.class.engine_adapter.class.name }
36
- it { expect(subject.title).to eq encode.input.url.to_s }
37
- it { expect(subject.raw_object).to eq encode.to_json }
38
- it { expect(subject.created_at).to be_within(1.second).of encode.created_at }
39
- it { expect(subject.updated_at).to be_within(1.second).of encode.updated_at }
40
- it { expect(subject.create_options).to eq create_options.to_json }
41
- it { expect(subject.progress).to eq encode.percent_complete }
42
- end
43
-
44
- describe 'cancel' do
45
- subject { ActiveEncode::EncodeRecord.find_by(global_id: encode.to_global_id.to_s) }
46
- let(:encode) { CustomEncode.create(nil) }
47
-
48
- it 'persists changes on cancel' do
49
- expect { encode.cancel! }.to change { subject.reload.state }.from("running").to("cancelled")
50
- end
51
- end
52
-
53
- describe 'reload' do
54
- subject { ActiveEncode::EncodeRecord.find_by(global_id: encode.to_global_id.to_s) }
55
- let(:encode) { CustomEncode.create(nil) }
56
-
57
- it 'persists changes on reload' do
58
- expect { encode.reload }.to change { subject.reload.updated_at }
59
- end
60
- end
61
- end
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'rails_helper'
3
-
4
- describe ActiveEncode::PollingJob do
5
- include ActiveJob::TestHelper
6
-
7
- before do
8
- class PollingEncode < ActiveEncode::Base
9
- include ActiveEncode::Polling
10
- after_status_update ->(encode) { encode.history << "PollingEncode ran after_status_update" }
11
- after_failed ->(encode) { encode.history << "PollingEncode ran after_failed" }
12
- after_cancelled ->(encode) { encode.history << "PollingEncode ran after_cancelled" }
13
- after_completed ->(encode) { encode.history << "PollingEncode ran after_completed" }
14
-
15
- def history
16
- @history ||= []
17
- end
18
- end
19
- end
20
-
21
- after do
22
- Object.send(:remove_const, :PollingEncode)
23
- end
24
-
25
- describe '#perform' do
26
- subject { encode.history }
27
- let(:encode) { PollingEncode.create("sample.mp4").tap { |encode| encode.state = state } }
28
- let(:poll) { described_class.new }
29
-
30
- before do
31
- encode
32
- clear_enqueued_jobs
33
- poll.perform(encode)
34
- end
35
-
36
- context "with job failed" do
37
- let(:state) { :failed }
38
-
39
- it "runs after_failed" do
40
- is_expected.to include("PollingEncode ran after_status_update")
41
- is_expected.to include("PollingEncode ran after_failed")
42
- end
43
-
44
- it "does not re-enqueue itself" do
45
- expect(described_class).not_to have_been_enqueued
46
- end
47
- end
48
-
49
- context "with job cancelled" do
50
- let(:state) { :cancelled }
51
-
52
- it "runs after_cancelled" do
53
- is_expected.to include("PollingEncode ran after_status_update")
54
- is_expected.to include("PollingEncode ran after_cancelled")
55
- end
56
-
57
- it "does not re-enqueue itself" do
58
- expect(described_class).not_to have_been_enqueued
59
- end
60
- end
61
-
62
- context "with job completed" do
63
- let(:state) { :completed }
64
-
65
- it "runs after_completed" do
66
- is_expected.to include("PollingEncode ran after_status_update")
67
- is_expected.to include("PollingEncode ran after_completed")
68
- end
69
-
70
- it "does not re-enqueue itself" do
71
- expect(described_class).not_to have_been_enqueued
72
- end
73
- end
74
-
75
- context "with job running" do
76
- let(:state) { :running }
77
-
78
- it "runs after_status_update" do
79
- is_expected.to include("PollingEncode ran after_status_update")
80
- end
81
-
82
- it "re-enqueues itself" do
83
- expect(described_class).to have_been_enqueued.with(encode)
84
- end
85
- end
86
- end
87
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'rails_helper'
3
-
4
- describe ActiveEncode::Polling do
5
- before do
6
- class PollingEncode < ActiveEncode::Base
7
- include ActiveEncode::Polling
8
- end
9
- end
10
-
11
- after do
12
- Object.send(:remove_const, :PollingEncode)
13
- end
14
-
15
- describe 'after_create' do
16
- subject { PollingEncode.create("sample.mp4") }
17
-
18
- it "enqueues a PollingJob" do
19
- subject
20
- expect(ActiveEncode::PollingJob).to have_been_enqueued.with(subject)
21
- end
22
- end
23
- end