active_encode 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +72 -0
  3. data/.rubocop.yml +8 -70
  4. data/.rubocop_todo.yml +64 -0
  5. data/Gemfile +3 -3
  6. data/active_encode.gemspec +4 -1
  7. data/app/controllers/active_encode/encode_record_controller.rb +1 -0
  8. data/app/jobs/active_encode/polling_job.rb +1 -1
  9. data/app/models/active_encode/encode_record.rb +1 -0
  10. data/db/migrate/20180822021048_create_active_encode_encode_records.rb +1 -0
  11. data/db/migrate/20190702153755_add_create_options_to_active_encode_encode_records.rb +6 -0
  12. data/db/migrate/20190712174821_add_progress_to_active_encode_encode_records.rb +6 -0
  13. data/lib/active_encode.rb +1 -0
  14. data/lib/active_encode/base.rb +1 -0
  15. data/lib/active_encode/callbacks.rb +1 -0
  16. data/lib/active_encode/core.rb +4 -3
  17. data/lib/active_encode/engine.rb +1 -0
  18. data/lib/active_encode/engine_adapter.rb +1 -0
  19. data/lib/active_encode/engine_adapters.rb +2 -1
  20. data/lib/active_encode/engine_adapters/elastic_transcoder_adapter.rb +25 -24
  21. data/lib/active_encode/engine_adapters/ffmpeg_adapter.rb +43 -58
  22. data/lib/active_encode/engine_adapters/matterhorn_adapter.rb +5 -4
  23. data/lib/active_encode/engine_adapters/test_adapter.rb +5 -4
  24. data/lib/active_encode/engine_adapters/zencoder_adapter.rb +3 -2
  25. data/lib/active_encode/global_id.rb +2 -1
  26. data/lib/active_encode/input.rb +3 -2
  27. data/lib/active_encode/output.rb +3 -2
  28. data/lib/active_encode/persistence.rb +7 -3
  29. data/lib/active_encode/polling.rb +2 -1
  30. data/lib/active_encode/status.rb +1 -0
  31. data/lib/active_encode/technical_metadata.rb +3 -2
  32. data/lib/active_encode/version.rb +2 -1
  33. data/lib/file_locator.rb +7 -8
  34. data/spec/controllers/encode_record_controller_spec.rb +2 -1
  35. data/spec/integration/elastic_transcoder_adapter_spec.rb +26 -26
  36. data/spec/integration/ffmpeg_adapter_spec.rb +26 -22
  37. data/spec/integration/matterhorn_adapter_spec.rb +6 -5
  38. data/spec/integration/zencoder_adapter_spec.rb +15 -14
  39. data/spec/rails_helper.rb +1 -0
  40. data/spec/routing/encode_record_controller_routing_spec.rb +1 -0
  41. data/spec/shared_specs/engine_adapter_specs.rb +1 -1
  42. data/spec/spec_helper.rb +2 -1
  43. data/spec/test_app_templates/lib/generators/test_app_generator.rb +13 -12
  44. data/spec/units/callbacks_spec.rb +3 -2
  45. data/spec/units/core_spec.rb +9 -8
  46. data/spec/units/engine_adapter_spec.rb +1 -0
  47. data/spec/units/file_locator_spec.rb +19 -18
  48. data/spec/units/global_id_spec.rb +4 -3
  49. data/spec/units/input_spec.rb +8 -5
  50. data/spec/units/output_spec.rb +8 -5
  51. data/spec/units/persistence_spec.rb +8 -4
  52. data/spec/units/polling_job_spec.rb +7 -6
  53. data/spec/units/polling_spec.rb +1 -0
  54. data/spec/units/status_spec.rb +3 -3
  55. metadata +37 -7
  56. data/.travis.yml +0 -19
@@ -130,7 +130,7 @@ RSpec.shared_examples 'an ActiveEncode::EngineAdapter' do |*_flags|
130
130
 
131
131
  it 'output has technical metadata' do
132
132
  subject.output.each do |output|
