Skip to content

Commit

Permalink
Merge 29854c1 into ecbb2f9
Browse files Browse the repository at this point in the history
  • Loading branch information
ndushay committed Apr 15, 2020
2 parents ecbb2f9 + 29854c1 commit c663f14
Show file tree
Hide file tree
Showing 42 changed files with 285 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ RSpec/MessageSpies:

RSpec/MultipleExpectations:
Max: 5
Exclude:
- 'spec/features/*'

RSpec/NestedGroups:
Max: 4 # default: 3
Expand Down
13 changes: 3 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-04-14 22:15:21 -0500 using RuboCop version 0.76.0.
# on 2020-04-14 22:38:01 -0700 using RuboCop version 0.76.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 9
# Offense count: 10
Metrics/AbcSize:
Max: 71


# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 183
Max: 155

# Offense count: 4
Metrics/CyclomaticComplexity:
Expand Down Expand Up @@ -42,12 +41,6 @@ RSpec/BeforeAfterAll:
- 'spec/support/**/*.rb'
- 'spec/lib/pre_assembly/digital_object_spec.rb'

# Offense count: 2
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/lib/pre_assembly/batch_spec.rb'

# Offense count: 32
RSpec/SubjectStub:
Exclude:
Expand Down
8 changes: 5 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ gem 'dor-workflow-client'
gem 'druid-tools'

group :test do
gem 'capybara'
gem 'coveralls', require: false
gem 'equivalent-xml'
gem 'factory_bot_rails'
gem 'rails-controller-testing'
gem 'random-word'
gem 'rspec-rails', '~> 4.0'
gem 'shoulda-matchers', '~> 4.1'
end

Expand All @@ -50,10 +54,8 @@ end

group :development, :test do
gem 'pry-byebug'
gem 'rspec-rails', '~> 4.0.0.rc1'
gem 'rails-controller-testing'
gem 'rubocop', '~> 0.76.0'
gem 'rubocop-rspec'
gem 'ruby-prof'
# gem 'ruby-prof'
gem 'sqlite3'
end
21 changes: 18 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ GEM
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
airbrussh (1.4.0)
sshkit (>= 1.6.1, != 1.7.0)
assembly-image (1.7.7)
Expand Down Expand Up @@ -103,6 +105,14 @@ GEM
capistrano
resque-pool
capistrano-shared_configs (0.2.2)
capybara (3.32.1)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.5)
xpath (~> 3.2)
cocina-models (0.31.1)
activesupport
dry-struct (~> 1.0)
Expand Down Expand Up @@ -299,6 +309,7 @@ GEM
pry-rails (0.3.9)
pry (>= 0.10.4)
psych (3.1.0)
public_suffix (4.0.4)
rack (2.2.2)
rack-protection (2.0.8.1)
rack
Expand Down Expand Up @@ -336,12 +347,14 @@ GEM
thor (>= 0.20.3, < 2.0)
rainbow (3.0.0)
rake (13.0.1)
random-word (2.1.1)
rb-fsevent (0.10.3)
rb-inotify (0.10.1)
ffi (~> 1.0)
redis (4.1.3)
redis-namespace (1.7.0)
redis (>= 3.0.4)
regexp_parser (1.7.0)
responders (3.0.0)
actionpack (>= 5.0)
railties (>= 5.0)
Expand Down Expand Up @@ -383,7 +396,6 @@ GEM
rubocop (>= 0.68.1)
ruby-enum (0.8.0)
i18n
ruby-prof (1.3.1)
ruby-progressbar (1.10.1)
ruby2_keywords (0.0.2)
sassc (2.0.1)
Expand Down Expand Up @@ -444,6 +456,8 @@ GEM
websocket-driver (0.7.1)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.4)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.3.0)

