Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55f70ab
commit 7a9143f
Showing
6 changed files
with
222 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module AssembleMarcFiles | ||
class << self | ||
def run | ||
program = AssembleMarcFiles.new | ||
log = program.execute | ||
NotifierMailer.administrators(log).deliver_now unless log.empty? | ||
rescue StandardError => e | ||
text = <<~MSG | ||
AssembleMarcFiles run error (#{e}) | ||
MSG | ||
NotifierMailer.administrators(text).deliver_now | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
module AssembleMarcFiles | ||
class AssembleMarcFiles | ||
def execute | ||
log = +'' | ||
lib_ptg_box = LibPtgBox::LibPtgBox.new | ||
log += synchronize(lib_ptg_box) | ||
lib_ptg_box.product_families.each do |product_family| | ||
log += assemble_marc_files(product_family) | ||
end | ||
log | ||
end | ||
|
||
def synchronize(lib_ptg_box) | ||
log = +'' | ||
lib_ptg_box.product_families.each do |product_family| | ||
product_family.products.each do |product| | ||
log += product_family.name + " " + product.name + "\n" | ||
# product.works.each do |work| | ||
# | ||
# end | ||
end | ||
end | ||
log | ||
end | ||
|
||
def assemble_marc_files(product_family) | ||
log = +'' | ||
log += product_family.name + "\n" | ||
log | ||
end | ||
|
||
# def run | ||
# umpebc_products_modified.each do |modified_product| | ||
# generate_product_marc_files(modified_product) | ||
# end | ||
# rescue StandardError => e | ||
# text = <<~MSG | ||
# AssembleMarcFiles run error (#{e}) | ||
# MSG | ||
# NotifierMailer.administrators(text).deliver_now | ||
# end | ||
# | ||
# private | ||
# | ||
# def generate_product_marc_files(product) | ||
# product.dois.each do |doi| | ||
# end | ||
# end | ||
# | ||
# def umpebc_products_modified | ||
# umpebc_product_family.products.map { |product| product if product.modified? }.compact | ||
# end | ||
# | ||
# def umpebc_product_family | ||
# @umpebc_product_family ||= begin | ||
# product_families = LibPtgBox::LibPtgBox.new.product_families | ||
# umpebc_family = nil | ||
# product_families.each do |family| | ||
# next unless /umpebc/i.match?(family.name) | ||
# | ||
# umpebc_family = family | ||
# break | ||
# end | ||
# raise 'umpebc product family not found' unless umpebc_family | ||
# | ||
# umpebc_family | ||
# end | ||
# end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
spec/programs/assemble_marc_files/assemble_marc_files_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
require 'support/mock_boxr' | ||
|
||
module Boxr | ||
MOCK_ROOT = Rails.root.join('spec', 'fixtures') | ||
|
||
class Client | ||
def initialize | ||
@init = true | ||
end | ||
|
||
def file_from_path(path) | ||
mock_client.file_from_path(File.join(MOCK_ROOT, path)) | ||
end | ||
|
||
def folder_from_path(path) | ||
mock_client.folder_from_path(File.join(MOCK_ROOT, path)) | ||
end | ||
|
||
def folder_items(folder, options) | ||
mock_client.folder_items(folder, options) | ||
end | ||
|
||
def download_file(file) | ||
mock_client.download_file(file) | ||
end | ||
|
||
def upload_file(path, folder) | ||
mock_client.upload_file(path, folder) | ||
end | ||
|
||
private | ||
|
||
def mock_client | ||
@mock_client ||= MockBoxr::Client.new | ||
end | ||
end | ||
end | ||
|
||
RSpec.describe AssembleMarcFiles::AssembleMarcFiles do | ||
subject(:program) { described_class.new } | ||
|
||
before { program } | ||
|
||
describe '#execute' do | ||
subject { program.execute } | ||
|
||
let(:lib_ptg_box) { instance_double(LibPtgBox::LibPtgBox, 'lib_ptg_box', product_families: [product_family]) } | ||
let(:product_family) { instance_double(LibPtgBox::ProductFamily, 'product_family') } | ||
|
||
before do | ||
allow(LibPtgBox::LibPtgBox).to receive(:new).and_return(lib_ptg_box) | ||
allow(program).to receive(:synchronize).with(lib_ptg_box).and_return("synchronize\n") | ||
allow(program).to receive(:assemble_marc_files).with(product_family).and_return("product_family\n") | ||
end | ||
|
||
it { is_expected.to eq("synchronize\nproduct_family\n") } | ||
end | ||
|
||
describe '#synchronize' do | ||
subject { program.synchronize(lib_ptg_box) } | ||
|
||
# let(:lib_ptg_box) { instance_double(LibPtgBox::LibPtgBox, 'lib_ptg_box') } | ||
let(:lib_ptg_box) { LibPtgBox::LibPtgBox.new } | ||
|
||
it { is_expected.to eq("synchronize\n") } | ||
end | ||
|
||
describe '#assemble_marc_files' do | ||
subject { program.assemble_marc_files(product_family) } | ||
|
||
let(:product_family) { instance_double(LibPtgBox::ProductFamily, 'product_family', name: 'product_name') } | ||
|
||
it { is_expected.to eq(product_family.name + "\n") } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe AssembleMarcFiles do | ||
describe '#run' do | ||
let(:assemble_marc_files) { instance_double(AssembleMarcFiles::AssembleMarcFiles, "AssembleMarcFiles") } | ||
let(:mailer) { double("NotifierMailer") } # rubocop:disable RSpec/VerifiedDoubles | ||
|
||
before do | ||
allow(AssembleMarcFiles::AssembleMarcFiles).to receive(:new).and_return(assemble_marc_files) | ||
allow(mailer).to receive(:deliver_now) | ||
end | ||
|
||
context 'when log empty' do | ||
before do | ||
allow(assemble_marc_files).to receive(:execute).and_return("") | ||
allow(NotifierMailer).to receive(:administrators).with(anything).and_return(mailer) | ||
end | ||
|
||
it 'does not notifies administrators' do | ||
described_class.run | ||
expect(assemble_marc_files).to have_received(:execute) | ||
expect(mailer).not_to have_received(:deliver_now) | ||
end | ||
end | ||
|
||
context 'when log non-empty' do | ||
before do | ||
allow(assemble_marc_files).to receive(:execute).and_return("log\n") | ||
allow(NotifierMailer).to receive(:administrators).with("log\n").and_return(mailer) | ||
end | ||
|
||
it 'notifies administrators' do | ||
described_class.run | ||
expect(assemble_marc_files).to have_received(:execute) | ||
expect(mailer).to have_received(:deliver_now) | ||
end | ||
end | ||
|
||
context 'when standard error' do | ||
before do | ||
allow(assemble_marc_files).to receive(:execute).and_raise(StandardError) | ||
allow(NotifierMailer).to receive(:administrators).with("AssembleMarcFiles run error (StandardError)\n").and_return(mailer) | ||
end | ||
|
||
it 'notifies administrators' do | ||
described_class.run | ||
expect(mailer).to have_received(:deliver_now) | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.