133
- expected_output = completed_output.find {|expected_out| expected_out[:id] == output.id }
133
+ expected_output = completed_output.find { |expected_out| expected_out[:id] == output.id }
134
134
  expect(output.as_json.symbolize_keys).to include expected_output
135
135
  end
136
136
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'coveralls'
2
3
  Coveralls.wear!
3
4
 
@@ -13,6 +14,6 @@ end
13
14
 
14
15
  RSpec::Matchers.define :be_the_same_time_as do |expected|
15
16
  match do |actual|
16
- expect(Time.parse(expected)).to eq(Time.parse(actual))
17
+ expect(Time.parse(expected).utc).to eq(Time.parse(actual).utc)
17
18
  end
18
19
  end
@@ -1,15 +1,16 @@
1
- require 'rails/generators'
1
+ # frozen_string_literal: true
2
+ # frozen_string_literal: true
3
+ require 'rails/generators'
2
4
 
3
- class TestAppGenerator < Rails::Generators::Base
4
- source_root "./spec/test_app_templates"
5
+ class TestAppGenerator < Rails::Generators::Base
6
+ source_root "./spec/test_app_templates"
5
7
 
6
- # if you need to generate any additional configuration
7
- # into the test app, this generator will be run immediately
8
- # after setting up the application
9
-
10
- def install_engine
11
- generate 'active_encode:install'
12
- rake 'active_encode:install:migrations'
13
- end
14
- end
8
+ # if you need to generate any additional configuration
9
+ # into the test app, this generator will be run immediately
10
+ # after setting up the application
15
11
 
12
+ def install_engine
13
+ generate 'active_encode:install'
14
+ rake 'active_encode:install:migrations'
15
+ end
16
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  describe ActiveEncode::Callbacks do
@@ -36,14 +37,14 @@ describe ActiveEncode::Callbacks do
36
37
  end
37
38
 
38
39
  describe 'find callback' do
39
- let(:encode) { CallbackEncode.create("sample.mp4") }
40
40
  subject { CallbackEncode.find(encode.id).history }
41
+ let(:encode) { CallbackEncode.create("sample.mp4") }
41
42
  it { is_expected.to include("CallbackEncode ran after_find") }
42
43
  end
43
44
 
44
45
  describe 'reload callback' do
45
- let(:encode) { CallbackEncode.create("sample.mp4") }
46
46
  subject { encode.reload.history }
47
+ let(:encode) { CallbackEncode.create("sample.mp4") }
47
48
  it { is_expected.to include("CallbackEncode ran after_reload") }
48
49
  end
49
50
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  describe ActiveEncode::Core do
@@ -5,7 +6,7 @@ describe ActiveEncode::Core do
5
6
  class CustomEncode < ActiveEncode::Base
6
7
  end
7
8
  end
8
- after do
9
+ after do
9
10
  Object.send(:remove_const, :CustomEncode)
10
11
  end
11
12
 
@@ -24,8 +25,8 @@ describe ActiveEncode::Core do
24
25
  end
25
26
 
26
27
  describe 'find' do
27
- let(:id) { encode_class.create(nil).id }
28
28
  subject { encode_class.find(id) }
29
+ let(:id) { encode_class.create(nil).id }
29
30
 
30
31
  it { is_expected.to be_a encode_class }
31
32
  its(:id) { is_expected.to eq id }
@@ -70,8 +71,8 @@ describe ActiveEncode::Core do
70
71
  end
71
72
 
72
73
  describe '#create!' do
73
- let(:encode) { encode_class.new(nil) }
74
74
  subject { encode.create! }
75
+ let(:encode) { encode_class.new(nil) }
75
76
 
76
77
  it { is_expected.to equal encode }
77
78
  it { is_expected.to be_a encode_class }
@@ -89,8 +90,8 @@ describe ActiveEncode::Core do
89
90
  end
90
91
 
91
92
  describe '#cancel!' do
92
- let(:encode) { encode_class.create(nil) }
93
93
  subject { encode.cancel! }
