Skip to content

Commit

Permalink
BundleContext factory and conversion of specs to use it
Browse files Browse the repository at this point in the history
For great cleanliness!
  • Loading branch information
atz committed Sep 20, 2018
1 parent 4819ae2 commit 7538b1a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 56 deletions.
10 changes: 10 additions & 0 deletions spec/factories/bundle_contexts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FactoryBot.define do
factory :bundle_context do
bundle_dir { 'spec/test_data/smpl_multimedia' }
content_metadata_creation { 'default' }
content_structure { 'simple_image' }
project_name { 'Test_Project' }
staging_style_symlink { false }
user
end
end
17 changes: 4 additions & 13 deletions spec/mailers/job_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
RSpec.describe JobMailer, type: :mailer do
let(:user) { build(:user, sunet_id: "Jdoe@stanford.edu") }
let(:bc) do
BundleContext.new(id: 1,
project_name: "SmokeTest",
content_structure: 1,
bundle_dir: "spec/test_data/images_jp2_tif",
staging_style_symlink: false,
content_metadata_creation: 1,
user: user)
end
let(:discovery_report_run) do
let(:bc) { build(:bundle_context) }
let(:job_run) do
JobRun.new(id: 1,
output_location: "/path/to/report",
bundle_context: bc,
job_type: "discovery_report")
end
let(:job_notification) { described_class.with(job_run: discovery_report_run).completion_email }
let(:job_notification) { described_class.with(job_run: job_run).completion_email }

it 'renders the headers' do
expect(job_notification.subject).to eq("Your pre-assembly job has completed")
expect(job_notification.to).to eq(["Jdoe@stanford.edu"])
expect(job_notification.to).to eq([job_run.bundle_context.user.email])
expect(job_notification.from).to eq(["no-reply-preassembly-job@stanford.edu"])
end

Expand Down
9 changes: 3 additions & 6 deletions spec/models/bundle_context_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
RSpec.describe BundleContext, type: :model do
let (:attr_hash) {
{
project_name: "Images_jp2_tif",
content_structure: 1,
bundle_dir: "spec/test_data/images_jp2_tif/",
staging_style_symlink: false,
content_metadata_creation: 1,
project_name: 'Images_jp2_tif',
bundle_dir: 'spec/test_data/images_jp2_tif',
user: build(:user, sunet_id: 'Jdoe@stanford.edu')
}
}
subject(:bc) { BundleContext.new(attr_hash) }
subject(:bc) { build(:bundle_context, attr_hash) }

context "validation" do
it "is not valid unless it has all required attributes" do
Expand Down
9 changes: 1 addition & 8 deletions spec/models/job_run_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
RSpec.describe JobRun, type: :model do
let(:bc) do
BundleContext.new(
project_name: 'ImagesJp2Tif',
content_structure: 1,
bundle_dir: 'spec/test_data/images_jp2_tif',
staging_style_symlink: false,
content_metadata_creation: 1,
user: build(:user)
).tap do |bc|
build(:bundle_context).tap do |bc|
Dir.delete(bc.output_dir) if Dir.exist?(bc.output_dir)
bc.save!
end
Expand Down
21 changes: 10 additions & 11 deletions spec/support/bundle_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ def noko_doc(x)
end

def bundle_context_from_hash(proj)
user = build(:user, sunet_id: 'Jdoe@stanford.edu')
cmc = hash_from_proj(proj)["content_md_creation"]["style"]
cmc = cmc + "_cm_style" if cmc == "smpl"

BundleContext.new(
project_name: hash_from_proj(proj)["project_name"],
content_structure: hash_from_proj(proj)["project_style"]["content_structure"],
bundle_dir: hash_from_proj(proj)["bundle_dir"],
staging_style_symlink: false,
content_metadata_creation: cmc ,
user: user
hash = hash_from_proj(proj)
cmc = hash["content_md_creation"]["style"]
cmc += '_cm_style' if cmc == "smpl"
build(
:bundle_context,
project_name: hash["project_name"],
content_structure: hash["project_style"]["content_structure"],
bundle_dir: hash["bundle_dir"],
content_metadata_creation: cmc,
user: build(:user, sunet_id: 'Jdoe@stanford.edu')
)
end
24 changes: 6 additions & 18 deletions spec/views/bundle_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,20 @@

context "Displays errors in Bundle Context Form"
it 'displays error message when missing project name' do
assign(:bundle_context, BundleContext.create(
project_name: nil,
content_structure: "simple_image",
content_metadata_creation: "default",
bundle_dir: "spec/test_data/bundle_input_b"
))
bc = build(:bundle_context, project_name: nil).tap(&:valid?)
assign(:bundle_context, bc)
render
expect(render).to match(/Project name can't be blank/)
end
it 'displays error message when missing bundle_dir' do
assign(:bundle_context, BundleContext.create(
project_name: "A great project",
content_structure: "simple_image",
content_metadata_creation: "default",
bundle_dir: nil
))
bc = build(:bundle_context, bundle_dir: nil).tap(&:valid?)
assign(:bundle_context, bc)
render
expect(render).to match(/Bundle dir can't be blank/)
end
it 'displays error message for non-existent bundle directory' do
assign(:bundle_context, BundleContext.create(
project_name: "Another great project",
content_structure: "simple_image",
content_metadata_creation: "default",
bundle_dir: "bad path"
))
bc = build(:bundle_context, bundle_dir: 'bad path').tap(&:valid?)
assign(:bundle_context, bc)
render
expect(render).to match(/Bundle dir Bundle directory: bad path not found./)
end
Expand Down

0 comments on commit 7538b1a

Please sign in to comment.