PLATFORMS
Expand All @@ -457,6 +471,7 @@ DEPENDENCIES
capistrano-passenger
capistrano-rails
capistrano-resque-pool
capybara
config
coveralls
devise
Expand All @@ -480,13 +495,13 @@ DEPENDENCIES
rails (~> 6.0)
rails-controller-testing
rake
random-word
resque (~> 2.0)
resque-lock
resque-pool
rspec-rails (~> 4.0.0.rc1)
rspec-rails (~> 4.0)
rubocop (~> 0.76.0)
rubocop-rspec
ruby-prof
sassc (~> 2.0.1)
shoulda-matchers (~> 4.1)
simple_form
Expand Down
File renamed without changes.
102 changes: 102 additions & 0 deletions spec/features/create_media_audio_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# frozen_string_literal: true

RSpec.describe 'Create Media Audio object', type: :feature do
let(:user) { create(:user) }
let(:user_id) { "#{user.sunet_id}@stanford.edu" }
let(:project_name) { "media-audio-objects-#{RandomWord.nouns.next}" }
let(:bundle_dir) { Rails.root.join('spec/test_data/media_audio_test') }
let(:bare_druid) { 'sn000dd0000' }
let(:object_staging_dir) { Rails.root.join(Settings.assembly_staging_dir, 'sn', '000', 'dd', '0000', bare_druid) }
let(:cocina_model_world_access) { instance_double(Cocina::Models::Access, access: 'world') }
let(:item) { instance_double(Cocina::Models::DRO, type: Cocina::Models::Vocab.media, access: cocina_model_world_access) }
let(:dsc_object_version) { instance_double(Dor::Services::Client::ObjectVersion, openable?: true) }
let(:dsc_object) { instance_double(Dor::Services::Client::Object, version: dsc_object_version, find: item) }
let(:exp_content_md) do
<<~XML
<contentMetadata objectId="sn000dd0000" type="media">
<resource sequence="1" id="sn000dd0000_1" type="audio">
<label>Audio file 1</label>
<file id="sn000dd0000_audio_a_m4a.m4a" preserve="yes" publish="no" shelve="no">
<checksum type="md5">53b1e299e0277978f0d3f131b9a65a76</checksum>
</file>
<file id="sn000dd0000_audio_a_mp3.mp3" preserve="yes" publish="yes" shelve="yes">
<checksum type="md5">3675d9ff3dea18a17986b0776f74a218</checksum>
</file>
<file id="sn000dd0000_audio_a_wav.wav" preserve="yes" publish="no" shelve="no">
<checksum type="md5">224646acbdfb7063c902bbd257460fcf</checksum>
</file>
</resource>
<resource sequence="2" id="sn000dd0000_2" type="image">
<label>Image for audio</label>
<file id="sn000dd0000_audio_img_1.jpg" preserve="yes" publish="yes" shelve="yes">
<checksum type="md5">3e9498107f73ff827e718d5c743f8813</checksum>
</file>
<file id="sn000dd0000_audio_img_1.tif" preserve="yes" publish="no" shelve="no">
<checksum type="md5">4fe3ad7bf975326ff1c1271e8f743ceb</checksum>
</file>
</resource>
<resource sequence="3" id="sn000dd0000_3" type="text">
<label>Transcript</label>
<file id="sn000dd0000_audio_pdf.pdf" preserve="yes" publish="yes" shelve="yes">
<checksum type="md5">f7169731f4c163f98eed35e1be12a209</checksum>
</file>
</resource>
</contentMetadata>
XML
end

before do
FileUtils.remove_dir(object_staging_dir) if Dir.exist?(object_staging_dir)

login_as(user, scope: :user)

allow(Dor::Services::Client).to receive(:object).and_return(dsc_object)
allow(StartAccession).to receive(:run).with(druid: "druid:#{bare_druid}", user: user.sunet_id)
end

# have background jobs run synchronously
include ActiveJob::TestHelper
around do |example|
perform_enqueued_jobs do
example.run
end
end

it do
visit '/'
expect(page).to have_selector('h3', text: 'Complete the form below')