94
+ let(:encode) { encode_class.create(nil) }
94
95
 
95
96
  it { is_expected.to equal encode }
96
97
  it { is_expected.to be_a encode_class }
@@ -108,8 +109,8 @@ describe ActiveEncode::Core do
108
109
  end
109
110
 
110
111
  describe '#reload' do
111
- let(:encode) { encode_class.create(nil) }
112
112
  subject { encode.reload }
113
+ let(:encode) { encode_class.create(nil) }
113
114
 
114
115
  it { is_expected.to equal encode }
115
116
  it { is_expected.to be_a encode_class }
@@ -134,15 +135,15 @@ describe ActiveEncode::Core do
134
135
  end
135
136
  end
136
137
  end
137
- after do
138
+ after do
138
139
  Object.send(:remove_const, :DefaultOptionsEncode)
139
140
  end
140
141
 
142
+ subject { encode.options }
141
143
  let(:encode_class) { DefaultOptionsEncode }
142
144
  let(:default_options) { { preset: 'video' } }
143
- let(:options) { { output: [{label: 'high', ffmpeg_opt: "640x480" }] } }
145
+ let(:options) { { output: [{ label: 'high', ffmpeg_opt: "640x480" }] } }
144
146
  let(:encode) { encode_class.new(nil, options) }
145
- subject { encode.options }
146
147
 
147
148
  it 'merges default options and options parameter' do
148
149
  expect(subject).to include default_options
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  describe ActiveEncode::EngineAdapter do
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright 2011-2018, The Trustees of Indiana University and Northwestern
2
3
  # University. Licensed under the Apache License, Version 2.0 (the "License");
3
4
  # you may not use this file except in compliance with the License.
@@ -24,12 +25,12 @@ describe FileLocator, type: :service do
24
25
  let(:key) { "mykey.mp4" }
25
26
  let(:s3file) { FileLocator::S3File.new("s3://#{bucket}/#{key}") }
26
27
 
27
- it "should be able to initialize from an S3 URI" do
28
+ it "is able to initialize from an S3 URI" do
28
29
  expect(s3file.bucket).to eq bucket
29
30
  expect(s3file.key).to eq key
30
31
  end
31
32
 
32
- it "should return an S3 Object" do
33
+ it "returns an S3 Object" do
33
34
  s3_object = s3file.object
34
35
  expect(s3_object).to be_an Aws::S3::Object
35
36
  expect(s3_object.bucket_name).to eq bucket
@@ -42,30 +43,30 @@ describe FileLocator, type: :service do
42
43
  let(:source) { "file://#{path}" }
43
44
  let(:locator) { FileLocator.new(source) }
44
45
 
45
- it "should return the correct uri" do
46
+ it "returns the correct uri" do
46
47
  expect(locator.uri).to eq Addressable::URI.parse(source)
47
48
  end
48
49
 
49
- it "should return the correct location" do
50
+ it "returns the correct location" do
50
51
  expect(locator.location).to eq path
51
52
  end
52
53
 
53
- it "should tell if file exists" do
54
+ it "tells if file exists" do
54
55
  allow(File).to receive(:exist?).with(path) { true }
55
56
  expect(locator.exist?).to be_truthy
56
57
  end
57
58
 
58
59
  context "return file" do
59
60
  let(:file) { double(File) }
60
- before :each do
61
+ before do
61
62
  allow(File).to receive(:open).and_return file
62
63
  end
63
64
 
64
- it "should return reader" do
65
+ it "returns reader" do
65
66
  expect(locator.reader).to eq file
66
67
  end
67
68
 
68
- it "should return attachment" do
69
+ it "returns attachment" do
69
70
  expect(locator.attachment).to eq file
70
71
  end
71
72
  end
@@ -77,23 +78,23 @@ describe FileLocator, type: :service do
77
78
  let(:source) { "s3://#{bucket}/#{key}" }
78
79
  let(:locator) { FileLocator.new(source) }
