Skip to content

Commit

Permalink
Merge pull request #193 from sul-dlss/bc_init
Browse files Browse the repository at this point in the history
BundleContext initialization has some requirements
  • Loading branch information
jmartin-sul committed Sep 7, 2018
2 parents 9d01936 + 37885c7 commit 5a1d5e8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
33 changes: 18 additions & 15 deletions app/lib/bundle_context_temporary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ class BundleUsageError < StandardError
class BundleContextTemporary
# Paramaters passed via YAML config files.
YAML_PARAMS = [
:project_style,
:bundle_dir,
:staging_dir,
:accession_items,
:bundle_dir,
:config_filename,
:content_exclusion,
:content_md_creation,
:file_attr,
:manifest_cols,
:manifest,
:progress_log_file,
:project_name,
:file_attr,
:content_md_creation,
:project_style,
:stageable_discovery,
:manifest_cols,
:content_exclusion,
:config_filename,
:validate_files,
:staging_style
:staging_dir,
:staging_style,
:validate_files
]

YAML_PARAMS.each { |p| attr_accessor p }
Expand All @@ -31,11 +31,14 @@ class BundleContextTemporary

# Unpack the user-supplied parameters, after converting
# all hash keys and some hash values to symbols.
def initialize(params = {})
params = Assembly::Utils.symbolize_keys params
Assembly::Utils.values_to_symbols! params[:project_style]
cmc = params[:content_md_creation]
cmc[:style] = cmc[:style].to_sym
def initialize(params)
params.deep_symbolize_keys!
raise ArgumentError, ':bundle_dir is required' unless params[:bundle_dir] # TODO: replace w/ AR validation
[:content_md_creation, :project_style, :stageable_discovery].each { |k| params[k] ||= {} }
params[:project_style].transform_values! { |v| v.is_a?(String) ? v.to_sym : v }
params[:project_style][:content_structure] ||= :simple_image
params[:content_md_creation][:style] ||= :default
params[:content_md_creation][:style] = params[:content_md_creation][:style].to_sym
params[:file_attr] ||= params[:publish_attr]
self.user_params = params
YAML_PARAMS.each { |p| instance_variable_set "@#{p}", params[p] }
Expand Down
5 changes: 5 additions & 0 deletions spec/lib/bundle_context_temporary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
before { allow_any_instance_of(described_class).to receive(:validate_usage) } # to be replaced w/ AR validation

describe "initialize() and other setup" do
it 'requires params' do
expect { described_class.new }.to raise_error(ArgumentError)
expect { described_class.new({}) }.to raise_error(ArgumentError)
end

it "trims the trailing slash from the bundle directory" do
expect(revs_context.bundle_dir).to eq('spec/test_data/bundle_input_a')
end
Expand Down
25 changes: 12 additions & 13 deletions spec/lib/pre_assembly/digital_object_spec.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
RSpec.describe PreAssembly::DigitalObject do
let(:dru) { 'gn330dv6119' }
let(:pid) { "druid:#{dru}" }
let(:ps) {
let(:context_params) do
{
# :apo_druid_id => 'druid:qq333xx4444',
# :set_druid_id => 'druid:mm111nn2222',
:source_id => 'SourceIDFoo',
:file_attr => { 'default' => { :publish => 'yes', :shelve => 'yes', :preserve => 'yes' } },
:source_id => 'SourceIDFoo'
}
end
let(:ps) do
context_params.merge(
:bundle_dir => 'spec/test_data/bundle_input_g',
:content_md_creation => { style: 'default' },
:progress_log_file => Tempfile.new('bundle_input_g').path,
:project_name => 'ProjectBar',
:label => 'LabelQuux',
:publish_attr => { 'default' => { :publish => 'yes', :shelve => 'yes', :preserve => 'yes' } },
:project_style => {},
:content_md_creation => {},
:bundle_dir => 'spec/test_data/bundle_input_g',
:staging_style => 'copy'
}
}
)
end
let(:dobj) { described_class.new(ps) }
let(:druid) { DruidTools::Druid.new(pid) }
let(:tmp_dir_args) { [nil, 'tmp'] }
Expand Down Expand Up @@ -131,7 +133,6 @@ def add_object_files(extension = 'tif')

before do
allow(dobj).to receive(:druid).and_return(druid)
dobj.content_md_creation[:style] = 'default'
dobj.project_style[:content_structure] = 'simple_image'
add_object_files('tif')
add_object_files('jp2')
Expand Down Expand Up @@ -272,7 +273,6 @@ def add_object_files(extension = 'tif')

before do
allow(dobj).to receive(:druid).and_return(druid)
dobj.content_md_creation[:style] = 'default'
dobj.project_style[:content_structure] = 'simple_image' # this is the default
dobj.project_style[:content_tag_override] = true # this allows override of content structure
allow(dobj).to receive(:content_type_tag).and_return('File') # this is what the object tag says, so we should get the file type out
Expand Down Expand Up @@ -341,7 +341,6 @@ def add_object_files(extension = 'tif')

before do
allow(dobj).to receive(:druid).and_return(druid)
dobj.content_md_creation[:style] = 'default'
dobj.project_style[:content_structure] = 'simple_image' # this is the default
allow(dobj).to receive(:content_type_tag).and_return('File') # this is what the object tag says, but it should be ignored since overriding is not allowed
dobj.file_attr = { 'image/jp2' => { :publish => 'yes', :shelve => 'yes', :preserve => 'no' }, 'image/tiff' => { :publish => 'no', :shelve => 'no', :preserve => 'yes' } }
Expand Down

0 comments on commit 5a1d5e8

Please sign in to comment.