darlingtonia 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d2846b9bcfda0f77bed4980b06ffebeea86fa2d
4
- data.tar.gz: 5768f600be72e578ef9969e84d1d71d3e5160c06
3
+ metadata.gz: de3308c4bc712e18cdca102c0dd860638aad4ffc
4
+ data.tar.gz: 2ee3c0231d0ee94f69c9b95bf8f07b84d67c42e0
5
5
  SHA512:
6
- metadata.gz: 1565987780f909a9ba63b872c68da62a6f782c46d5363930b188a7c64e63bc323e1cdbfb1d54274291b6a6dfea046a6a87d672648d7a11d6a707dafb25e11db8
7
- data.tar.gz: ddae5b051da31ee14317e09b5c36597cd3ec6ad550d6ddd1585ac4d30ba77dccae2cbbbcf0deb8cf6d790bf6a37be87c46f9a766502423603e8609b27b1beb00
6
+ metadata.gz: b0057d871e574a744e6b9d2c53f9fef71e93b5b6cc3259a8a5f212469123e57595eba3ee93ab9bd9764c9dede09459c4171fb5e3301b493cf11daf3c9c5f22f7
7
+ data.tar.gz: d7907d65a9c6a97067ee12f1c5a0732b0305858bb8d49bd7e5440415e7f0f307f30024ddf727fd48b8a5ae131adc4a78f4232e135f52909e0dbaea46c351449f
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
+ pkg
1
2
  tmp
2
3
  Gemfile.lock
@@ -1,3 +1,14 @@
1
+ 0.3.0 - Fri Jan 19, 2018
2
+ ------------------------
3
+
4
+ Representative files.
5
+
6
+ - `ImportRecord` now passes through a `#representative_file` to its mapper,
7
+ returning `nil` if the mapper does not provide such a method.
8
+ - `CsvParser#records` now returns an empty record collection if it is given
9
+ invalid CSV input. This allows cleaner handling in other validations and
10
+ imports.
11
+
1
12
  0.2.0 - Wed Jan 17, 2018
2
13
  ------------------------
3
14
 
@@ -29,6 +29,16 @@ module Darlingtonia
29
29
  end
30
30
  end
31
31
 
32
+ ##
33
+ # @return [String, nil] an identifier for the representative file; nil if
34
+ # none is given.
35
+ def representative_file
36
+ return mapper.representative_file if
37
+ mapper.respond_to?(:representative_file)
38
+
39
+ nil
40
+ end
41
+
32
42
  ##
33
43
  # Respond to methods matching mapper fields
34
44
  def method_missing(method_name, *args, &block)
@@ -38,6 +38,8 @@ module Darlingtonia
38
38
  CSV.parse(file.read, headers: true).each do |row|
39
39
  yield InputRecord.from(metadata: row)
40
40
  end
41
+ rescue CSV::MalformedCSVError
42
+ []
41
43
  end
42
44
  end
43
45
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Darlingtonia
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -34,16 +34,26 @@ EOS
34
34
  end
35
35
 
36
36
  describe '#records' do
37
- include_context 'with content'
37
+ context 'with valid content' do
38
+ include_context 'with content'
39
+
40
+ it 'has the correct titles' do
41
+ expect(parser.records.map(&:title))
42
+ .to contain_exactly(['The Moomins and the Great Flood'],
43
+ ['Comet in Moominland'])
44
+ end
38
45
 
39
- it 'has the correct titles' do
40
- expect(parser.records.map(&:title))
41
- .to contain_exactly(['The Moomins and the Great Flood'],
42
- ['Comet in Moominland'])
46
+ it 'has correct other fields' do
47
+ expect(parser.records.map(&:date)).to contain_exactly(['1945'], ['1946'])
48
+ end
43
49
  end
44
50
 
45
- it 'has correct other fields' do
46
- expect(parser.records.map(&:date)).to contain_exactly(['1945'], ['1946'])
51
+ context 'with invalid file' do
52
+ let(:file) { File.open('spec/fixtures/bad_example.csv') }
53
+
54
+ it 'is empty' do
55
+ expect(parser.records.to_a).to be_empty
56
+ end
47
57
  end
48
58
  end
49
59
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'spec_helper'
4
+
3
5
  describe Darlingtonia::InputRecord do
4
6
  subject(:record) { described_class.from(metadata: metadata) }
5
7
 
@@ -17,6 +19,30 @@ describe Darlingtonia::InputRecord do
17
19
  it 'handles basic text fields' do
18
20
  expect(record.attributes).to include(:title, :description)
19
21
  end
22
+
23
+ it 'does not include representative_file' do
24
+ expect(record.attributes).not_to include(:representative_file)
25
+ end
26
+ end
27
+
28
+ describe '#representative_file' do
29
+ it 'is nil if mapper does not provide a representative file' do
30
+ expect(record.representative_file).to be_nil
31
+ end
32
+
33
+ context 'when mapper provides representative_file' do
34
+ let(:representative_file) { :A_DUMMY_FILE }
35
+
36
+ before do
37
+ allow(record.mapper)
38
+ .to receive(:representative_file)
39
+ .and_return(representative_file)
40
+ end
41
+
42
+ it 'is the file from the mapper' do
43
+ expect(record.representative_file).to eql representative_file
44
+ end
45
+ end
20
46
  end
21
47
 
22
48
  describe 'mapped fields' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: darlingtonia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Johnson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-01-17 00:00:00.000000000 Z
12
+ date: 2018-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: active-fedora