fill_in 'Project name', with: project_name
select 'Pre Assembly Run', from: 'Job type'
select 'Media', from: 'Content structure'
fill_in 'Bundle dir', with: bundle_dir
select 'Media', from: 'Content metadata creation'

click_button 'Submit'
exp_str = 'Success! Your job is queued. A link to job output will be emailed to you upon completion.'
expect(page).to have_content exp_str

# go to job details page, download result when finished
first('td > a').click
expect(page).to have_content project_name
# p project_name # useful for debugging

# wait for preassembly to finish
expect(page).to have_link('Download')

result_file = Rails.root.join(Settings.job_output_parent_dir, user_id, project_name, "#{project_name}_progress.yml")
yaml = YAML.load_file(result_file)
expect(yaml[:status]).to eq 'success'

# we got all the expected content files
expect(Dir.children(File.join(object_staging_dir, 'content')).size).to eq 12

metadata_dir = File.join(object_staging_dir, 'metadata')
expect(Dir.children(metadata_dir).size).to eq 2

content_md_xml = File.open(File.join(metadata_dir, 'contentMetadata.xml')).read
expect(noko_doc(content_md_xml)).to be_equivalent_to exp_content_md

# note that technicalMetadata.xml is created, but we don't care about it anymore due to new technical-metadata-service
end
end
117 changes: 117 additions & 0 deletions spec/features/create_media_video_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# frozen_string_literal: true

RSpec.describe 'Create Media Video object', type: :feature do
let(:user) { create(:user) }
let(:user_id) { "#{user.sunet_id}@stanford.edu" }
let(:project_name) { "media-video-objects-#{RandomWord.nouns.next}" }
let(:bundle_dir) { Rails.root.join('spec/test_data/media_video_test') }
let(:bare_druid) { 'vd000bj0000' }
let(:object_staging_dir) { Rails.root.join(Settings.assembly_staging_dir, 'vd', '000', 'bj', '0000', bare_druid) }
let(:cocina_model_world_access) { instance_double(Cocina::Models::Access, access: 'world') }
let(:item) { instance_double(Cocina::Models::DRO, type: Cocina::Models::Vocab.media, access: cocina_model_world_access) }
let(:dsc_object_version) { instance_double(Dor::Services::Client::ObjectVersion, openable?: true) }
let(:dsc_object) { instance_double(Dor::Services::Client::Object, version: dsc_object_version, find: item) }
let(:exp_content_md) do
<<~XML
<contentMetadata objectId="vd000bj0000" type="media">
<resource sequence="1" id="vd000bj0000_1" type="video">
<label>Video file 1</label>
<file id="vd000bj0000_video_1.mp4" preserve="yes" publish="yes" shelve="yes">
<checksum type="md5">ee4e90be549c5614ac6282a5b80a506b</checksum>
</file>
<file id="vd000bj0000_video_1.mpeg" preserve="yes" publish="no" shelve="no">
<checksum type="md5">bed85c6ffc2f8070599a7fb682852f30</checksum>
</file>
<file id="vd000bj0000_video_1_thumb.jp2" preserve="yes" publish="yes" shelve="yes">
<checksum type="md5">4b0e92aec76da9ac98567b8e6848e922</checksum>
</file>
</resource>
<resource sequence="2" id="vd000bj0000_2" type="video">
<label>Video file 2</label>
<file id="vd000bj0000_video_2.mp4" preserve="yes" publish="yes" shelve="yes">
<checksum type="md5">ee4e90be549c5614ac6282a5b80a506b</checksum>
</file>
<file id="vd000bj0000_video_2.mpeg" preserve="yes" publish="no" shelve="no">
<checksum type="md5">bed85c6ffc2f8070599a7fb682852f30</checksum>
</file>
<file id="vd000bj0000_video_2_thumb.jp2" preserve="yes" publish="yes" shelve="yes">
<checksum type="md5">4b0e92aec76da9ac98567b8e6848e922</checksum>
</file>
</resource>
<resource sequence="3" id="vd000bj0000_3" type="image">
<label>Image of media (1 of 2)</label>
<file id="vd000bj0000_video_img_1.tif" preserve="yes" publish="no" shelve="no">
<checksum type="md5">4fe3ad7bf975326ff1c1271e8f743ceb</checksum>
</file>
</resource>
<resource sequence="4" id="vd000bj0000_4" type="image">
<label>Image of media (2 of 2)</label>
<file id="vd000bj0000_video_img_2.tif" preserve="yes" publish="no" shelve="no">
<checksum type="md5">4fe3ad7bf975326ff1c1271e8f743ceb</checksum>
</file>
</resource>
<resource sequence="5" id="vd000bj0000_5" type="file">
<label>Disc log file</label>
<file id="vd000bj0000_video_log.txt" preserve="yes" publish="no" shelve="no">
<checksum type="md5">b659a852e4f0faa2f1d83973446a4ee9</checksum>
</file>
</resource>
</contentMetadata>
XML
end

