-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Max Kadel <[email protected]>
- Loading branch information
1 parent
dcc6dcf
commit 1c35700
Showing
2 changed files
with
60 additions
and
0 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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'csv' | ||
|
||
module AlmaRenew | ||
class RenewFile | ||
attr_reader :temp_file, :renew_item_list | ||
def initialize(temp_file:) | ||
@temp_file = temp_file | ||
@renew_item_list = [] | ||
end | ||
|
||
def process | ||
CSVValidator.new(csv_filename: temp_file.path).require_headers ['Barcode', 'Patron Group', 'Expiry Date', 'Primary Identifier'] | ||
CSV.foreach(temp_file, headers: true, encoding: 'bom|utf-8') do |row| | ||
renew_item_list << Item.new(row.to_h) | ||
end | ||
renew_item_list | ||
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,39 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
|
||
RSpec.describe AlmaRenew::RenewFile, type: :model, file_download: true do | ||
let(:temp_file) { Tempfile.new(encoding: 'ascii-8bit') } | ||
let(:renew_file) { described_class.new(temp_file:) } | ||
|
||
it "can be instantiated" do | ||
expect(described_class.new(temp_file:)).to be | ||
end | ||
|
||
it "can access the temp_file" do | ||
expect(renew_file.temp_file).to eq(temp_file) | ||
end | ||
|
||
describe "#process" do | ||
before do | ||
allow(Tempfile).to receive(:new).and_return(temp_file) | ||
end | ||
|
||
around do |example| | ||
temp_file.write(File.open(File.join('spec', 'fixtures', 'renew.csv')).read) | ||
temp_file.rewind | ||
example.run | ||
end | ||
|
||
it "can be processed" do | ||
expect(described_class.new(temp_file:).process).to be | ||
end | ||
|
||
it "returns an array" do | ||
expect(renew_file.process).to be_instance_of(Array) | ||
end | ||
|
||
it "has Items in the array" do | ||
expect(renew_file.process.first).to be_instance_of(AlmaRenew::Item) | ||
end | ||
end | ||
end |