Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #785 from psu-libraries/date-fix
Browse files Browse the repository at this point in the history
Bug fixes for system usability
  • Loading branch information
awead authored Jan 23, 2019
2 parents a1bf122 + af29113 commit 27777bb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/cho/transaction/shared/save_with_change_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SaveWithChangeSet
private

def process_file(change_set)
return Success(change_set) if change_set.try(:file).nil?
return Success(change_set) if change_set.try(:file).blank?

mime_type = Mime::Type.lookup(change_set.file.content_type)
if mime_type.symbol == :zip
Expand Down
10 changes: 9 additions & 1 deletion app/cho/validation/edtf_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ def validate(field_value)
return true if field_value.blank?

Array.wrap(field_value).each do |value|
date = Date.edtf(value)
date = parse(value) || Date.edtf(value)
errors << "Date #{value} is not a valid EDTF date" unless date
end
errors.empty?
end

private

def parse(date)
Date.parse(date)
rescue ArgumentError
nil
end
end
end
9 changes: 9 additions & 0 deletions spec/cho/validation/edtf_date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,14 @@

it { is_expected.to be_truthy }
end

context 'with a valid Ruby date' do
let(:dates) { 'January 21, 2019' }

it 'is valid' do
expect(validation_instance.validate(dates)).to be_truthy
expect(validation_instance.errors).to be_empty
end
end
end
end

0 comments on commit 27777bb

Please sign in to comment.