before do
FileUtils.remove_dir(object_staging_dir) if Dir.exist?(object_staging_dir)

login_as(user, scope: :user)

allow(Dor::Services::Client).to receive(:object).and_return(dsc_object)
allow(StartAccession).to receive(:run).with(druid: "druid:#{bare_druid}", user: user.sunet_id)
end

# have background jobs run synchronously
include ActiveJob::TestHelper
around do |example|
perform_enqueued_jobs do
example.run
end
end

it do
visit '/'
expect(page).to have_selector('h3', text: 'Complete the form below')

fill_in 'Project name', with: project_name
select 'Pre Assembly Run', from: 'Job type'
select 'Media', from: 'Content structure'
fill_in 'Bundle dir', with: bundle_dir
select 'Media', from: 'Content metadata creation'

click_button 'Submit'
exp_str = 'Success! Your job is queued. A link to job output will be emailed to you upon completion.'
expect(page).to have_content exp_str

# go to job details page, download result when finished
first('td > a').click
expect(page).to have_content project_name
# p project_name # useful for debugging

# wait for preassembly to finish
expect(page).to have_link('Download')

result_file = Rails.root.join(Settings.job_output_parent_dir, user_id, project_name, "#{project_name}_progress.yml")
yaml = YAML.load_file(result_file)
expect(yaml[:status]).to eq 'success'

# we got all the expected content files
expect(Dir.children(File.join(object_staging_dir, 'content')).size).to eq 18

metadata_dir = File.join(object_staging_dir, 'metadata')
expect(Dir.children(metadata_dir).size).to eq 2

content_md_xml = File.open(File.join(metadata_dir, 'contentMetadata.xml')).read
expect(noko_doc(content_md_xml)).to be_equivalent_to exp_content_md

# note that technicalMetadata.xml is created, but we don't care about it anymore due to new technical-metadata-service
end
end
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
config.include Devise::Test::IntegrationHelpers, type: :feature

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
Expand Down
2 changes: 2 additions & 0 deletions spec/test_data/media_audio_test/manifest.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
druid,object
sn000dd0000,sn000dd0000
7 changes: 7 additions & 0 deletions spec/test_data/media_audio_test/media_manifest.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source_id,filename,label,sequence,publish,preserve,shelve,resource_type
,sn000dd0000_audio_a_m4a.m4a,Audio file 1,1,no,yes,no,audio
,sn000dd0000_audio_a_mp3.mp3,Audio file 1,1,yes,yes,yes,audio
,sn000dd0000_audio_a_wav.wav,Audio file 1,1,no,yes,no,audio
,sn000dd0000_audio_img_1.jpg,Image for audio,2,yes,yes,yes,image
,sn000dd0000_audio_img_1.tif,Image for audio,2,no,yes,no,image
,sn000dd0000_audio_pdf.pdf,Transcript,3,yes,yes,yes,text
Binary file not shown.

0 comments on commit c663f14

Please sign in to comment.