79
80
 
80
- it "should return the correct uri" do
81
+ it "returns the correct uri" do
81
82
  expect(locator.uri).to eq Addressable::URI.parse(source)
82
83
  end
83
84
 
84
- it "should return the correct location" do
85
+ it "returns the correct location" do
85
86
  expect(locator.location).to start_with "https://#{bucket}.s3.us-stubbed-1.amazonaws.com/#{key}"
86
87
  end
87
88
 
88
- it "should tell if file exists" do
89
+ it "tells if file exists" do
89
90
  expect(locator.exist?).to be_truthy
90
91
  end
91
92
 
92
- it "should return reader" do
93
+ it "returns reader" do
93
94
  expect(locator.reader).to be_a StringIO
94
95
  end
95
96
 
96
- it "should return attachment" do
97
+ it "returns attachment" do
97
98
  expect(locator.attachment).to eq Addressable::URI.parse(source)
98
99
  end
99
100
  end
@@ -103,25 +104,25 @@ describe FileLocator, type: :service do
103
104
  let(:source) { "bogus://#{path}" }
104
105
  let(:locator) { FileLocator.new(source) }
105
106
 
106
- it "should return the correct uri" do
107
+ it "returns the correct uri" do
107
108
  expect(locator.uri).to eq Addressable::URI.parse(source)
108
109
  end
109
110
 
110
- it "should return the correct location" do
111
+ it "returns the correct location" do
111
112
  expect(locator.location).to eq source
112
113
  end
113
114
 
114
- it "should tell if file exists" do
115
+ it "tells if file exists" do
115
116
  expect(locator.exist?).to be_falsy
116
117
  end
117
118
 
118
- it "should return reader" do
119
+ it "returns reader" do
119
120
  io = double(IO)
120
121
  allow(Kernel).to receive(:open).and_return io
121
122
  expect(locator.reader).to eq io
122
123
  end
123
124
 
124
- it "should return attachment" do
125
+ it "returns attachment" do
125
126
  expect(locator.attachment).to eq locator.location
126
127
  end
127
128
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  describe ActiveEncode::GlobalID do
@@ -11,9 +12,9 @@ describe ActiveEncode::GlobalID do
11
12
  end
12
13
 
13
14
  describe '#to_global_id' do
15
+ subject { encode.to_global_id }
14
16
  let(:encode_class) { ActiveEncode::Base }
15
17
  let(:encode) { encode_class.create(nil) }
16
- subject { encode.to_global_id }
17
18
 
18
19
  it { is_expected.to be_a GlobalID }
19
20
  its(:model_class) { is_expected.to eq encode_class }
@@ -31,17 +32,17 @@ describe ActiveEncode::GlobalID do
31
32
  end
32
33
 
33
34
  describe 'GlobalID::Locator#locate' do
35
+ subject { GlobalID::Locator.locate(global_id) }
34
36
  let(:encode_class) { ActiveEncode::Base }
35
37
  let(:encode) { encode_class.create(nil) }
36
38
  let(:global_id) { encode.to_global_id }
37
- subject { GlobalID::Locator.locate(global_id) }
38
39
 
39
40
  it { is_expected.to be_a encode_class }
40
41
  its(:id) { is_expected.to eq encode.id }
41
42
 
42
43
  context 'with an ActiveEncode::Base subclass' do
43
44
  let(:encode_class) { CustomEncode }
44
-
45
+
45
46
  it { is_expected.to be_a encode_class }
46
47
  its(:id) { is_expected.to eq encode.id }
47
48
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  describe ActiveEncode::Input do
@@ -6,8 +7,10 @@ describe ActiveEncode::Input do
6
7
  describe 'attributes' do
7
8
  it { is_expected.to respond_to(:id, :url) }
8
9
  it { is_expected.to respond_to(:state, :errors, :created_at, :updated_at) }
