Skip to content

Commit

Permalink
Merge pull request #144 from collectionspace/chronic-date-parser-bugfix
Browse files Browse the repository at this point in the history
Chronic date parser bugfix
  • Loading branch information
kspurgin authored Jun 24, 2022
2 parents ad267b7 + 736d573 commit 1fd73b7
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ This project bumps the version number for any changes (including documentation u
- none

## [Unreleased] - i.e. pushed to main branch but not yet tagged as a release
- <del>Handle all dependencies in Gemfile and remove .gemspec since this will never be released as a gem - [PR 141](https://github.com/collectionspace/collectionspace-mapper/pull/141)</del> -- Reverted in [PR 142](https://github.com/collectionspace/collectionspace-mapper/pull/142)

## [4.0.3] - 2022-06-23
- BUGFIX: Fixes error when calling `mappable` on a `ChronicParser` initialized with a date string Chronic cannot parse - [PR 144](https://github.com/collectionspace/collectionspace-mapper/pull/144)
- Replace `facets` gem with `activesupport` - [PR 141](https://github.com/collectionspace/collectionspace-mapper/pull/141)
- <del>Handle all dependencies in Gemfile and remove .gemspec since this will never be released as a gem - [PR 141](https://github.com/collectionspace/collectionspace-mapper/pull/141)</del> -- Reverted in [PR 142](https://github.com/collectionspace/collectionspace-mapper/pull/142)


## [4.0.2] - 2022-06-07
Uses Zeitwerk eager loading (and custom inflection on version.rb to VERSION) to make `rails:zeitwerk` check pass when used with collectionspace-csv-importer.
Expand Down
9 changes: 5 additions & 4 deletions lib/collectionspace/mapper/dates/chronic_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ def initialize(date_string, handler)
@date_string = date_string
@handler = handler
parsed = parse
return CollectionSpace::Mapper::Dates::ServicesParser.new(date_string, handler) unless parsed

@mappable = map_timestamp(parsed)
if parsed.nil?
@mappable = CollectionSpace::Mapper::Dates::ServicesParser.new(date_string, handler).mappable
else
@mappable = map_timestamp(parsed)
end
self
end

Expand All @@ -32,7 +34,6 @@ def parse

Chronic.parse(date_string)
end

end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/collectionspace/mapper/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module CollectionSpace
module Mapper
VERSION = '4.0.2'
VERSION = '4.0.3'
end
end
32 changes: 32 additions & 0 deletions spec/collectionspace/mapper/dates/chronic_parser_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe CollectionSpace::Mapper::Dates::ChronicParser do
subject(:parser){ described_class.new(str, handler) }
let(:client){ anthro_client }
let(:cache){ anthro_cache }
let(:csid_cache){ anthro_csid_cache }
let(:config){ CollectionSpace::Mapper::Config.new }
let(:searcher) { CollectionSpace::Mapper::Searcher.new(client: client, config: config) }
let(:handler){ CollectionSpace::Mapper::Dates::StructuredDateHandler.new(client: client, cache: cache, csid_cache: csid_cache, config: config, searcher: searcher) }

describe '#mappable' do
context 'with 2022-06-23' do
let(:str){ '2022-06-23' }

it 'returns expected' do
expect(parser.mappable['dateEarliestScalarValue']).to eq('2022-06-23T00:00:00.000Z')
end
end

context 'with 01-00-2000' do
let(:str){ '01-00-2000' }

it 'returns expected', :aggregate_failures do
expect(parser.mappable['dateDisplayDate']).to eq(str)
expect(parser.mappable['scalarValuesComputed']).to eq('false')
end
end
end
end
32 changes: 32 additions & 0 deletions spec/collectionspace/mapper/dates/services_parser_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe CollectionSpace::Mapper::Dates::ServicesParser do
subject(:parser){ described_class.new(str, handler) }
let(:client){ anthro_client }
let(:cache){ anthro_cache }
let(:csid_cache){ anthro_csid_cache }
let(:config){ CollectionSpace::Mapper::Config.new }
let(:searcher) { CollectionSpace::Mapper::Searcher.new(client: client, config: config) }
let(:handler){ CollectionSpace::Mapper::Dates::StructuredDateHandler.new(client: client, cache: cache, csid_cache: csid_cache, config: config, searcher: searcher) }

describe '#mappable' do
context 'with 2022-06-23' do
let(:str){ '2022-06-23' }

it 'returns expected' do
expect(parser.mappable['dateEarliestScalarValue']).to eq('2022-06-23T00:00:00.000Z')
end
end

context 'with 01-00-2000' do
let(:str){ '01-00-2000' }

it 'returns expected', :aggregate_failures do
expect(parser.mappable['dateDisplayDate']).to eq(str)
expect(parser.mappable['scalarValuesComputed']).to eq('false')
end
end
end
end

0 comments on commit 1fd73b7

Please sign in to comment.