Skip to content

Commit

Permalink
bundle_context: normalize_bundle_dir method is private
Browse files Browse the repository at this point in the history
  • Loading branch information
ndushay committed Sep 19, 2018
1 parent edf5681 commit 1bdbf84
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions app/models/bundle_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@ def assembly_staging_dir
Settings.assembly_staging_dir
end

def normalize_bundle_dir
normalize_dir(bundle_dir)
end

def output_dir
@output_dir ||= "#{normalize_dir(Settings.job_output_parent_dir)}/#{user.sunet_id}/#{normalize_bundle_dir}"
@output_dir ||= "#{normalize_dir(Settings.job_output_parent_dir)}/#{user.sunet_id}/#{bundle_dir}"
end

def progress_log_file
Expand Down Expand Up @@ -126,6 +122,10 @@ def normalize_dir(dir)
dir.chomp('/') if dir
end

def normalize_bundle_dir
self[:bundle_dir] = normalize_dir(bundle_dir)
end

def verify_output_dir
if persisted?
# FIXME: or should we just try to create it?
Expand Down
6 changes: 4 additions & 2 deletions spec/controllers/bundle_contexts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@

context "POST create" do
context "Valid Parameters" do
let(:output_dir) { "#{Settings.job_output_parent_dir}/#{subject.current_user.sunet_id}/spec/test_data/smpl_multimedia" }
before do
dir = "#{Settings.job_output_parent_dir}/#{subject.current_user.sunet_id}/spec/test_data/smpl_multimedia"
Dir.delete(dir) if Dir.exist?(dir)
Dir.delete(output_dir) if Dir.exist?(output_dir)
post :create, params: params
end

Expand All @@ -57,10 +57,12 @@
expect(bc.bundle_dir).to eq "spec/test_data/smpl_multimedia"
end
it "persists the JobRun" do
Dir.delete(output_dir) if Dir.exist?(output_dir)
expect { post :create, params: params }.to change(JobRun, :count).by(1)
end

it "fails if job_type is nil" do
Dir.delete(output_dir) if Dir.exist?(output_dir)
params[:bundle_context].merge!(job_runs_attributes: {"0" => { job_type: "" }})
expect { post :create, params: params }.not_to change(JobRun, :count)
end
Expand Down
10 changes: 4 additions & 6 deletions spec/models/bundle_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
it { is_expected.to validate_presence_of(:content_metadata_creation) }
it { is_expected.to belong_to(:user) }

it 'bundle_dir has trailing slash removed' do
expect(bc.bundle_dir).to eq "spec/test_data/images_jp2_tif"
end

describe '#bundle' do
it 'returns a PreAssembly::Bundle' do
expect(bc.bundle).to be_a(PreAssembly::Bundle)
Expand All @@ -63,12 +67,6 @@
end
end

describe "#normalize_bundle_dir" do
it "removes the trailing forward slash" do
expect(bc.normalize_bundle_dir).to eq "spec/test_data/images_jp2_tif"
end
end

describe "#content_tag_override?" do
it "is set to true" do
expect(described_class.new.content_tag_override?).to be true
Expand Down

0 comments on commit 1bdbf84

Please sign in to comment.