9
- it { is_expected.to respond_to(:width, :height, :frame_rate, :checksum,
10
- :audio_codec, :video_codec, :audio_bitrate, :video_bitrate) }
10
+ it {
11
+ is_expected.to respond_to(:width, :height, :frame_rate, :checksum,
12
+ :audio_codec, :video_codec, :audio_bitrate, :video_bitrate)
13
+ }
11
14
  end
12
15
 
13
16
  describe '#valid?' do
@@ -15,8 +18,8 @@ describe ActiveEncode::Input do
15
18
  described_class.new.tap do |obj|
16
19
  obj.id = "1"
17
20
  obj.url = "file:///tmp/video.mp4"
18
- obj.created_at = Time.now
19
- obj.updated_at = Time.now
21
+ obj.created_at = Time.now.utc
22
+ obj.updated_at = Time.now.utc
20
23
  end
21
24
  end
22
25
 
@@ -31,7 +34,7 @@ describe ActiveEncode::Input do
31
34
  expect(valid_input.tap { |obj| obj.created_at = "today" }).not_to be_valid
32
35
  expect(valid_input.tap { |obj| obj.updated_at = nil }).not_to be_valid
33
36
  expect(valid_input.tap { |obj| obj.updated_at = "today" }).not_to be_valid
34
- expect(valid_input.tap { |obj| obj.created_at = Time.now }).not_to be_valid
37
+ expect(valid_input.tap { |obj| obj.created_at = Time.now.utc }).not_to be_valid
35
38
  end
36
39
  end
37
40
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  describe ActiveEncode::Output do
@@ -6,8 +7,10 @@ describe ActiveEncode::Output do
6
7
  describe 'attributes' do
7
8
  it { is_expected.to respond_to(:id, :url, :label) }
8
9
  it { is_expected.to respond_to(:state, :errors, :created_at, :updated_at) }
9
- it { is_expected.to respond_to(:width, :height, :frame_rate, :checksum,
10
- :audio_codec, :video_codec, :audio_bitrate, :video_bitrate) }
10
+ it {
11
+ is_expected.to respond_to(:width, :height, :frame_rate, :checksum,
12
+ :audio_codec, :video_codec, :audio_bitrate, :video_bitrate)
13
+ }
11
14
  end
12
15
 
13
16
  describe '#valid?' do
@@ -16,8 +19,8 @@ describe ActiveEncode::Output do
16
19
  obj.id = "1"
17
20
  obj.url = "file:///tmp/video.mp4"
18
21
  obj.label = "HD"
19
- obj.created_at = Time.now
20
- obj.updated_at = Time.now
22
+ obj.created_at = Time.now.utc
23
+ obj.updated_at = Time.now.utc
21
24
  end
22
25
  end
23
26
 
@@ -33,7 +36,7 @@ describe ActiveEncode::Output do
33
36
  expect(valid_output.tap { |obj| obj.created_at = "today" }).not_to be_valid
34
37
  expect(valid_output.tap { |obj| obj.updated_at = nil }).not_to be_valid
35
38
  expect(valid_output.tap { |obj| obj.updated_at = "today" }).not_to be_valid
36
- expect(valid_output.tap { |obj| obj.created_at = Time.now }).not_to be_valid
39
+ expect(valid_output.tap { |obj| obj.created_at = Time.now.utc }).not_to be_valid
37
40
  end
38
41
  end
39
42
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rails_helper'
2
3
 
3
4
  describe ActiveEncode::Persistence, db_clean: true do
@@ -12,8 +13,8 @@ describe ActiveEncode::Persistence, db_clean: true do
12
13
  end
13
14
 
14
15
  describe 'find' do
15
- let(:encode) { CustomEncode.create(nil) }
16
16
  subject { ActiveEncode::EncodeRecord.find_by(global_id: encode.to_global_id.to_s) }
17
+ let(:encode) { CustomEncode.create(nil) }
17
18
 
18
19
  it 'persists changes on find' do
19
20
  expect { CustomEncode.find(encode.id) }.to change { subject.reload.updated_at }
@@ -21,8 +22,9 @@ describe ActiveEncode::Persistence, db_clean: true do
21
22
  end
22
23
 
23
24
  describe 'create' do
24
- let(:encode) { CustomEncode.create(nil) }
25
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) }
26
28
 
27
29
  it 'creates a record' do
28
30
  expect { encode }.to change { ActiveEncode::EncodeRecord.count }.by(1)
@@ -35,11 +37,13 @@ describe ActiveEncode::Persistence, db_clean: true do
35
37
  its(:raw_object) { is_expected.to eq encode.to_json }
36
38
  its(:created_at) { is_expected.to be_within(1.second).of encode.created_at }
37
39
  its(:updated_at) { is_expected.to be_within(1.second).of encode.updated_at }
40
+ its(:create_options) { is_expected.to eq create_options.to_json }
41
+ its(:progress) { is_expected.to eq encode.percent_complete }
38
42
  end
39
43
 
40
44
  describe 'cancel' do
41
- let(:encode) { CustomEncode.create(nil) }
42
45
  subject { ActiveEncode::EncodeRecord.find_by(global_id: encode.to_global_id.to_s) }
46
+ let(:encode) { CustomEncode.create(nil) }
43
47
 
44
48
  it 'persists changes on cancel' do
45
49
  expect { encode.cancel! }.to change { subject.reload.state }.from("running").to("cancelled")
@@ -47,8 +51,8 @@ describe ActiveEncode::Persistence, db_clean: true do
47
51
  end
48
52
 
49
53
  describe 'reload' do
50
- let(:encode) { CustomEncode.create(nil) }
51
54
  subject { ActiveEncode::EncodeRecord.find_by(global_id: encode.to_global_id.to_s) }
55
+ let(:encode) { CustomEncode.create(nil) }
52
56
 
53
57
  it 'persists changes on reload' do
54
58
  expect { encode.reload }.to change { subject.reload.updated_at }
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rails_helper'
2
3
 
3
4
  describe ActiveEncode::PollingJob do
@@ -22,9 +23,9 @@ describe ActiveEncode::PollingJob do
22
23
  end
23
24
 
24
25
  describe '#perform' do
25
- let(:encode) { PollingEncode.create("sample.mp4").tap { |encode| encode.state = state } }
26
- let(:poll) { ActiveEncode::PollingJob.new }
27
26
  subject { encode.history }
27
+ let(:encode) { PollingEncode.create("sample.mp4").tap { |encode| encode.state = state } }
28
+ let(:poll) { described_class.new }
28
29
 
29
30
  before do
30
31
  encode
@@ -41,7 +42,7 @@ describe ActiveEncode::PollingJob do
41
42
  end
42
43
 
43
44
  it "does not re-enqueue itself" do
44
- expect(ActiveEncode::PollingJob).not_to have_been_enqueued
45
+ expect(described_class).not_to have_been_enqueued
45
46
  end
46
47
  end
47
48
 
@@ -54,7 +55,7 @@ describe ActiveEncode::PollingJob do
54
55
  end
55
56
 
56
57
  it "does not re-enqueue itself" do
57
- expect(ActiveEncode::PollingJob).not_to have_been_enqueued
58
+ expect(described_class).not_to have_been_enqueued
58
59
  end
59
60
  end
60
61
 
@@ -67,7 +68,7 @@ describe ActiveEncode::PollingJob do
67
68
  end
68
69
 
69
70
  it "does not re-enqueue itself" do
70
- expect(ActiveEncode::PollingJob).not_to have_been_enqueued
71
+ expect(described_class).not_to have_been_enqueued
71
72
  end
72
73
  end
73
74
 
@@ -79,7 +80,7 @@ describe ActiveEncode::PollingJob do
79
80
  end
80
81
 
81
82
  it "re-enqueues itself" do
82
- expect(ActiveEncode::PollingJob).to have_been_enqueued.with(encode)
83
+ expect(described_class).to have_been_enqueued.with(encode)
83
84
  end
84
85
  end
85
86
  end